Skip to content

Commit

Permalink
Kubetest Version Addition
Browse files Browse the repository at this point in the history
- Adds version flag for kubetest
- Adds kubetest version in metadata.json
- Fixes kubernetes#20886
  • Loading branch information
supriya-premkumar committed Mar 10, 2021
1 parent 0c22aa3 commit e3de79e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions images/kubekins-e2e/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions kubetest/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
15 changes: 10 additions & 5 deletions kubetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e3de79e

Please sign in to comment.