Skip to content

Commit

Permalink
Merge pull request #500 from jcaamano/master
Browse files Browse the repository at this point in the history
Set Major and Minor in kubernetes version info
  • Loading branch information
briandowns authored Nov 3, 2020
2 parents aeb2f9e + ce02a4d commit 6f91705
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,23 @@ WORKDIR ${GOPATH}/src/github.com/kubernetes/kubernetes
# force code generation
RUN make WHAT=cmd/kube-apiserver
ARG TAG
ARG MAJOR
ARG MINOR
# build statically linked executables
RUN echo "export GIT_COMMIT=$(git rev-parse HEAD)" \
>> /usr/local/go/bin/go-build-static-k8s.sh
RUN echo "export BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
>> /usr/local/go/bin/go-build-static-k8s.sh
RUN echo "export GO_LDFLAGS=\"-linkmode=external \
-X k8s.io/component-base/version.gitVersion=${TAG} \
-X k8s.io/component-base/version.gitMajor=${MAJOR} \
-X k8s.io/component-base/version.gitMinor=${MINOR} \
-X k8s.io/component-base/version.gitCommit=\${GIT_COMMIT} \
-X k8s.io/component-base/version.gitTreeState=clean \
-X k8s.io/component-base/version.buildDate=\${BUILD_DATE} \
-X k8s.io/client-go/pkg/version.gitVersion=${TAG} \
-X k8s.io/client-go/pkg/version.gitMajor=${MAJOR} \
-X k8s.io/client-go/pkg/version.gitMinor=${MINOR} \
-X k8s.io/client-go/pkg/version.gitCommit=\${GIT_COMMIT} \
-X k8s.io/client-go/pkg/version.gitTreeState=clean \
-X k8s.io/client-go/pkg/version.buildDate=\${BUILD_DATE} \
Expand Down
2 changes: 2 additions & 0 deletions scripts/build-image-kubernetes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ source ./scripts/version.sh

DOCKER_BUILDKIT=${DOCKER_BUILDKIT:-1} docker image build \
--build-arg TAG=${VERSION} \
--build-arg MAJOR=${VERSION_MAJOR} \
--build-arg MINOR=${VERSION_MINOR} \
--build-arg KUBERNETES_VERSION=${KUBERNETES_VERSION} \
--tag ${REPO}/hardened-kubernetes:${DOCKERIZED_VERSION} \
--tag ${REPO}/hardened-kubernetes:${DOCKERIZED_VERSION}-${GOARCH} \
Expand Down
5 changes: 5 additions & 0 deletions scripts/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@ else
VERSION="${KUBERNETES_VERSION}-dev+${COMMIT:0:8}$DIRTY"
fi

if [[ "${VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?([-+].*)?$ ]]; then
VERSION_MAJOR=${BASH_REMATCH[1]}
VERSION_MINOR=${BASH_REMATCH[2]}
fi

DOCKERIZED_VERSION="${VERSION/+/-}" # this mimics what kubernetes builds do

0 comments on commit 6f91705

Please sign in to comment.