Skip to content

Commit 02c057f

Browse files
authored
commands/.../cmd: make command flags more consistent (#528)
* commands/.../cmd: make command flags more consistent
1 parent fe6d2a3 commit 02c057f

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ script:
3232
# test framework with defaults
3333
- operator-sdk test local .
3434
# test operator-sdk test flags
35-
- operator-sdk test local . -g deploy/crd.yaml -n deploy/namespace-init.yaml -f "-parallel 1" -k $HOME/.kube/config
35+
- operator-sdk test local . --global-manifest deploy/crd.yaml --namespaced-manifest deploy/namespace-init.yaml --go-test-flags "-parallel 1" --kubeconfig $HOME/.kube/config
3636
# go back to project root
3737
- cd ../..
3838
- go vet ./...

commands/operator-sdk/cmd/build.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ For example:
5555
`,
5656
Run: buildFunc,
5757
}
58-
buildCmd.Flags().BoolVarP(&enableTests, "enable-tests", "e", false, "Enable in-cluster testing by adding test binary to the image")
59-
buildCmd.Flags().StringVarP(&testLocationBuild, "test-location", "t", "./test/e2e", "Location of tests")
60-
buildCmd.Flags().StringVarP(&namespacedManBuild, "namespaced", "n", "deploy/operator.yaml", "Path of namespaced resources for tests")
58+
buildCmd.Flags().BoolVar(&enableTests, "enable-tests", false, "Enable in-cluster testing by adding test binary to the image")
59+
buildCmd.Flags().StringVar(&testLocationBuild, "test-location", "./test/e2e", "Location of tests")
60+
buildCmd.Flags().StringVar(&namespacedManBuild, "namespaced-manifest", "deploy/operator.yaml", "Path of namespaced resources manifest for tests")
6161
return buildCmd
6262
}
6363

commands/operator-sdk/cmd/test/cluster.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ func NewTestClusterCmd() *cobra.Command {
5252
if ok {
5353
defaultKubeConfig = homedir + "/.kube/config"
5454
}
55-
testCmd.Flags().StringVarP(&tcConfig.namespace, "namespace", "n", "default", "Namespace to run tests in")
56-
testCmd.Flags().StringVarP(&tcConfig.kubeconfig, "kubeconfig", "k", defaultKubeConfig, "Kubeconfig path")
57-
testCmd.Flags().StringVarP(&tcConfig.imagePullPolicy, "imagePullPolicy", "i", "Always", "Set test pod image pull policy. Allowed values: Always, Never")
58-
testCmd.Flags().StringVarP(&tcConfig.serviceAccount, "serviceAccount", "s", "default", "Service account to run tests on")
59-
testCmd.Flags().IntVarP(&tcConfig.pendingTimeout, "pendingTimeout", "p", 60, "Timeout for testing pod in pending state")
55+
testCmd.Flags().StringVar(&tcConfig.namespace, "namespace", "default", "Namespace to run tests in")
56+
testCmd.Flags().StringVar(&tcConfig.kubeconfig, "kubeconfig", defaultKubeConfig, "Kubeconfig path")
57+
testCmd.Flags().StringVar(&tcConfig.imagePullPolicy, "image-pull-policy", "Always", "Set test pod image pull policy. Allowed values: Always, Never")
58+
testCmd.Flags().StringVar(&tcConfig.serviceAccount, "service-account", "default", "Service account to run tests on")
59+
testCmd.Flags().IntVar(&tcConfig.pendingTimeout, "pending-timeout", 60, "Timeout for testing pod in pending state")
6060

6161
return testCmd
6262
}

commands/operator-sdk/cmd/test/local.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ func NewTestLocalCmd() *cobra.Command {
4848
if ok {
4949
defaultKubeConfig = homedir + "/.kube/config"
5050
}
51-
testCmd.Flags().StringVarP(&tlConfig.kubeconfig, "kubeconfig", "k", defaultKubeConfig, "Kubeconfig path")
52-
testCmd.Flags().StringVarP(&tlConfig.globalManPath, "global-init", "g", "deploy/crd.yaml", "Path to manifest for Global resources (e.g. CRD manifest)")
53-
testCmd.Flags().StringVarP(&tlConfig.namespacedManPath, "namespaced-init", "n", "", "Path to manifest for per-test, namespaced resources (e.g. RBAC and Operator manifest)")
54-
testCmd.Flags().StringVarP(&tlConfig.goTestFlags, "go-test-flags", "f", "", "Additional flags to pass to go test")
51+
testCmd.Flags().StringVar(&tlConfig.kubeconfig, "kubeconfig", defaultKubeConfig, "Kubeconfig path")
52+
testCmd.Flags().StringVar(&tlConfig.globalManPath, "global-manifest", "deploy/crd.yaml", "Path to manifest for Global resources (e.g. CRD manifest)")
53+
testCmd.Flags().StringVar(&tlConfig.namespacedManPath, "namespaced-manifest", "", "Path to manifest for per-test, namespaced resources (e.g. RBAC and Operator manifest)")
54+
testCmd.Flags().StringVar(&tlConfig.goTestFlags, "go-test-flags", "", "Additional flags to pass to go test")
5555

5656
return testCmd
5757
}

test/e2e/memcached_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ func TestMemcached(t *testing.T) {
149149
if err != nil {
150150
t.Fatalf("dep ensure failed: %v\nCommand Output:\n%v", err, string(cmdOut))
151151
}
152-
// use current operator-sdk code
153-
os.RemoveAll("vendor/github.com/operator-framework/operator-sdk/pkg")
154-
os.Symlink(path.Join(gopath, "/src/github.com/operator-framework/operator-sdk/pkg"),
155-
"vendor/github.com/operator-framework/operator-sdk/pkg")
156152

157153
// create crd
158154
crdYAML, err := ioutil.ReadFile("deploy/crd.yaml")
@@ -288,7 +284,10 @@ func MemcachedCluster(t *testing.T) {
288284
t.Fatalf("failed to write deploy/operator.yaml: %v", err)
289285
}
290286
t.Log("Building operator docker image")
291-
cmdOut, err := exec.Command("operator-sdk", "build", *f.ImageName, "-e", "-t", "./test/e2e", "-n", "deploy/operator.yaml").CombinedOutput()
287+
cmdOut, err := exec.Command("operator-sdk", "build", *f.ImageName,
288+
"--enable-tests",
289+
"--test-location", "./test/e2e",
290+
"--namespaced-manifest", "deploy/operator.yaml").CombinedOutput()
292291
if err != nil {
293292
t.Fatalf("error: %v\nCommand Output: %s\n", err, string(cmdOut))
294293
}
@@ -378,7 +377,10 @@ func MemcachedClusterTest(t *testing.T) {
378377
if err != nil {
379378
t.Fatalf("could not get namespace: %v", err)
380379
}
381-
cmdOut, err := exec.Command("operator-sdk", "test", "cluster", *f.ImageName, "-n", namespace, "-i", "Never", "-s", "memcached-operator").CombinedOutput()
380+
cmdOut, err := exec.Command("operator-sdk", "test", "cluster", *f.ImageName,
381+
"--namespace", namespace,
382+
"--image-pull-policy", "Never",
383+
"--service-account", "memcached-operator").CombinedOutput()
382384
if err != nil {
383385
t.Fatalf("in-cluster test failed: %v\nCommand Output:\n%s", err, string(cmdOut))
384386
}

0 commit comments

Comments
 (0)