Skip to content

commands/.../cmd: make command flags more consistent #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
6 changes: 3 additions & 3 deletions commands/operator-sdk/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 5 additions & 5 deletions commands/operator-sdk/cmd/test/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions commands/operator-sdk/cmd/test/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
14 changes: 8 additions & 6 deletions test/e2e/memcached_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down