Skip to content

Commit

Permalink
fix: ExternalTargetCANamespace name
Browse files Browse the repository at this point in the history
The fix for connectivity tests ExternalTargetCANamespace name.
The name must be namespace specific in case of tests
concurrent run for proper CiliumNetworkPolicy provisioning.

Signed-off-by: viktor-kurchenko <[email protected]>
  • Loading branch information
viktor-kurchenko authored and michi-covalent committed Jun 26, 2024
1 parent 5146f46 commit a2cb73e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 18 deletions.
8 changes: 7 additions & 1 deletion cli/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func newCmdConnectivityTest(hooks api.Hooks) *cobra.Command {
cmd.Flags().BoolVarP(&params.Timestamp, "timestamp", "t", false, "Show timestamp in messages")
cmd.Flags().BoolVarP(&params.PauseOnFail, "pause-on-fail", "p", false, "Pause execution on test failure")
cmd.Flags().StringVar(&params.ExternalTarget, "external-target", "one.one.one.one.", "Domain name to use as external target in connectivity tests")
cmd.Flags().StringVar(&params.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(&params.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(&params.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(&params.ExternalCIDR, "external-cidr", "1.0.0.0/8", "CIDR to use as external target in connectivity tests")
cmd.Flags().StringVar(&params.ExternalIP, "external-ip", "1.1.1.1", "IP to use as external target in connectivity tests")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
65 changes: 48 additions & 17 deletions cli/connectivity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}

0 comments on commit a2cb73e

Please sign in to comment.