From bf91e6790e90a00193aeffa0962a1ed2f63abad4 Mon Sep 17 00:00:00 2001 From: Sean Malloy Date: Thu, 3 Dec 2020 00:06:22 -0600 Subject: [PATCH 1/2] Enable Multi-Arch Container Image Builds Previous to this change official descheduler container images only supported the AMD64 hardware architecture. This change enables building official descheduler container images for multiple architectures. The initially supported architectures are AMD64 and ARM64. --- Dockerfile | 3 ++- Makefile | 29 ++++++++++++++++++++++++++--- cloudbuild.yaml | 2 +- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0208b970b..b3dfc3879 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,8 +15,9 @@ FROM golang:1.15.2 WORKDIR /go/src/sigs.k8s.io/descheduler COPY . . +ARG ARCH ARG VERSION -RUN VERSION=${VERSION} make +RUN VERSION=${VERSION} make build.$ARCH FROM scratch diff --git a/Makefile b/Makefile index f74f26c00..b05a62e9e 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ VERSION?=v$(shell date +%Y%m%d)-$(shell git describe --tags --match "v*") BUILD=$(shell date +%FT%T%z) LDFLAG_LOCATION=sigs.k8s.io/descheduler/cmd/descheduler/app +ARCHS = amd64 arm64 LDFLAGS=-ldflags "-X ${LDFLAG_LOCATION}.version=${VERSION} -X ${LDFLAG_LOCATION}.buildDate=${BUILD}" @@ -47,18 +48,40 @@ all: build build: CGO_ENABLED=0 go build ${LDFLAGS} -o _output/bin/descheduler sigs.k8s.io/descheduler/cmd/descheduler +build.amd64: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o _output/bin/descheduler sigs.k8s.io/descheduler/cmd/descheduler + +build.arm64: + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build ${LDFLAGS} -o _output/bin/descheduler sigs.k8s.io/descheduler/cmd/descheduler + dev-image: build docker build -f Dockerfile.dev -t $(IMAGE) . image: - docker build --build-arg VERSION="$(VERSION)" -t $(IMAGE) . + docker build --build-arg VERSION="$(VERSION)" --build-arg ARCH="amd64" -t $(IMAGE) . -push-container-to-gcloud: image +image.amd64: + docker build --build-arg VERSION="$(VERSION)" --build-arg ARCH="amd64" -t $(IMAGE)-amd64 . + +image.arm64: + docker build --build-arg VERSION="$(VERSION)" --build-arg ARCH="arm64" -t $(IMAGE)-arm64 . + +push: image gcloud auth configure-docker docker tag $(IMAGE) $(IMAGE_GCLOUD) docker push $(IMAGE_GCLOUD) -push: push-container-to-gcloud +push-all: image.amd64 image.arm64 + gcloud auth configure-docker + for arch in $(ARCHS); do \ + docker tag $(IMAGE)-$${arch} $(IMAGE_GCLOUD)-$${arch} ;\ + docker push $(IMAGE_GCLOUD)-$${arch} ;\ + done + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(IMAGE_GCLOUD) $(addprefix --amend $(IMAGE_GCLOUD)-, $(ARCHS)) + for arch in $(ARCHS); do \ + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest annotate --arch $${arch} $(IMAGE_GCLOUD) $(IMAGE_GCLOUD)-$${arch} ;\ + done + DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $(IMAGE_GCLOUD) ;\ clean: rm -rf _output diff --git a/cloudbuild.yaml b/cloudbuild.yaml index d9a9b5605..a80de306e 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -14,7 +14,7 @@ steps: - VERSION=$_GIT_TAG - BASE_REF=$_PULL_BASE_REF args: - - push + - push-all substitutions: # _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and # can be used as a substitution From 94f1c7dd8d4309b0886047b2d6491e1b7e43d60d Mon Sep 17 00:00:00 2001 From: Sean Malloy Date: Thu, 3 Dec 2020 00:44:19 -0600 Subject: [PATCH 2/2] Document Multi-Arch Container Image Usage --- docs/release-guide.md | 2 +- docs/user-guide.md | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/release-guide.md b/docs/release-guide.md index 9a0adeb14..d780a772e 100644 --- a/docs/release-guide.md +++ b/docs/release-guide.md @@ -20,7 +20,7 @@ 3. Push the release branch to the descheuler repo and ensure branch protection is enabled (not required for patch releases) 4. Tag the repository from the `master` branch (from the `release-1.18` branch for a patch release) and push the tag `VERSION=v0.18.0 git tag -m $VERSION $VERSION; git push origin $VERSION` 5. Checkout the tag you just created and make sure your repo is clean by git's standards `git checkout $VERSION` -6. Build and push the container image to the staging registry `VERSION=$VERSION make push` +6. Build and push the container image to the staging registry `VERSION=$VERSION make push-all` 7. Publish a draft release using the tag you just created 8. Perform the [image promotion process](https://github.com/kubernetes/k8s.io/tree/master/k8s.gcr.io#image-promoter) 9. Publish release diff --git a/docs/user-guide.md b/docs/user-guide.md index 342d75cfe..63a371e25 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -3,6 +3,16 @@ Starting with descheduler release v0.10.0 container images are available in the official k8s container registry. * `k8s.gcr.io/descheduler/descheduler` +Also, starting with descheduler release v0.20.0 multi-arch container images are provided. Currently AMD64 and ARM64 +container images are provided. Multi-arch container images cannot be pulled by [kind](https://kind.sigs.k8s.io) from +a registry. Therefore starting with descheduler release v0.20.0 use the below process to download the official descheduler +image into a kind cluster. +``` +kind create cluster +docker pull k8s.gcr.io/descheduler/descheduler:v0.20.0 +kind load docker-image k8s.gcr.io/descheduler/descheduler:v0.20.0 +``` + ## Policy Configuration Examples The [examples](https://github.com/kubernetes-sigs/descheduler/tree/master/examples) directory has descheduler policy configuration examples.