diff --git a/cli/connectivity.go b/cli/connectivity.go index ebff7abd7f..808f2791f4 100644 --- a/cli/connectivity.go +++ b/cli/connectivity.go @@ -125,7 +125,7 @@ func newCmdConnectivityTest(hooks api.Hooks) *cobra.Command { cmd.Flags().BoolVarP(¶ms.Timestamp, "timestamp", "t", false, "Show timestamp in messages") cmd.Flags().BoolVarP(¶ms.PauseOnFail, "pause-on-fail", "p", false, "Pause execution on test failure") cmd.Flags().StringVar(¶ms.ExternalTarget, "external-target", "one.one.one.one.", "Domain name to use as external target in connectivity tests") - cmd.Flags().StringVar(¶ms.ExternalTargetCANamespace, "external-target-ca-namespace", defaults.ConnectivityCheckNamespace, "Namespace of the CA secret for the external target. Used by client-egress-l7-tls test cases.") + cmd.Flags().StringVar(¶ms.ExternalTargetCANamespace, "external-target-ca-namespace", "", "Namespace of the CA secret for the external target. Used by client-egress-l7-tls test cases.") cmd.Flags().StringVar(¶ms.ExternalTargetCAName, "external-target-ca-name", "cabundle", "Name of the CA secret for the external target. Used by client-egress-l7-tls test cases.") cmd.Flags().StringVar(¶ms.ExternalCIDR, "external-cidr", "1.0.0.0/8", "CIDR to use as external target in connectivity tests") cmd.Flags().StringVar(¶ms.ExternalIP, "external-ip", "1.1.1.1", "IP to use as external target in connectivity tests") @@ -228,6 +228,9 @@ func newConnectivityTests(params check.Parameters, logger *check.ConcurrentLogge params.TestConcurrency = 1 } if params.TestConcurrency < 2 { + if params.ExternalTargetCANamespace == "" { + params.ExternalTargetCANamespace = defaults.ConnectivityCheckNamespace + } cc, err := check.NewConnectivityTest(k8sClient, params, defaults.CLIVersion, logger) if err != nil { return nil, err @@ -239,6 +242,9 @@ func newConnectivityTests(params check.Parameters, logger *check.ConcurrentLogge for i := 0; i < params.TestConcurrency; i++ { params := params params.TestNamespace = fmt.Sprintf("%s-%d", params.TestNamespace, i+1) + if params.ExternalTargetCANamespace == "" { + params.ExternalTargetCANamespace = params.TestNamespace + } params.ExternalDeploymentPort += i params.EchoServerHostPort += i params.JunitFile = junit.NamespacedFileName(params.TestNamespace, params.JunitFile) diff --git a/cli/connectivity_test.go b/cli/connectivity_test.go index 5a846270bd..2788abbe7c 100644 --- a/cli/connectivity_test.go +++ b/cli/connectivity_test.go @@ -14,35 +14,63 @@ import ( func TestNewConnectivityTests(t *testing.T) { testCases := []struct { - params check.Parameters - expectedCount int - expectedTestNamespaces []string + params check.Parameters + expectedCount int + expectedTestNamespaces []string + expectedExternalTargetCANamespace []string }{ { params: check.Parameters{ - FlowValidation: check.FlowValidationModeDisabled, - TestNamespace: "cilium-test", + FlowValidation: check.FlowValidationModeDisabled, + TestNamespace: "cilium-test", + ExternalTargetCANamespace: "", }, - expectedCount: 1, - expectedTestNamespaces: []string{"cilium-test"}, + expectedCount: 1, + expectedTestNamespaces: []string{"cilium-test"}, + expectedExternalTargetCANamespace: []string{"cilium-test"}, }, { params: check.Parameters{ - FlowValidation: check.FlowValidationModeDisabled, - TestNamespace: "cilium-test", - TestConcurrency: -1, + FlowValidation: check.FlowValidationModeDisabled, + TestNamespace: "cilium-test", + ExternalTargetCANamespace: "cilium-test", }, - expectedCount: 1, - expectedTestNamespaces: []string{"cilium-test"}, + expectedCount: 1, + expectedTestNamespaces: []string{"cilium-test"}, + expectedExternalTargetCANamespace: []string{"cilium-test"}, }, { params: check.Parameters{ - FlowValidation: check.FlowValidationModeDisabled, - TestNamespace: "cilium-test", - TestConcurrency: 3, + FlowValidation: check.FlowValidationModeDisabled, + TestNamespace: "cilium-test", + ExternalTargetCANamespace: "cilium-test", + TestConcurrency: -1, }, - expectedCount: 3, - expectedTestNamespaces: []string{"cilium-test-1", "cilium-test-2", "cilium-test-3"}, + expectedCount: 1, + expectedTestNamespaces: []string{"cilium-test"}, + expectedExternalTargetCANamespace: []string{"cilium-test"}, + }, + { + params: check.Parameters{ + FlowValidation: check.FlowValidationModeDisabled, + TestNamespace: "cilium-test", + ExternalTargetCANamespace: "", + TestConcurrency: 3, + }, + expectedCount: 3, + expectedTestNamespaces: []string{"cilium-test-1", "cilium-test-2", "cilium-test-3"}, + expectedExternalTargetCANamespace: []string{"cilium-test-1", "cilium-test-2", "cilium-test-3"}, + }, + { + params: check.Parameters{ + FlowValidation: check.FlowValidationModeDisabled, + TestNamespace: "cilium-test", + ExternalTargetCANamespace: "cilium-test", + TestConcurrency: 3, + }, + expectedCount: 3, + expectedTestNamespaces: []string{"cilium-test-1", "cilium-test-2", "cilium-test-3"}, + expectedExternalTargetCANamespace: []string{"cilium-test"}, }, } for _, tt := range testCases { @@ -54,5 +82,8 @@ func TestNewConnectivityTests(t *testing.T) { for i, n := range tt.expectedTestNamespaces { require.Equal(t, n, actual[i].Params().TestNamespace) } + for i, n := range tt.expectedExternalTargetCANamespace { + require.Equal(t, n, actual[i].Params().ExternalTargetCANamespace) + } } }