From 4259c9967bc604488f2751375073a0926f1c27b2 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 Issue-20886 --- images/kubekins-e2e/cloudbuild.yaml | 1 + kubetest/e2e.go | 3 +++ kubetest/main.go | 15 ++++++++++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/images/kubekins-e2e/cloudbuild.yaml b/images/kubekins-e2e/cloudbuild.yaml index 3d790818f1701..4bd0c6369a90b 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/e2e.go b/kubetest/e2e.go index c0b8616ed1a67..8fc6bc87a6dac 100644 --- a/kubetest/e2e.go +++ b/kubetest/e2e.go @@ -55,6 +55,9 @@ func run(deploy deployer, o options) error { if cmd == nil { cmd = exec.Command("./cluster/kubectl.sh") } + if o.version { + log.Printf("kubetest version: %s", gitTag) + } if o.checkSkew { cmd.Args = append(cmd.Args, "--match-server-version") } diff --git a/kubetest/main.go b/kubetest/main.go index 98d852c608fc1..ba3ba518f3f2b 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", gitTag) // Initialize global pseudo random generator. Initializing it to select random AWS Zones. rand.Seed(time.Now().UnixNano()) @@ -513,6 +517,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)