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

vpa: add multiarch builds #3123

Merged
merged 1 commit into from Aug 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions vertical-pod-autoscaler/builder/Dockerfile
Expand Up @@ -18,6 +18,9 @@ LABEL maintainer="Beata Skiba <bskiba@google.com>"
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
@@ -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
Expand Up @@ -14,8 +14,8 @@

FROM gcr.io/distroless/static:latest
MAINTAINER Tomasz Kulczynski "tkulczynski@google.com"

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
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
@@ -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
Expand Up @@ -15,7 +15,8 @@
FROM gcr.io/distroless/static:latest
MAINTAINER Krzysztof Grygiel "kgrygiel@google.com"

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
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
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
@@ -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
Expand Up @@ -16,7 +16,8 @@
FROM gcr.io/distroless/static:latest
MAINTAINER Marcin Wielgus "mwielgus@google.com"

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
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