Skip to content
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

Add --local-operator-flags for testing with --up-local #1509

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
25 changes: 15 additions & 10 deletions cmd/operator-sdk/test/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ import (
var deployTestDir = filepath.Join(scaffold.DeployDir, "test")

type testLocalConfig struct {
kubeconfig string
globalManPath string
namespacedManPath string
goTestFlags string
moleculeTestFlags string
namespace string
upLocal bool
noSetup bool
debug bool
image string
kubeconfig string
globalManPath string
namespacedManPath string
goTestFlags string
moleculeTestFlags string
namespace string
upLocal bool
noSetup bool
debug bool
image string
localOperatorFlags string
}

var tlConfig testLocalConfig
Expand All @@ -70,6 +71,7 @@ func newTestLocalCmd() *cobra.Command {
testCmd.Flags().BoolVar(&tlConfig.noSetup, "no-setup", false, "Disable test resource creation")
testCmd.Flags().BoolVar(&tlConfig.debug, "debug", false, "Enable debug-level logging")
testCmd.Flags().StringVar(&tlConfig.image, "image", "", "Use a different operator image from the one specified in the namespaced manifest")
testCmd.Flags().StringVar(&tlConfig.localOperatorFlags, "local-operator-flags", "", "The flags that the operator needs (while using --up-local). Example: \"--flag1 value1 --flag2=value2\"")

return testCmd
}
Expand Down Expand Up @@ -207,6 +209,9 @@ func testLocalGoFunc(cmd *cobra.Command, args []string) error {
}
if tlConfig.upLocal {
testArgs = append(testArgs, "-"+test.LocalOperatorFlag)
if tlConfig.localOperatorFlags != "" {
testArgs = append(testArgs, "-"+test.LocalOperatorArgs, tlConfig.localOperatorFlags)
}
}
opts := projutil.GoTestOptions{
GoCmdOptions: projutil.GoCmdOptions{
Expand Down
1 change: 1 addition & 0 deletions doc/sdk-cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ Runs the tests locally
* `--go-test-flags` string - Additional flags to pass to go test
* `--molecule-test-flags` string - Additional flags to pass to molecule test
* `--up-local` - enable running operator locally with go run instead of as an image in the cluster
* `--local-operator-flags` string - flags that the operator needs, while using --up-local (e.g. \"--flag1 value1 --flag2=value2\")
* `--no-setup` - disable test resource creation
* `--image` string - use a different operator image from the one specified in the namespaced manifest
* `-h, --help` - help for local
Expand Down
9 changes: 8 additions & 1 deletion pkg/test/main_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os/exec"
"os/signal"
"path/filepath"
"strings"
"syscall"
"testing"

Expand All @@ -42,6 +43,7 @@ const (
SingleNamespaceFlag = "singleNamespace"
TestNamespaceEnv = "TEST_NAMESPACE"
LocalOperatorFlag = "localOperator"
LocalOperatorArgs = "localOperatorArgs"
)

func MainEntry(m *testing.M) {
Expand All @@ -51,6 +53,7 @@ func MainEntry(m *testing.M) {
namespacedManPath := flag.String(NamespacedManPathFlag, "", "path to rbac manifest")
singleNamespace = flag.Bool(SingleNamespaceFlag, false, "enable single namespace mode")
localOperator := flag.Bool(LocalOperatorFlag, false, "enable if operator is running locally (not in cluster)")
localOperatorArgs := flag.String(LocalOperatorArgs, "", "flags that the operator needs (while using --up-local). example: \"--flag1 value1 --flag2=value2\"")
flag.Parse()
// go test always runs from the test directory; change to project root
err := os.Chdir(*projRoot)
Expand All @@ -74,7 +77,11 @@ func MainEntry(m *testing.M) {
if err := projutil.GoBuild(opts); err != nil {
log.Fatalf("Failed to build local operator binary: %s", err)
}
localCmd = exec.Command(outputBinName)
args := []string{}
if *localOperatorArgs != "" {
args = append(args, strings.Split(*localOperatorArgs, " ")...)
}
localCmd = exec.Command(outputBinName, args...)
localCmd.Stdout = &localCmdOutBuf
localCmd.Stderr = &localCmdErrBuf
c := make(chan os.Signal)
Expand Down