diff --git a/multidimensional-pod-autoscaler/hack/update-codegen.sh b/multidimensional-pod-autoscaler/hack/update-codegen.sh index af6418bacd19..6a2a0b12b0d1 100755 --- a/multidimensional-pod-autoscaler/hack/update-codegen.sh +++ b/multidimensional-pod-autoscaler/hack/update-codegen.sh @@ -18,18 +18,29 @@ set -o errexit set -o nounset set -o pipefail -SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/.. -CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../../code-generator)} +GO_CMD=${1:-go} +CURRENT_DIR=$(dirname "${BASH_SOURCE[0]}") +REPO_ROOT="$(git rev-parse --show-toplevel)" +CODEGEN_PKG=$($GO_CMD list -m -mod=readonly -f "{{.Dir}}" k8s.io/code-generator) +cd "${CURRENT_DIR}/.." +# shellcheck source=/dev/null source "${CODEGEN_PKG}/kube_codegen.sh" kube::codegen::gen_helpers \ - "$(dirname ${BASH_SOURCE})/../pkg/apis" \ - --boilerplate "${SCRIPT_ROOT}"/hack/boilerplate.go.txt + "$(dirname ${BASH_SOURCE})/../pkg/apis" \ + --boilerplate "${REPO_ROOT}/hack/boilerplate/boilerplate.generatego.txt" + +echo "Ran gen helpers, moving on to generating client code..." kube::codegen::gen_client \ "$(dirname ${BASH_SOURCE})/../pkg/apis" \ --output-pkg k8s.io/autoscaler/multidimensional-pod-autoscaler/pkg/client \ --output-dir "$(dirname ${BASH_SOURCE})/../pkg/client" \ - --boilerplate "${SCRIPT_ROOT}"/hack/boilerplate.go.txt \ + --boilerplate "${REPO_ROOT}/hack/boilerplate/boilerplate.generatego.txt" \ --with-watch + +echo "Generated client code, running `go mod tidy`..." + +# We need to clean up the go.mod file since code-generator adds temporary library to the go.mod file. +"${GO_CMD}" mod tidy diff --git a/multidimensional-pod-autoscaler/pkg/admission-controller/Dockerfile b/multidimensional-pod-autoscaler/pkg/admission-controller/Dockerfile index 55db2857a008..c5ef15d76268 100644 --- a/multidimensional-pod-autoscaler/pkg/admission-controller/Dockerfile +++ b/multidimensional-pod-autoscaler/pkg/admission-controller/Dockerfile @@ -1,4 +1,4 @@ -# Copyright 2024 The Kubernetes Authors. All rights reserved +# Copyright 2018 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. @@ -12,22 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM --platform=$BUILDPLATFORM golang:1.23.3 AS builder +FROM --platform=$BUILDPLATFORM golang:1.23.4 AS builder -ENV GOPATH=/gopath/ -ENV PATH=$GOPATH/bin:$PATH +WORKDIR /workspace -COPY . /gopath/src/k8s.io/autoscaler/multidimensional-pod-autoscaler -WORKDIR /gopath/src/k8s.io/autoscaler/multidimensional-pod-autoscaler +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum + +RUN go mod download + +COPY common common +COPY pkg pkg ARG TARGETOS TARGETARCH -RUN CGO_ENABLED=0 LD_FLAGS=-s GOARCH=$TARGETARCH GOOS=$TARGETOS go build -C pkg/admission-controller -mod vendor -o admission-controller-$TARGETARCH +RUN CGO_ENABLED=0 LD_FLAGS=-s GOARCH=$TARGETARCH GOOS=$TARGETOS go build -C pkg/admission-controller -o admission-controller-$TARGETARCH FROM gcr.io/distroless/static:latest ARG TARGETARCH -COPY --from=builder /gopath/src/k8s.io/autoscaler/multidimensional-pod-autoscaler/pkg/admission-controller/admission-controller-$TARGETARCH /admission-controller +COPY --from=builder /workspace/pkg/admission-controller/admission-controller-$TARGETARCH /admission-controller ENTRYPOINT ["/admission-controller"] diff --git a/multidimensional-pod-autoscaler/pkg/recommender/Dockerfile b/multidimensional-pod-autoscaler/pkg/recommender/Dockerfile index 3441cea0ea1d..26f7b20f0a1d 100644 --- a/multidimensional-pod-autoscaler/pkg/recommender/Dockerfile +++ b/multidimensional-pod-autoscaler/pkg/recommender/Dockerfile @@ -12,22 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM --platform=$BUILDPLATFORM golang:1.23.3 AS builder +FROM --platform=$BUILDPLATFORM golang:1.23.4 AS builder -ENV GOPATH=/gopath/ -ENV PATH=$GOPATH/bin:$PATH +WORKDIR /workspace -COPY . /gopath/src/k8s.io/autoscaler/multidimensional-pod-autoscaler -WORKDIR /gopath/src/k8s.io/autoscaler/multidimensional-pod-autoscaler +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum + +RUN go mod download + +COPY common common +COPY pkg pkg ARG TARGETOS TARGETARCH -RUN CGO_ENABLED=0 LD_FLAGS=-s GOARCH=$TARGETARCH GOOS=$TARGETOS go build -C pkg/recommender -mod vendor -o recommender-$TARGETARCH +RUN CGO_ENABLED=0 LD_FLAGS=-s GOARCH=$TARGETARCH GOOS=$TARGETOS go build -C pkg/recommender -o recommender-$TARGETARCH FROM gcr.io/distroless/static:latest ARG TARGETARCH -COPY --from=builder /gopath/src/k8s.io/autoscaler/multidimensional-pod-autoscaler/pkg/recommender/recommender-$TARGETARCH /recommender +COPY --from=builder /workspace/pkg/recommender/recommender-$TARGETARCH /recommender ENTRYPOINT ["/recommender"] diff --git a/multidimensional-pod-autoscaler/pkg/updater/Dockerfile b/multidimensional-pod-autoscaler/pkg/updater/Dockerfile index d8703436bdc4..63de33b1fa32 100644 --- a/multidimensional-pod-autoscaler/pkg/updater/Dockerfile +++ b/multidimensional-pod-autoscaler/pkg/updater/Dockerfile @@ -12,22 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM --platform=$BUILDPLATFORM golang:1.23.3 AS builder +FROM --platform=$BUILDPLATFORM golang:1.23.4 AS builder -ENV GOPATH=/gopath/ -ENV PATH=$GOPATH/bin:$PATH +WORKDIR /workspace -COPY . /gopath/src/k8s.io/autoscaler/multidimensional-pod-autoscaler -WORKDIR /gopath/src/k8s.io/autoscaler/multidimensional-pod-autoscaler +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum + +RUN go mod download + +COPY common common +COPY pkg pkg ARG TARGETOS TARGETARCH -RUN CGO_ENABLED=0 LD_FLAGS=-s GOARCH=$TARGETARCH GOOS=$TARGETOS go build -C pkg/updater -mod vendor -o updater-$TARGETARCH +RUN CGO_ENABLED=0 LD_FLAGS=-s GOARCH=$TARGETARCH GOOS=$TARGETOS go build -C pkg/updater -o updater-$TARGETARCH FROM gcr.io/distroless/static:latest ARG TARGETARCH -COPY --from=builder /gopath/src/k8s.io/autoscaler/multidimensional-pod-autoscaler/pkg/updater/updater-$TARGETARCH /updater +COPY --from=builder /workspace/pkg/updater/updater-$TARGETARCH /updater ENTRYPOINT ["/updater"]