Skip to content

Commit 7a0731b

Browse files
authored
Merge pull request kubernetes#3714 from hakman/multi-arch-support
[cluster-autoscaler] Add build support for ARM64
2 parents aa9367f + ab2f8ec commit 7a0731b

File tree

3 files changed

+76
-28
lines changed

3 files changed

+76
-28
lines changed

cluster-autoscaler/Dockerfile renamed to cluster-autoscaler/Dockerfile.amd64

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
ARG BASEIMAGE=gcr.io/distroless/static:latest
14+
ARG BASEIMAGE=gcr.io/distroless/static:latest-amd64
1515
FROM $BASEIMAGE
1616
LABEL maintainer="Marcin Wielgus <[email protected]>"
1717

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

cluster-autoscaler/Makefile

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
all: build
1+
ALL_ARCH = amd64 arm64
2+
all: $(addprefix build-arch-,$(ALL_ARCH))
23

34
TAG?=dev
45
FLAGS=
56
LDFLAGS?=-s
67
ENVVAR=CGO_ENABLED=0 GO111MODULE=off
78
GOOS?=linux
9+
GOARCH?=$(shell go env GOARCH)
810
REGISTRY?=staging-k8s.gcr.io
911
DOCKER_NETWORK?=default
1012
ifdef BUILD_TAGS
@@ -27,56 +29,83 @@ else
2729
RM_FLAG=
2830
endif
2931

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

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

37-
test-unit: clean deps build
38+
build-binary: build-binary-arch-$(GOARCH)
39+
40+
build-binary-arch-%: clean-arch-%
41+
$(ENVVAR) GOOS=$(GOOS) GOARCH=$* go build -o cluster-autoscaler-$* ${LDFLAGS_FLAG} ${TAGS_FLAG}
42+
43+
test-unit: clean build
3844
GO111MODULE=off go test --test.short -race ./... ${TAGS_FLAG}
3945

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

43-
make-image:
48+
dev-release-arch-%: build-binary-arch-% make-image-arch-% push-image-arch-%
49+
@echo "Release ${TAG}${FOR_PROVIDER}-$* completed"
50+
51+
make-image: make-image-arch-$(GOARCH)
52+
53+
make-image-arch-%:
4454
ifdef BASEIMAGE
4555
docker build --pull --build-arg BASEIMAGE=${BASEIMAGE} \
46-
-t ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG} .
56+
-t ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG}-$* \
57+
-f Dockerfile.$* .
4758
else
48-
docker build --pull -t ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG} .
59+
docker build --pull \
60+
-t ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG}-$* \
61+
-f Dockerfile.$* .
4962
endif
63+
@echo "Image ${TAG}${FOR_PROVIDER}-$* completed"
64+
65+
push-image: push-image-arch-$(GOARCH)
5066

51-
push-image:
52-
./push_image.sh ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG}
67+
push-image-arch-%:
68+
./push_image.sh ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG}-$*
5369

54-
execute-release: make-image push-image
70+
push-manifest:
71+
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG} \
72+
$(addprefix $(REGISTRY)/cluster-autoscaler$(PROVIDER):$(TAG)-, $(ALL_ARCH))
73+
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge ${REGISTRY}/cluster-autoscaler${PROVIDER}:${TAG}
5574

56-
clean:
57-
rm -f cluster-autoscaler
75+
execute-release: $(addprefix make-image-arch-,$(ALL_ARCH)) $(addprefix push-image-arch-,$(ALL_ARCH)) push-manifest
76+
@echo "Release ${TAG}${FOR_PROVIDER} completed"
77+
78+
clean: clean-arch-$(GOARCH)
79+
80+
clean-arch-%:
81+
rm -f cluster-autoscaler-$*
5882

5983
generate:
6084
go generate ./cloudprovider/aws
6185

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

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

69-
build-in-docker: clean docker-builder
70-
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'
93+
build-in-docker: build-in-docker-arch-$(GOARCH)
7194

72-
release: build-in-docker execute-release
95+
build-in-docker-arch-%: clean-arch-% docker-builder
96+
docker run ${RM_FLAG} -v `pwd`:/gopath/src/k8s.io/autoscaler/cluster-autoscaler/:Z autoscaling-builder:latest \
97+
bash -c 'cd /gopath/src/k8s.io/autoscaler/cluster-autoscaler && BUILD_TAGS=${BUILD_TAGS} LDFLAGS="${LDFLAGS}" make build-binary-arch-$*'
98+
99+
release: $(addprefix build-in-docker-arch-,$(ALL_ARCH)) execute-release
73100
@echo "Full in-docker release ${TAG}${FOR_PROVIDER} completed"
74101

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

78-
test-in-docker: clean docker-builder
79-
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}'
104+
container-arch-%: build-in-docker-arch-% make-image-arch-%
105+
@echo "Full in-docker image ${TAG}${FOR_PROVIDER}-$* completed"
80106

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

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

0 commit comments

Comments
 (0)