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

[cluster-autoscaler] Add build support for ARM64 #3714

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ARG BASEIMAGE=gcr.io/distroless/static:latest
ARG BASEIMAGE=gcr.io/distroless/static:latest-amd64
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this make use of an additional ARG for the architecture to avoid having to have two separate docker files?

Copy link
Member Author

Choose a reason for hiding this comment

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

The ARG would work here, but not further when copying the binary. Not sure if there's a good way to not add both ARG and ENV var. Separate Dockerfile seemed cleaner.

FROM $BASEIMAGE
LABEL maintainer="Marcin Wielgus <[email protected]>"

COPY cluster-autoscaler /
COPY cluster-autoscaler-amd64 /cluster-autoscaler
CMD ["/cluster-autoscaler"]
19 changes: 19 additions & 0 deletions cluster-autoscaler/Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2016 The Kubernetes Authors. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ARG BASEIMAGE=gcr.io/distroless/static:latest-arm64
FROM $BASEIMAGE
LABEL maintainer="Marcin Wielgus <[email protected]>"

COPY cluster-autoscaler-arm64 /cluster-autoscaler
CMD ["/cluster-autoscaler"]
81 changes: 55 additions & 26 deletions cluster-autoscaler/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
all: build
ALL_ARCH = amd64 arm64
all: $(addprefix build-arch-,$(ALL_ARCH))

TAG?=dev
FLAGS=
LDFLAGS?=-s
ENVVAR=CGO_ENABLED=0 GO111MODULE=off
GOOS?=linux
GOARCH?=$(shell go env GOARCH)
REGISTRY?=staging-k8s.gcr.io
DOCKER_NETWORK?=default
ifdef BUILD_TAGS
Expand All @@ -27,56 +29,83 @@ else
RM_FLAG=
endif

build: clean deps
$(ENVVAR) GOOS=$(GOOS) go build ${LDFLAGS_FLAG} ${TAGS_FLAG} ./...
$(ENVVAR) GOOS=$(GOOS) go build -o cluster-autoscaler ${LDFLAGS_FLAG} ${TAGS_FLAG}
build: build-arch-$(GOARCH)

build-binary: clean deps
$(ENVVAR) GOOS=$(GOOS) go build -o cluster-autoscaler ${LDFLAGS_FLAG} ${TAGS_FLAG}
build-arch-%: clean-arch-%
$(ENVVAR) GOOS=$(GOOS) GOARCH=$* go build ${LDFLAGS_FLAG} ${TAGS_FLAG} ./...
$(ENVVAR) GOOS=$(GOOS) GOARCH=$* go build -o cluster-autoscaler-$* ${LDFLAGS_FLAG} ${TAGS_FLAG}

test-unit: clean deps build
build-binary: build-binary-arch-$(GOARCH)

build-binary-arch-%: clean-arch-%
$(ENVVAR) GOOS=$(GOOS) GOARCH=$* go build -o cluster-autoscaler-$* ${LDFLAGS_FLAG} ${TAGS_FLAG}

test-unit: clean build
GO111MODULE=off go test --test.short -race ./... ${TAGS_FLAG}

dev-release: build-binary execute-release
@echo "Release ${TAG}${FOR_PROVIDER} completed"
dev-release: dev-release-arch-$(GOARCH)

make-image:
dev-release-arch-%: build-binary-arch-% make-image-arch-% push-image-arch-%
@echo "Release ${TAG}${FOR_PROVIDER}-$* completed"

make-image: make-image-arch-$(GOARCH)

make-image-arch-%:
ifdef BASEIMAGE
docker build --pull --build-arg BASEIMAGE=${BASEIMAGE} \
-t ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG} .
-t ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG}-$* \
-f Dockerfile.$* .
else
docker build --pull -t ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG} .
docker build --pull \
-t ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG}-$* \
-f Dockerfile.$* .
endif
@echo "Image ${TAG}${FOR_PROVIDER}-$* completed"

push-image: push-image-arch-$(GOARCH)

push-image:
./push_image.sh ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG}
push-image-arch-%:
./push_image.sh ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG}-$*

execute-release: make-image push-image
push-manifest:
hakman marked this conversation as resolved.
Show resolved Hide resolved
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG} \
$(addprefix $(REGISTRY)/cluster-autoscaler$(PROVIDER):$(TAG)-, $(ALL_ARCH))
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG}

clean:
rm -f cluster-autoscaler
execute-release: $(addprefix make-image-arch-,$(ALL_ARCH)) $(addprefix push-image-arch-,$(ALL_ARCH)) push-manifest
@echo "Release ${TAG}${FOR_PROVIDER} completed"

clean: clean-arch-$(GOARCH)

clean-arch-%:
rm -f cluster-autoscaler-$*

generate:
go generate ./cloudprovider/aws

format:
test -z "$$(find . -path ./vendor -prune -type f -o -name '*.go' -exec gofmt -s -d {} + | tee /dev/stderr)" || \
test -z "$$(find . -path ./vendor -prune -type f -o -name '*.go' -exec gofmt -s -w {} + | tee /dev/stderr)"
test -z "$$(find . -path ./vendor -prune -type f -o -name '*.go' -exec gofmt -s -w {} + | tee /dev/stderr)"

docker-builder:
docker build --network=${DOCKER_NETWORK} -t autoscaling-builder ../builder

build-in-docker: clean docker-builder
docker run ${RM_FLAG} -v `pwd`:/gopath/src/k8s.io/autoscaler/cluster-autoscaler/:Z autoscaling-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/cluster-autoscaler && BUILD_TAGS=${BUILD_TAGS} LDFLAGS="${LDFLAGS}" make build-binary'
build-in-docker: build-in-docker-arch-$(GOARCH)

release: build-in-docker execute-release
build-in-docker-arch-%: clean-arch-% docker-builder
docker run ${RM_FLAG} -v `pwd`:/gopath/src/k8s.io/autoscaler/cluster-autoscaler/:Z autoscaling-builder:latest \
bash -c 'cd /gopath/src/k8s.io/autoscaler/cluster-autoscaler && BUILD_TAGS=${BUILD_TAGS} LDFLAGS="${LDFLAGS}" make build-binary-arch-$*'

release: $(addprefix build-in-docker-arch-,$(ALL_ARCH)) execute-release
@echo "Full in-docker release ${TAG}${FOR_PROVIDER} completed"

container: build-in-docker make-image
@echo "Created in-docker image ${TAG}${FOR_PROVIDER}"
container: container-arch-$(GOARCH)

test-in-docker: clean docker-builder
docker run ${RM_FLAG} -v `pwd`:/gopath/src/k8s.io/autoscaler/cluster-autoscaler/:Z autoscaling-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/cluster-autoscaler && GO111MODULE=off go test -race ./... ${TAGS_FLAG}'
container-arch-%: build-in-docker-arch-% make-image-arch-%
@echo "Full in-docker image ${TAG}${FOR_PROVIDER}-$* completed"

.PHONY: all deps build test-unit clean format execute-release dev-release docker-builder build-in-docker release generate
test-in-docker: clean docker-builder
docker run ${RM_FLAG} -v `pwd`:/gopath/src/k8s.io/autoscaler/cluster-autoscaler/:Z autoscaling-builder:latest \
bash -c 'cd /gopath/src/k8s.io/autoscaler/cluster-autoscaler && GO111MODULE=off go test -race ./... ${TAGS_FLAG}'

.PHONY: all build test-unit clean format execute-release dev-release docker-builder build-in-docker release generate push-image push-manifest