From b4766019c1745adb20e8cab8f2f40ce47d1ffe78 Mon Sep 17 00:00:00 2001 From: Supriya Premkumar Date: Tue, 9 Mar 2021 20:26:05 -0800 Subject: [PATCH] Kubetest Version Addition - Adds version flag for kubetest - Adds kubetest version in metadata.json - Fixes 20886 --- images/kubekins-e2e/cloudbuild.yaml | 1 + kubetest/main.go | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/images/kubekins-e2e/cloudbuild.yaml b/images/kubekins-e2e/cloudbuild.yaml index 3d790818f170..848786743657 100644 --- a/images/kubekins-e2e/cloudbuild.yaml +++ b/images/kubekins-e2e/cloudbuild.yaml @@ -15,6 +15,7 @@ steps: - name: gcr.io/cloud-builders/docker args: - build + - --ldflags="-X=main.gitTag=$_GIT_TAG" - --tag=gcr.io/$PROJECT_ID/kubekins-e2e:$_GIT_TAG-$_CONFIG - --build-arg=BAZEL_VERSION_ARG=$_BAZEL_VERSION - --build-arg=CFSSL_VERSION=$_CFSSL_VERSION diff --git a/kubetest/main.go b/kubetest/main.go index 98d852c608fc..ac48e0e1b1d2 100644 --- a/kubetest/main.go +++ b/kubetest/main.go @@ -48,16 +48,18 @@ const defaultGinkgoParallel = 25 var ( artifacts = filepath.Join(os.Getenv("WORKSPACE"), "_artifacts") + boskos, _ = client.NewClient(os.Getenv("JOB_NAME"), "http://boskos.test-pods.svc.cluster.local.", "", "") + control = process.NewControl(timeout, interrupt, terminate, verbose) + gitTag = "" // initializing default zero value. ldflags will populate this during build time. interrupt = time.NewTimer(time.Duration(0)) // interrupt testing at this time. terminate = time.NewTimer(time.Duration(0)) // terminate testing at this time. - verbose = false timeout = time.Duration(0) - boskos, _ = client.NewClient(os.Getenv("JOB_NAME"), "http://boskos.test-pods.svc.cluster.local.", "", "") - control = process.NewControl(timeout, interrupt, terminate, verbose) + verbose = false ) type options struct { build buildStrategy + boskosWaitDuration time.Duration charts bool checkLeaks bool checkSkew bool @@ -122,12 +124,13 @@ type options struct { testCmdArgs []string up bool upgradeArgs string - boskosWaitDuration time.Duration + version bool } func defineFlags() *options { o := options{} flag.Var(&o.build, "build", "Rebuild k8s binaries, optionally forcing (release|quick|bazel) strategy") + flag.DurationVar(&o.boskosWaitDuration, "boskos-wait-duration", 5*time.Minute, "Defines how long it waits until quit getting Boskos resoure, default 5 minutes") flag.BoolVar(&o.charts, "charts", false, "If true, run charts tests") flag.BoolVar(&o.checkSkew, "check-version-skew", true, "Verify client and server versions match") flag.BoolVar(&o.checkLeaks, "check-leaked-resources", false, "Ensure project ends with the same resources") @@ -188,7 +191,7 @@ func defineFlags() *options { flag.DurationVar(&timeout, "timeout", time.Duration(0), "Terminate testing after the timeout duration (s/m/h)") flag.BoolVar(&o.up, "up", false, "If true, start the e2e cluster. If cluster is already up, recreate it.") flag.StringVar(&o.upgradeArgs, "upgrade_args", "", "If set, run upgrade tests before other tests") - flag.DurationVar(&o.boskosWaitDuration, "boskos-wait-duration", 5*time.Minute, "Defines how long it waits until quit getting Boskos resoure, default 5 minutes") + flag.BoolVar(&o.version, "version", false, "Command to print version") // The "-v" flag was also used by glog, which is used by k8s.io/client-go. Duplicate flags cause panics. // 1. Even if we could convince glog to change, they have too many consumers to ever do so. @@ -274,6 +277,7 @@ func validateFlags(o *options) error { func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) + log.Printf("Running kubetest version: %s\n", gitTag) // Initialize global pseudo random generator. Initializing it to select random AWS Zones. rand.Seed(time.Now().UnixNano()) @@ -289,6 +293,11 @@ func main() { log.Fatalf("Flags validation failed. err: %v", err) } + if o.version { + log.Printf("kubetest version: %s\n", gitTag) + return + } + control = process.NewControl(timeout, interrupt, terminate, verbose) // do things when we know we are running in the kubetest image @@ -513,6 +522,7 @@ func writeMetadata(path, metadataSources string) error { ver := findVersion() m["job-version"] = ver // TODO(krzyzacy): retire m["revision"] = ver + m["kubetest-version"] = gitTag re := regexp.MustCompile(`^BUILD_METADATA_(.+)$`) for _, e := range os.Environ() { p := strings.SplitN(e, "=", 2)