From 94ac896269323a1be22048da9e0884326cf37e28 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Wed, 11 Aug 2021 09:02:06 +0000 Subject: [PATCH] test images: Simplifies the agnhost binary version Currently, whenever agnhost/VERSION is bumped, the version in agnhost/agnhost.go has to be bumped as well. This is also verified on presubmit (build/dependencies.yaml). This means that whenever we need to bump the agnhost image version, someone has to approve the build/dependencies.yaml, which is not as easy. This commit removes the need for this check by automatically setting the Version inside agnhost.go at build time, simplifying the process. --- build/dependencies.yaml | 16 ---------------- test/images/README.md | 3 +-- test/images/agnhost/Makefile | 2 ++ test/images/agnhost/README.md | 8 -------- test/images/agnhost/VERSION | 2 +- test/images/agnhost/agnhost.go | 4 +++- test/images/image-util.sh | 2 +- 7 files changed, 8 insertions(+), 29 deletions(-) diff --git a/build/dependencies.yaml b/build/dependencies.yaml index 52e16320765..0e7b714dc40 100644 --- a/build/dependencies.yaml +++ b/build/dependencies.yaml @@ -16,22 +16,6 @@ dependencies: - path: hack/tools/go.mod match: sigs.k8s.io/zeitgeist\ v(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))? - # agnhost: bump this one first - - name: "agnhost" - version: "2.32" - refPaths: - - path: test/images/agnhost/VERSION - match: \d.\d - - path: test/images/agnhost/agnhost.go - match: "Version:" - - # then after merge and successful postsubmit image push / promotion, bump this - - name: "agnhost: dependents" - version: "2.32" - refPaths: - - path: test/utils/image/manifest.go - match: configs\[Agnhost\] = Config{list\.PromoterE2eRegistry, "agnhost", "\d+\.\d+"} - # CNI plugins - name: "cni" version: 0.9.1 diff --git a/test/images/README.md b/test/images/README.md index 583f155c991..0990e66d8ef 100644 --- a/test/images/README.md +++ b/test/images/README.md @@ -104,8 +104,7 @@ These images are then used by the rest of the E2E test images as a cache / base Make updates to the functionality of the images required for your test case and update the version number. The version can easily be bumped by modifying the file `test/images/${IMAGE_NAME}/VERSION`, which will -be used when building the image. Additionally, for the `agnhost` image, also bump the `Version` in -`test/images/agnhost/agnhost.go`. +be used when building the image. Some test images (`agnhost`) are used as bases for other images (`kitten`, `nautilus`). If the parent image's `VERSION` has been bumped, also bump the version in the children's `BASEIMAGE` files in order diff --git a/test/images/agnhost/Makefile b/test/images/agnhost/Makefile index 943f68d4b06..99cdd475542 100644 --- a/test/images/agnhost/Makefile +++ b/test/images/agnhost/Makefile @@ -19,6 +19,8 @@ TARGET ?= $(CURDIR) GOARM ?= 7 GOLANG_VERSION ?= latest SRC_DIR = $(notdir $(shell pwd)) +VERSION = $(shell cat VERSION) +LD_FLAGS = -X 'main.Version=$(VERSION)' export bin: diff --git a/test/images/agnhost/README.md b/test/images/agnhost/README.md index ef84e1d2be4..e0d0c259869 100644 --- a/test/images/agnhost/README.md +++ b/test/images/agnhost/README.md @@ -16,14 +16,6 @@ The image was created for testing purposes, reducing the need for having differe cases for the same tested behaviour. -## Developer notes - -We've introduced versioning into the `agnhost` binary for debugging purposes (e.g.: if the -image and binary versions do not match, see [here](https://github.com/kubernetes/kubernetes/pull/79667#discussion_r304198370)). - -Whenever the image `VERSION` is bumped, the `Version` in `agnhost.go` will also have to be bumped. - - ## Usage The `agnhost` binary has several subcommands which are can be used to test different diff --git a/test/images/agnhost/VERSION b/test/images/agnhost/VERSION index 0f34dc7f370..f3283c08e18 100644 --- a/test/images/agnhost/VERSION +++ b/test/images/agnhost/VERSION @@ -1 +1 @@ -2.32 +2.33 diff --git a/test/images/agnhost/agnhost.go b/test/images/agnhost/agnhost.go index 3118cc1bcae..2c517e5be95 100644 --- a/test/images/agnhost/agnhost.go +++ b/test/images/agnhost/agnhost.go @@ -48,10 +48,12 @@ import ( "k8s.io/kubernetes/test/images/agnhost/webhook" ) +var Version = "development" + func main() { rootCmd := &cobra.Command{ Use: "app", - Version: "2.32", + Version: Version, } rootCmd.AddCommand(auditproxy.CmdAuditProxy) diff --git a/test/images/image-util.sh b/test/images/image-util.sh index c89c52e645d..9d2d0e2fbdd 100755 --- a/test/images/image-util.sh +++ b/test/images/image-util.sh @@ -277,7 +277,7 @@ bin() { golang:"${GOLANG_VERSION}" \ /bin/bash -c "\ cd /go/src/k8s.io/kubernetes/test/images/${SRC_DIR} && \ - CGO_ENABLED=0 ${arch_prefix} GOOS=${OS} GOARCH=${ARCH} go build -a -installsuffix cgo --ldflags '-w' -o ${TARGET}/${SRC} ./$(dirname "${SRC}")" + CGO_ENABLED=0 ${arch_prefix} GOOS=${OS} GOARCH=${ARCH} go build -a -installsuffix cgo --ldflags \"-w ${LD_FLAGS}\" -o ${TARGET}/${SRC} ./$(dirname "${SRC}")" done }