diff --git a/cli/connectivity.go b/cli/connectivity.go index 4743d9faed..44c9dc0e2f 100644 --- a/cli/connectivity.go +++ b/cli/connectivity.go @@ -13,6 +13,7 @@ import ( "syscall" "time" + "github.com/cilium/cilium/pkg/option" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -40,6 +41,8 @@ func newCmdConnectivity(hooks api.Hooks) *cobra.Command { var params = check.Parameters{ ExternalDeploymentPort: 8080, EchoServerHostPort: 4000, + JunitProperties: make(map[string]string), + NodeSelector: make(map[string]string), Writer: os.Stdout, SysdumpOptions: sysdump.Options{ LargeSysdumpAbortTimeout: sysdump.DefaultLargeSysdumpAbortTimeout, @@ -132,7 +135,7 @@ func newCmdConnectivityTest(hooks api.Hooks) *cobra.Command { cmd.Flags().StringVar(¶ms.ExternalOtherIP, "external-other-ip", "1.0.0.1", "Other IP to use as external target in connectivity tests") cmd.Flags().StringSliceVar(¶ms.NodeCIDRs, "node-cidr", nil, "one or more CIDRs that cover all nodes in the cluster") cmd.Flags().StringVar(¶ms.JunitFile, "junit-file", "", "Generate junit report and write to file") - cmd.Flags().StringToStringVar(¶ms.JunitProperties, "junit-property", map[string]string{}, "Add key=value properties to the generated junit file") + cmd.Flags().Var(option.NewNamedMapOptions("junit-property", ¶ms.JunitProperties, nil), "junit-property", "Add key=value properties to the generated junit file") cmd.Flags().BoolVar(¶ms.SkipIPCacheCheck, "skip-ip-cache-check", true, "Skip IPCache check") cmd.Flags().MarkHidden("skip-ip-cache-check") cmd.Flags().BoolVar(¶ms.IncludeUnsafeTests, "include-unsafe-tests", false, "Include tests which can modify cluster nodes state") @@ -218,7 +221,7 @@ func newCmdConnectivityPerf(hooks api.Hooks) *cobra.Command { func registerCommonFlags(flags *pflag.FlagSet) { flags.BoolVarP(¶ms.Debug, "debug", "d", false, "Show debug messages") - flags.StringToStringVar(¶ms.NodeSelector, "node-selector", map[string]string{}, "Restrict connectivity pods to nodes matching this label") + flags.Var(option.NewNamedMapOptions("node-selector", ¶ms.NodeSelector, nil), "node-selector", "Restrict connectivity pods to nodes matching this label") flags.StringVar(¶ms.TestNamespace, "test-namespace", defaults.ConnectivityCheckNamespace, "Namespace to perform the connectivity in") flags.Var(¶ms.DeploymentAnnotations, "deployment-pod-annotations", "Add annotations to the connectivity pods, e.g. '{\"client\":{\"foo\":\"bar\"}}'") } diff --git a/cli/connectivity_test.go b/cli/connectivity_test.go index 2788abbe7c..8dee42894b 100644 --- a/cli/connectivity_test.go +++ b/cli/connectivity_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/cilium/cilium-cli/api" "github.com/cilium/cilium-cli/connectivity/check" ) @@ -87,3 +88,19 @@ func TestNewConnectivityTests(t *testing.T) { } } } + +func TestConnectivityTestFlags(t *testing.T) { + ct := newCmdConnectivityTest(&api.NopHooks{}) + require.Empty(t, params.JunitProperties) + ct.Flags().Set("junit-property", "a=b") + require.NoError(t, ct.Flags().Set("junit-property", "a=b")) + require.Equal(t, map[string]string{"a": "b"}, params.JunitProperties) + require.NoError(t, ct.Flags().Set("junit-property", "c=d")) + require.Equal(t, map[string]string{"a": "b", "c": "d"}, params.JunitProperties) + + require.Empty(t, params.NodeSelector) + require.NoError(t, ct.Flags().Set("node-selector", "a=b")) + require.Equal(t, map[string]string{"a": "b"}, params.NodeSelector) + require.NoError(t, ct.Flags().Set("node-selector", "c=d")) + require.Equal(t, map[string]string{"a": "b", "c": "d"}, params.NodeSelector) +}