Skip to content

Commit

Permalink
Merge pull request #3123 from povilasv/multiarch
Browse files Browse the repository at this point in the history
vpa: add multiarch builds
  • Loading branch information
k8s-ci-robot authored Aug 20, 2020
2 parents f26eba8 + 66b37fc commit 9565ee1
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 36 deletions.
3 changes: 3 additions & 0 deletions vertical-pod-autoscaler/builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ LABEL maintainer="Beata Skiba <[email protected]>"
ENV GOPATH /gopath/
ENV PATH $GOPATH/bin:$PATH

ARG GOARCH
ARG LDFLAGS

RUN go version
RUN go get github.com/tools/godep
RUN godep version
Expand Down
5 changes: 5 additions & 0 deletions vertical-pod-autoscaler/pkg/admission-controller/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Admission Controller binary
admission-controller
admission-controller-amd64
admission-controller-arm64
admission-controller-arm
admission-controller-ppc64le
admission-controller-s390x
4 changes: 2 additions & 2 deletions vertical-pod-autoscaler/pkg/admission-controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

FROM gcr.io/distroless/static:latest
MAINTAINER Tomasz Kulczynski "[email protected]"

copy admission-controller /
ARG ARCH
copy admission-controller-$ARCH /admission-controller

ENTRYPOINT ["/admission-controller"]
CMD ["--v=4", "--stderrthreshold=info"]
53 changes: 43 additions & 10 deletions vertical-pod-autoscaler/pkg/admission-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ ENVVAR=CGO_ENABLED=0 $(TEST_ENVVAR)
GOOS?=linux
COMPONENT=admission-controller
FULL_COMPONENT=vpa-${COMPONENT}
ARCH?=amd64

ALL_ARCHITECTURES=amd64 arm arm64 ppc64le s390x
export DOCKER_CLI_EXPERIMENTAL=enabled

build: clean
$(ENVVAR) GOOS=$(GOOS) go build ./...
Expand All @@ -16,13 +20,21 @@ build: clean
build-binary: clean
$(ENVVAR) GOOS=$(GOOS) go build -o ${COMPONENT}

build-binary-with-vendor: clean
$(ENVVAR) GOOS=$(GOOS) go build -mod vendor -o ${COMPONENT}
.PHONY: build-binary-with-vendor
build-binary-with-vendor: $(addprefix build-binary-with-vendor-,$(ALL_ARCHITECTURES)) clean

.PHONY: build-binary-with-vendor-*
build-binary-with-vendor-%:
$(ENVVAR) GOARCH=$* GOOS=$(GOOS) go build -mod vendor -o ${COMPONENT}-$*

test-unit: clean build
$(TEST_ENVVAR) go test --test.short -race ./... $(FLAGS)

docker-build:
.PHONY: docker-build
docker-build: $(addprefix docker-build-,$(ALL_ARCHITECTURES))

.PHONY: docker-build-*
docker-build-%:
ifndef REGISTRY
ERR = $(error REGISTRY is undefined)
$(ERR)
Expand All @@ -31,9 +43,16 @@ ifndef TAG
ERR = $(error TAG is undefined)
$(ERR)
endif
docker build --pull -t ${REGISTRY}/${FULL_COMPONENT}:${TAG} .
docker build --pull -t ${REGISTRY}/${FULL_COMPONENT}-$*:${TAG} --build-arg ARCH=$* .

.PHONY: docker-push
docker-push: $(addprefix sub-push-,$(ALL_ARCHITECTURES)) push-multi-arch;

.PHONY: sub-push-*
sub-push-%: docker-build-% do-push-% ;

docker-push:
.PHONY: do-push-*
do-push-%:
ifndef REGISTRY
ERR = $(error REGISTRY is undefined)
$(ERR)
Expand All @@ -42,19 +61,33 @@ ifndef TAG
ERR = $(error TAG is undefined)
$(ERR)
endif
docker push ${REGISTRY}/${FULL_COMPONENT}:${TAG}
docker push ${REGISTRY}/${FULL_COMPONENT}-$*:${TAG}

.PHONY: push-multi-arch
push-multi-arch:
docker manifest create --amend $(REGISTRY)/${FULL_COMPONENT}:$(TAG) $(shell echo $(ALL_ARCHITECTURES) | sed -e "s~[^ ]*~$(REGISTRY)/${FULL_COMPONENT}\-&:$(TAG)~g")
@for arch in $(ALL_ARCHITECTURES); do docker manifest annotate --arch $${arch} $(REGISTRY)/${FULL_COMPONENT}:$(TAG) $(REGISTRY)/${FULL_COMPONENT}-$${arch}:${TAG}; done
docker manifest push --purge $(REGISTRY)/${FULL_COMPONENT}:$(TAG)

docker-builder:
docker build -t vpa-autoscaling-builder ../../builder

build-in-docker: clean docker-builder
docker run -v `pwd`/../..:/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler vpa-autoscaling-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler && make build-binary-with-vendor -C pkg/admission-controller'
.PHONY: build-in-docker
build-in-docker: $(addprefix build-in-docker-,$(ALL_ARCHITECTURES))

.PHONY: build-in-docker-*
build-in-docker-%: clean docker-builder
docker run -v `pwd`/../..:/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler vpa-autoscaling-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler && make build-binary-with-vendor-$* -C pkg/admission-controller'


.PHONY: release
release: build-in-docker docker-build docker-push
@echo "Full in-docker release ${FULL_COMPONENT}:${TAG} completed"

clean:
rm -f ${COMPONENT}
clean: $(addprefix clean-,$(ALL_ARCHITECTURES))

clean-%:
rm -f ${COMPONENT}-$*

format:
test -z "$$(find . -path ./vendor -prune -type f -o -name '*.go' -exec gofmt -s -d {} + | tee /dev/stderr)" || \
Expand Down
5 changes: 5 additions & 0 deletions vertical-pod-autoscaler/pkg/recommender/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Recommender binary
recommender
recommender-amd64
recommender-arm64
recommender-arm
recommender-ppc64le
recommender-s390x
3 changes: 2 additions & 1 deletion vertical-pod-autoscaler/pkg/recommender/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
FROM gcr.io/distroless/static:latest
MAINTAINER Krzysztof Grygiel "[email protected]"

COPY recommender /
ARG ARCH
COPY recommender-$ARCH /recommender

ENTRYPOINT ["/recommender"]
CMD ["--v=4", "--stderrthreshold=info", "--prometheus-address=http://prometheus.monitoring.svc"]
51 changes: 41 additions & 10 deletions vertical-pod-autoscaler/pkg/recommender/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ ENVVAR=CGO_ENABLED=0 $(TEST_ENVVAR)
GOOS?=linux
COMPONENT=recommender
FULL_COMPONENT=vpa-${COMPONENT}
ARCH?=amd64

ALL_ARCHITECTURES=amd64 arm arm64 ppc64le s390x
export DOCKER_CLI_EXPERIMENTAL=enabled

build: clean
$(ENVVAR) GOOS=$(GOOS) go build ./...
Expand All @@ -16,13 +20,21 @@ build: clean
build-binary: clean
$(ENVVAR) GOOS=$(GOOS) go build -o ${COMPONENT}

build-binary-with-vendor: clean
$(ENVVAR) GOOS=$(GOOS) go build -mod vendor -o ${COMPONENT}
.PHONY: build-binary-with-vendor
build-binary-with-vendor: $(addprefix build-binary-with-vendor-,$(ALL_ARCHITECTURES)) clean

.PHONY: build-binary-with-vendor-*
build-binary-with-vendor-%:
$(ENVVAR) GOARCH=$* GOOS=$(GOOS) go build -mod vendor -o ${COMPONENT}-$*

test-unit: clean build
$(TEST_ENVVAR) go test --test.short -race ./... $(FLAGS)

docker-build:
.PHONY: docker-build
docker-build: $(addprefix docker-build-,$(ALL_ARCHITECTURES))

.PHONY: docker-build-*
docker-build-%:
ifndef REGISTRY
ERR = $(error REGISTRY is undefined)
$(ERR)
Expand All @@ -31,9 +43,16 @@ ifndef TAG
ERR = $(error TAG is undefined)
$(ERR)
endif
docker build --pull -t ${REGISTRY}/${FULL_COMPONENT}:${TAG} .
docker build --pull -t ${REGISTRY}/${FULL_COMPONENT}-$*:${TAG} --build-arg ARCH=$* .

.PHONY: docker-push
docker-push: $(addprefix sub-push-,$(ALL_ARCHITECTURES)) push-multi-arch;

docker-push:
.PHONY: sub-push-*
sub-push-%: docker-build-% do-push-% ;

.PHONY: do-push-*
do-push-%:
ifndef REGISTRY
ERR = $(error REGISTRY is undefined)
$(ERR)
Expand All @@ -42,19 +61,31 @@ ifndef TAG
ERR = $(error TAG is undefined)
$(ERR)
endif
docker push ${REGISTRY}/${FULL_COMPONENT}:${TAG}
docker push ${REGISTRY}/${FULL_COMPONENT}-$*:${TAG}

.PHONY: push-multi-arch
push-multi-arch:
docker manifest create --amend $(REGISTRY)/${FULL_COMPONENT}:$(TAG) $(shell echo $(ALL_ARCHITECTURES) | sed -e "s~[^ ]*~$(REGISTRY)/${FULL_COMPONENT}\-&:$(TAG)~g")
@for arch in $(ALL_ARCHITECTURES); do docker manifest annotate --arch $${arch} $(REGISTRY)/${FULL_COMPONENT}:$(TAG) $(REGISTRY)/${FULL_COMPONENT}-$${arch}:${TAG}; done
docker manifest push --purge $(REGISTRY)/${FULL_COMPONENT}:$(TAG)

docker-builder:
docker build -t vpa-autoscaling-builder ../../builder

build-in-docker: clean docker-builder
docker run -v `pwd`/../..:/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler vpa-autoscaling-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler && make build-binary-with-vendor -C pkg/recommender'
.PHONY: build-in-docker
build-in-docker: $(addprefix build-in-docker-,$(ALL_ARCHITECTURES))

.PHONY: build-in-docker-*
build-in-docker-%: clean docker-builder
docker run -v `pwd`/../..:/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler vpa-autoscaling-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler && make build-binary-with-vendor-$* -C pkg/recommender'

release: build-in-docker docker-build docker-push
@echo "Full in-docker release ${FULL_COMPONENT}:${TAG} completed"

clean:
rm -f ${COMPONENT}
clean: $(addprefix clean-,$(ALL_ARCHITECTURES))

clean-%:
rm -f ${COMPONENT}-$*

format:
test -z "$$(find . -path ./vendor -prune -type f -o -name '*.go' -exec gofmt -s -d {} + | tee /dev/stderr)" || \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/stretchr/testify/mock"

"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
Expand Down Expand Up @@ -58,6 +58,7 @@ spec:
memory: "1024Mi"
cpu: "1000m"
`

const pod2Yaml = `
apiVersion: v1
kind: Pod
Expand Down Expand Up @@ -121,7 +122,8 @@ func newSpecClientTestCase() *specClientTestCase {
podYamls: []string{pod1Yaml, pod2Yaml},
}
}
func newTestContainerSpec(podID model.PodID, containerName string, milicores int, memory int) BasicContainerSpec {

func newTestContainerSpec(podID model.PodID, containerName string, milicores int, memory int64) BasicContainerSpec {
containerID := model.ContainerID{
PodID: podID,
ContainerName: containerName,
Expand Down
5 changes: 5 additions & 0 deletions vertical-pod-autoscaler/pkg/updater/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
# Updater binary
updater
updater-amd64
updater-arm64
updater-arm
updater-ppc64le
updater-s390x
3 changes: 2 additions & 1 deletion vertical-pod-autoscaler/pkg/updater/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
FROM gcr.io/distroless/static:latest
MAINTAINER Marcin Wielgus "[email protected]"

COPY updater /
ARG ARCH
COPY updater-$ARCH /updater

ENTRYPOINT ["/updater"]
CMD ["--v=4", "--stderrthreshold=info"]
52 changes: 42 additions & 10 deletions vertical-pod-autoscaler/pkg/updater/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ ENVVAR=CGO_ENABLED=0 $(TEST_ENVVAR)
GOOS?=linux
COMPONENT=updater
FULL_COMPONENT=vpa-${COMPONENT}
ARCH?=amd64

ALL_ARCHITECTURES=amd64 arm arm64 ppc64le s390x
export DOCKER_CLI_EXPERIMENTAL=enabled

build: clean
$(ENVVAR) GOOS=$(GOOS) go build ./...
Expand All @@ -16,13 +20,21 @@ build: clean
build-binary: clean
$(ENVVAR) GOOS=$(GOOS) go build -o ${COMPONENT}

build-binary-with-vendor: clean
$(ENVVAR) GOOS=$(GOOS) go build -mod vendor -o ${COMPONENT}
.PHONY: build-binary-with-vendor
build-binary-with-vendor: $(addprefix build-binary-with-vendor-,$(ALL_ARCHITECTURES)) clean

.PHONY: build-binary-with-vendor-*
build-binary-with-vendor-%:
$(ENVVAR) GOARCH=$* GOOS=$(GOOS) go build -mod vendor -o ${COMPONENT}-$*

test-unit: clean build
$(TEST_ENVVAR) go test --test.short -race ./... $(FLAGS)

docker-build:
.PHONY: docker-build
docker-build: $(addprefix docker-build-,$(ALL_ARCHITECTURES))

.PHONY: docker-build-*
docker-build-%:
ifndef REGISTRY
ERR = $(error REGISTRY is undefined)
$(ERR)
Expand All @@ -31,9 +43,16 @@ ifndef TAG
ERR = $(error TAG is undefined)
$(ERR)
endif
docker build --pull -t ${REGISTRY}/${FULL_COMPONENT}:${TAG} .
docker build --pull -t ${REGISTRY}/${FULL_COMPONENT}-$*:${TAG} --build-arg ARCH=$* .

.PHONY: docker-push
docker-push: $(addprefix sub-push-,$(ALL_ARCHITECTURES)) push-multi-arch;

docker-push:
.PHONY: sub-push-*
sub-push-%: docker-build-% do-push-% ;

.PHONY: do-push-*
do-push-%:
ifndef REGISTRY
ERR = $(error REGISTRY is undefined)
$(ERR)
Expand All @@ -42,19 +61,32 @@ ifndef TAG
ERR = $(error TAG is undefined)
$(ERR)
endif
docker push ${REGISTRY}/${FULL_COMPONENT}:${TAG}
docker push ${REGISTRY}/${FULL_COMPONENT}-$*:${TAG}

.PHONY: push-multi-arch
push-multi-arch:
docker manifest create --amend $(REGISTRY)/${FULL_COMPONENT}:$(TAG) $(shell echo $(ALL_ARCHITECTURES) | sed -e "s~[^ ]*~$(REGISTRY)/${FULL_COMPONENT}\-&:$(TAG)~g")
@for arch in $(ALL_ARCHITECTURES); do docker manifest annotate --arch $${arch} $(REGISTRY)/${FULL_COMPONENT}:$(TAG) $(REGISTRY)/${FULL_COMPONENT}-$${arch}:${TAG}; done
docker manifest push --purge $(REGISTRY)/${FULL_COMPONENT}:$(TAG)

docker-builder:
docker build -t vpa-autoscaling-builder ../../builder

build-in-docker: clean docker-builder
docker run -v `pwd`/../..:/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler vpa-autoscaling-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler && make build-binary-with-vendor -C pkg/updater'
.PHONY: build-in-docker
build-in-docker: $(addprefix build-in-docker-,$(ALL_ARCHITECTURES))

.PHONY: build-in-docker-*
build-in-docker-%: clean docker-builder
docker run -v `pwd`/../..:/gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler vpa-autoscaling-builder:latest bash -c 'cd /gopath/src/k8s.io/autoscaler/vertical-pod-autoscaler && make build-binary-with-vendor-$* -C pkg/updater'

.PHONY: release
release: build-in-docker docker-build docker-push
@echo "Full in-docker release ${FULL_COMPONENT}:${TAG} completed"

clean:
rm -f ${COMPONENT}
clean: $(addprefix clean-,$(ALL_ARCHITECTURES))

clean-%:
rm -f ${COMPONENT}-$*

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

0 comments on commit 9565ee1

Please sign in to comment.