From be73f76153bb4fbe679bd857a50e35c3321501dc Mon Sep 17 00:00:00 2001 From: Alexander Pavel Date: Tue, 25 Sep 2018 12:09:12 -0700 Subject: [PATCH 1/2] commands/.../cmd: make command flags more consistent --- commands/operator-sdk/cmd/build.go | 6 +++--- commands/operator-sdk/cmd/test/cluster.go | 10 +++++----- commands/operator-sdk/cmd/test/local.go | 8 ++++---- test/e2e/memcached_test.go | 14 ++++++++------ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/commands/operator-sdk/cmd/build.go b/commands/operator-sdk/cmd/build.go index 1110106ff2..b12c1446a5 100644 --- a/commands/operator-sdk/cmd/build.go +++ b/commands/operator-sdk/cmd/build.go @@ -55,9 +55,9 @@ For example: `, Run: buildFunc, } - buildCmd.Flags().BoolVarP(&enableTests, "enable-tests", "e", false, "Enable in-cluster testing by adding test binary to the image") - buildCmd.Flags().StringVarP(&testLocationBuild, "test-location", "t", "./test/e2e", "Location of tests") - buildCmd.Flags().StringVarP(&namespacedManBuild, "namespaced", "n", "deploy/operator.yaml", "Path of namespaced resources for tests") + buildCmd.Flags().BoolVar(&enableTests, "enable-tests", false, "Enable in-cluster testing by adding test binary to the image") + buildCmd.Flags().StringVar(&testLocationBuild, "test-location", "./test/e2e", "Location of tests") + buildCmd.Flags().StringVar(&namespacedManBuild, "namespaced-manifest", "deploy/operator.yaml", "Path of namespaced resources manifest for tests") return buildCmd } diff --git a/commands/operator-sdk/cmd/test/cluster.go b/commands/operator-sdk/cmd/test/cluster.go index 7064bbc5c9..cdd5cfd050 100644 --- a/commands/operator-sdk/cmd/test/cluster.go +++ b/commands/operator-sdk/cmd/test/cluster.go @@ -52,11 +52,11 @@ func NewTestClusterCmd() *cobra.Command { if ok { defaultKubeConfig = homedir + "/.kube/config" } - testCmd.Flags().StringVarP(&tcConfig.namespace, "namespace", "n", "default", "Namespace to run tests in") - testCmd.Flags().StringVarP(&tcConfig.kubeconfig, "kubeconfig", "k", defaultKubeConfig, "Kubeconfig path") - testCmd.Flags().StringVarP(&tcConfig.imagePullPolicy, "imagePullPolicy", "i", "Always", "Set test pod image pull policy. Allowed values: Always, Never") - testCmd.Flags().StringVarP(&tcConfig.serviceAccount, "serviceAccount", "s", "default", "Service account to run tests on") - testCmd.Flags().IntVarP(&tcConfig.pendingTimeout, "pendingTimeout", "p", 60, "Timeout for testing pod in pending state") + testCmd.Flags().StringVar(&tcConfig.namespace, "namespace", "default", "Namespace to run tests in") + testCmd.Flags().StringVar(&tcConfig.kubeconfig, "kubeconfig", defaultKubeConfig, "Kubeconfig path") + testCmd.Flags().StringVar(&tcConfig.imagePullPolicy, "image-pull-policy", "Always", "Set test pod image pull policy. Allowed values: Always, Never") + testCmd.Flags().StringVar(&tcConfig.serviceAccount, "service-account", "default", "Service account to run tests on") + testCmd.Flags().IntVar(&tcConfig.pendingTimeout, "pending-timeout", 60, "Timeout for testing pod in pending state") return testCmd } diff --git a/commands/operator-sdk/cmd/test/local.go b/commands/operator-sdk/cmd/test/local.go index 0e203487d8..14191ba2f4 100644 --- a/commands/operator-sdk/cmd/test/local.go +++ b/commands/operator-sdk/cmd/test/local.go @@ -48,10 +48,10 @@ func NewTestLocalCmd() *cobra.Command { if ok { defaultKubeConfig = homedir + "/.kube/config" } - testCmd.Flags().StringVarP(&tlConfig.kubeconfig, "kubeconfig", "k", defaultKubeConfig, "Kubeconfig path") - testCmd.Flags().StringVarP(&tlConfig.globalManPath, "global-init", "g", "deploy/crd.yaml", "Path to manifest for Global resources (e.g. CRD manifest)") - testCmd.Flags().StringVarP(&tlConfig.namespacedManPath, "namespaced-init", "n", "", "Path to manifest for per-test, namespaced resources (e.g. RBAC and Operator manifest)") - testCmd.Flags().StringVarP(&tlConfig.goTestFlags, "go-test-flags", "f", "", "Additional flags to pass to go test") + testCmd.Flags().StringVar(&tlConfig.kubeconfig, "kubeconfig", defaultKubeConfig, "Kubeconfig path") + testCmd.Flags().StringVar(&tlConfig.globalManPath, "global-manifest", "deploy/crd.yaml", "Path to manifest for Global resources (e.g. CRD manifest)") + testCmd.Flags().StringVar(&tlConfig.namespacedManPath, "namespaced-manifest", "", "Path to manifest for per-test, namespaced resources (e.g. RBAC and Operator manifest)") + testCmd.Flags().StringVar(&tlConfig.goTestFlags, "go-test-flags", "", "Additional flags to pass to go test") return testCmd } diff --git a/test/e2e/memcached_test.go b/test/e2e/memcached_test.go index beaa95db3d..2503deb1db 100644 --- a/test/e2e/memcached_test.go +++ b/test/e2e/memcached_test.go @@ -149,10 +149,6 @@ func TestMemcached(t *testing.T) { if err != nil { t.Fatalf("dep ensure failed: %v\nCommand Output:\n%v", err, string(cmdOut)) } - // use current operator-sdk code - os.RemoveAll("vendor/github.com/operator-framework/operator-sdk/pkg") - os.Symlink(path.Join(gopath, "/src/github.com/operator-framework/operator-sdk/pkg"), - "vendor/github.com/operator-framework/operator-sdk/pkg") // create crd crdYAML, err := ioutil.ReadFile("deploy/crd.yaml") @@ -288,7 +284,10 @@ func MemcachedCluster(t *testing.T) { t.Fatalf("failed to write deploy/operator.yaml: %v", err) } t.Log("Building operator docker image") - cmdOut, err := exec.Command("operator-sdk", "build", *f.ImageName, "-e", "-t", "./test/e2e", "-n", "deploy/operator.yaml").CombinedOutput() + cmdOut, err := exec.Command("operator-sdk", "build", *f.ImageName, + "--enable-tests", + "--test-location", "./test/e2e", + "--namespaced-manifest", "deploy/operator.yaml").CombinedOutput() if err != nil { t.Fatalf("error: %v\nCommand Output: %s\n", err, string(cmdOut)) } @@ -378,7 +377,10 @@ func MemcachedClusterTest(t *testing.T) { if err != nil { t.Fatalf("could not get namespace: %v", err) } - cmdOut, err := exec.Command("operator-sdk", "test", "cluster", *f.ImageName, "-n", namespace, "-i", "Never", "-s", "memcached-operator").CombinedOutput() + cmdOut, err := exec.Command("operator-sdk", "test", "cluster", *f.ImageName, + "--namespace", namespace, + "--image-pull-policy", "Never", + "--service-account", "memcached-operator").CombinedOutput() if err != nil { t.Fatalf("in-cluster test failed: %v\nCommand Output:\n%s", err, string(cmdOut)) } From f7b3550273de820116dd3eb94a73aed003092a9f Mon Sep 17 00:00:00 2001 From: Alexander Pavel Date: Tue, 25 Sep 2018 12:23:05 -0700 Subject: [PATCH 2/2] .travis.yml: update travis script --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 029eac1c0a..dcf6ba8e4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,7 +32,7 @@ script: # test framework with defaults - operator-sdk test local . # test operator-sdk test flags -- operator-sdk test local . -g deploy/crd.yaml -n deploy/namespace-init.yaml -f "-parallel 1" -k $HOME/.kube/config +- operator-sdk test local . --global-manifest deploy/crd.yaml --namespaced-manifest deploy/namespace-init.yaml --go-test-flags "-parallel 1" --kubeconfig $HOME/.kube/config # go back to project root - cd ../.. - go vet ./...