Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ For kubebuilder-tools : add support to darwin/arm64, and other future OS/Arch asset bundles + etcd #2762

Conversation

akutz
Copy link

@akutz akutz commented Jun 21, 2022

This patch updates the Dockerfile used to produce the kubebuilder asset bundle to support darwin/arm64, as well as possible, other, future OS/Architecture combinations, with support for building etcd as well.

This patch will build kubectl and etcd from source in the case either is not found using their prebuilt URL locations.

Testing includes:

  1. Building the asset bundle:

    $ docker build --build-arg 'ARCH=arm64' --build-arg 'KUBERNETES_VERSION=v1.24.2' -t envtest-darwin-arm64 .
    [+] Building 148.1s (17/17) FINISHED                                                                                
     => [internal] load build definition from Dockerfile                                                           0.0s
     => => transferring dockerfile: 2.48kB                                                                         0.0s
     => [internal] load .dockerignore                                                                              0.0s
     => => transferring context: 2B                                                                                0.0s
     => [internal] load metadata for docker.io/library/alpine:3.16                                                 0.3s
     => [internal] load metadata for docker.io/library/golang:1.18                                                 0.3s
     => [builder  1/10] FROM docker.io/library/golang:1.18@sha256:1c3d22f95ce57821fff1dcd857c54809ea62f33634e2696  0.0s
     => CACHED [stage-1 1/2] FROM docker.io/library/alpine:3.16@sha256:686d8c9dfa6f3ccfc8230bc3178d23f84eeaf7e457  0.0s
     => CACHED [builder  2/10] RUN apt update &&     apt install unzip rsync -y &&     mkdir -p /usr/local/kubebu  0.0s
     => CACHED [builder  3/10] WORKDIR /kubernetes                                                                 0.0s
     => CACHED [builder  4/10] RUN git clone https://github.com/kubernetes/kubernetes . --depth=1 -b v1.24.2       0.0s
     => [builder  5/10] RUN make WHAT=cmd/kube-apiserver &&     cp _output/local/bin/darwin/arm64/kube-apiserve  115.6s
     => [builder  6/10] RUN /bin/bash -o pipefail -c '     { curl -sLO https://storage.googleapis.com/kubernetes-  1.3s
     => [builder  7/10] WORKDIR /etcd                                                                              0.0s 
     => [builder  8/10] RUN /bin/bash -x -c '     { curl -sLO https://github.com/coreos/etcd/releases/download/$  23.1s 
     => [builder  9/10] WORKDIR /usr/local                                                                         0.0s 
     => [builder 10/10] RUN tar -czvf /kubebuilder_darwin_arm64.tar.gz kubebuilder/                                6.4s 
     => [stage-1 2/2] COPY --from=builder /kubebuilder_darwin_arm64.tar.gz /                                       0.1s 
     => exporting to image                                                                                         0.1s 
     => => exporting layers                                                                                        0.1s 
     => => writing image sha256:f1fe3e4bc8d665d35fb05457cfe54d5ce73620eb1196722206772fee176c0a3b                   0.0s 
     => => naming to docker.io/library/envtest-darwin-arm64                                                        0.0s 
    
    Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
  2. Copying the produced asset tarball out of the container image:

    $ docker run envtest-darwin-arm64
    
    $ docker ps -a
    CONTAINER ID   IMAGE                  COMMAND                  CREATED             STATUS                     PORTS                       NAMES
    66d8420678b6   envtest-darwin-arm64   "/bin/sh"                3 seconds ago       Exited (0) 3 seconds ago                               unruffled_morse
    
    $ docker cp 66d8420678b6:/kubebuilder_darwin_arm64.tar.gz .
  3. Verifying the contents of the tarball:

    $ tar xzf kubebuilder_darwin_arm64.tar.gz 
    
    $ ls kubebuilder/bin
    etcd		kube-apiserver	kubectl
    
    $ file kubebuilder/bin/etcd
    kubebuilder/bin/etcd: Mach-O 64-bit executable arm64
    
    $ file kubebuilder/bin/kube-apiserver 
    kubebuilder/bin/kube-apiserver: Mach-O 64-bit executable arm64
    
    $ file kubebuilder/bin/kubectl
    kubebuilder/bin/kubectl: Mach-O 64-bit executable arm64
    
    $ ./kubebuilder/bin/etcd --version
    etcd Version: 3.5.4
    Git SHA: 08407ff
    Go Version: go1.18.3
    Go OS/Arch: darwin/arm64
    
    $ ./kubebuilder/bin/kube-apiserver --version
    Kubernetes v1.24.2
    
    $ ./kubebuilder/bin/kubectl version
    WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
    Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.2", GitCommit:"f66044f4361b9f1f96f0053dd46cb7dce5e990a8", GitTreeState:"clean", BuildDate:"2022-06-15T14:22:29Z", GoVersion:"go1.18.3", Compiler:"gc", Platform:"darwin/arm64"}
    Kustomize Version: v4.5.4
    Server Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.0", GitCommit:"4ce5a8954017644c5420bae81d72b09b735c21f0", GitTreeState:"clean", BuildDate:"2022-05-19T15:42:59Z", GoVersion:"go1.18.1", Compiler:"gc", Platform:"linux/arm64"}

Update 1
I decided to validate it again using --no-cache when building the image, and it still works as expected:

$ docker build --no-cache --build-arg 'ARCH=arm64' --build-arg 'KUBERNETES_VERSION=v1.24.2' -t envtest-darwin-arm64 .
[+] Building 164.7s (19/19) FINISHED                                                                                
 => [internal] load build definition from Dockerfile                                                           0.0s
 => => transferring dockerfile: 2.44kB                                                                         0.0s
 => [internal] load .dockerignore                                                                              0.0s
 => => transferring context: 2B                                                                                0.0s
 => [internal] load metadata for docker.io/library/alpine:3.16                                                 0.8s
 => [internal] load metadata for docker.io/library/golang:1.18                                                 0.8s
 => [auth] library/alpine:pull token for registry-1.docker.io                                                  0.0s
 => [auth] library/golang:pull token for registry-1.docker.io                                                  0.0s
 => CACHED [builder  1/10] FROM docker.io/library/golang:1.18@sha256:1c3d22f95ce57821fff1dcd857c54809ea62f336  0.0s
 => CACHED [stage-1 1/2] FROM docker.io/library/alpine:3.16@sha256:686d8c9dfa6f3ccfc8230bc3178d23f84eeaf7e457  0.0s
 => [builder  2/10] RUN apt update &&     apt install unzip rsync -y &&     mkdir -p /usr/local/kubebuilder/b  3.4s
 => [builder  3/10] WORKDIR /kubernetes                                                                        0.0s
 => [builder  4/10] RUN git clone https://github.com/kubernetes/kubernetes . --depth=1 -b v1.24.2             12.8s
 => [builder  5/10] RUN make WHAT=cmd/kube-apiserver &&     cp _output/local/bin/darwin/arm64/kube-apiserve  115.0s 
 => [builder  6/10] RUN /bin/bash -x -c '     { curl -sLO https://storage.googleapis.com/kubernetes-release/r  1.5s 
 => [builder  7/10] WORKDIR /etcd                                                                              0.0s 
 => [builder  8/10] RUN /bin/bash -x -c '     { curl -sLO https://github.com/coreos/etcd/releases/download/$  23.2s 
 => [builder  9/10] WORKDIR /usr/local                                                                         0.0s 
 => [builder 10/10] RUN tar -czvf /kubebuilder_darwin_arm64.tar.gz kubebuilder/                                6.4s 
 => [stage-1 2/2] COPY --from=builder /kubebuilder_darwin_arm64.tar.gz /                                       0.1s 
 => exporting to image                                                                                         0.1s 
 => => exporting layers                                                                                        0.1s 
 => => writing image sha256:4bfb9de03c3f0b58c6611e419cc524804d2d27ec7c82403605a8c14721881246                   0.0s 
 => => naming to docker.io/library/envtest-darwin-arm64                                                        0.0s 

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
$ docker run envtest-darwin-arm64

$ docker ps -a
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS                      PORTS                       NAMES
516bd3122ea7   envtest-darwin-arm64   "/bin/sh"                2 seconds ago    Exited (0) 1 second ago    

$ docker cp 516bd3122ea7:/kubebuilder_darwin_arm64.tar.gz .
$ tar xzf kubebuilder_darwin_arm64.tar.gz

$ file kubebuilder/bin/*
kubebuilder/bin/etcd:           Mach-O 64-bit executable arm64
kubebuilder/bin/kube-apiserver: Mach-O 64-bit executable arm64
kubebuilder/bin/kubectl:        Mach-O 64-bit executable arm64

$ ./kubebuilder/bin/etcd --version
etcd Version: 3.5.4
Git SHA: 08407ff
Go Version: go1.18.3
Go OS/Arch: darwin/arm64

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 21, 2022
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jun 21, 2022
@akutz akutz force-pushed the feature/envtest-tarball-darwin-arm64 branch from 6fdb510 to b15d732 Compare June 21, 2022 19:05
This patch updates the Dockerfile used to produce the
kubebuilder asset bundle to support darwin/arm64,
including etcd.

This patch will build kubectl and etcd from source in
the case either is not found using their prebuilt URL
locations.
@akutz akutz force-pushed the feature/envtest-tarball-darwin-arm64 branch from b15d732 to 06fe6e4 Compare June 21, 2022 19:06
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution 🥇

That is great. I tested locally and all worked fine:

$ docker build --build-arg OS=darwin --build-arg ARCH=arm64 --build-arg KUBERNETES_VERSION=v1.24.1 .
[+] Building 472.8s (17/17) FINISHED                                            
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 37B                                        0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for docker.io/library/alpine:3.16             0.8s
 => [internal] load metadata for docker.io/library/golang:1.18             0.8s
 => CACHED [stage-1 1/2] FROM docker.io/library/alpine:3.16@sha256:686d8c  0.0s
 => CACHED [builder  1/10] FROM docker.io/library/golang:1.18@sha256:1c3d  0.0s
 => => resolve docker.io/library/golang:1.18@sha256:1c3d22f95ce57821fff1d  0.0s
 => [builder  2/10] RUN apt update &&     apt install unzip rsync -y &&    5.5s
 => [builder  3/10] WORKDIR /kubernetes                                    0.0s
 => [builder  4/10] RUN git clone https://github.com/kubernetes/kubernet  24.8s
 => [builder  5/10] RUN make WHAT=cmd/kube-apiserver &&     cp _output/  360.3s 
 => [builder  6/10] RUN /bin/bash -x -c '     { curl -sLO https://storage  6.9s 
 => [builder  7/10] WORKDIR /etcd                                          0.1s 
 => [builder  8/10] RUN /bin/bash -x -c '     { curl -sLO https://github  59.9s 
 => [builder  9/10] WORKDIR /usr/local                                     0.0s 
 => [builder 10/10] RUN tar -czvf /kubebuilder_darwin_arm64.tar.gz kubebu  9.5s 
 => [stage-1 2/2] COPY --from=builder /kubebuilder_darwin_arm64.tar.gz /   0.4s 
 => exporting to image                                                     0.4s 
 => => exporting layers                                                    0.4s 
 => => writing image sha256:68e818cbc0ca92d8e80ef576e4b9dd835d78d3bda2da6  0.0

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: akutz, camilamacedo86

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 22, 2022
@camilamacedo86 camilamacedo86 changed the title ✨ Support darwin/arm64, and other future OS/Arch asset bundles + etcd ✨ For kubebuilder-tools : add support to darwin/arm64, and other future OS/Arch asset bundles + etcd Jun 22, 2022
@camilamacedo86 camilamacedo86 merged commit 24c5da8 into kubernetes-sigs:tools-releases Jun 22, 2022
@akutz akutz deleted the feature/envtest-tarball-darwin-arm64 branch June 22, 2022 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants