Skip to content

Commit 58995cd

Browse files
committed
connectivity: allow to restrict connectivity test pods using nodeSelector
The connectivity test pods will be restricted to nodes matching labels given in the --node-selector flag. Usage: $ kubectl get nodes NAME STATUS ROLES AGE VERSION kind-control-plane Ready control-plane 15m v1.25.3 kind-worker Ready <none> 15m v1.25.3 kind-worker2 Ready <none> 15m v1.25.3 kind-worker3 Ready <none> 15m v1.25.3 kind-worker4 Ready <none> 15m v1.25.3 $ kubectl label nodes kind-worker{2,3} connectivity.cilium.io/test=true $ cilium connectivity test --node-selector connectivity.cilium.io/test=true [...] ✅ All 32 tests (261 actions) successful, 2 tests skipped, 1 scenarios skipped. $ kubectl get pods -n cilium-test -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES client-7858556799-xd52x 1/1 Running 0 5m56s 10.244.2.120 kind-worker3 <none> <none> client2-646989676f-zgxxl 1/1 Running 0 5m56s 10.244.2.55 kind-worker3 <none> <none> echo-other-node-79659b5c6-8dzfw 2/2 Running 0 5m55s 10.244.3.148 kind-worker2 <none> <none> echo-same-node-69f7699d84-5bvxj 2/2 Running 0 5m56s 10.244.2.168 kind-worker3 <none> <none> Fixes #1269 Signed-off-by: Tobias Klauser <tobias@cilium.io>
1 parent fe38969 commit 58995cd

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

connectivity/check/check.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Parameters struct {
5050
DNSTestServerImage string
5151
Datapath bool
5252
AgentPodSelector string
53+
NodeSelector map[string]string
5354
ExternalTarget string
5455
ExternalCIDR string
5556
ExternalIP string

connectivity/check/deployment.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type deploymentParameters struct {
9393
HostPort int
9494
Command []string
9595
Affinity *corev1.Affinity
96+
NodeSelector map[string]string
9697
ReadinessProbe *corev1.Probe
9798
Labels map[string]string
9899
HostNetwork bool
@@ -146,6 +147,7 @@ func newDeployment(p deploymentParameters) *appsv1.Deployment {
146147
},
147148
},
148149
Affinity: p.Affinity,
150+
NodeSelector: p.NodeSelector,
149151
HostNetwork: p.HostNetwork,
150152
ServiceAccountName: p.Name,
151153
},
@@ -396,7 +398,8 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
396398
},
397399
},
398400
},
399-
HostNetwork: ct.params.PerfHostNet,
401+
NodeSelector: ct.params.NodeSelector,
402+
HostNetwork: ct.params.PerfHostNet,
400403
})
401404
_, err = ct.clients.src.CreateServiceAccount(ctx, ct.params.TestNamespace, k8s.NewServiceAccount(nm.ClientName()), metav1.CreateOptions{})
402405
if err != nil {
@@ -446,7 +449,8 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
446449
},
447450
},
448451
},
449-
HostNetwork: ct.params.PerfHostNet,
452+
NodeSelector: ct.params.NodeSelector,
453+
HostNetwork: ct.params.PerfHostNet,
450454
})
451455
_, err = ct.clients.src.CreateServiceAccount(ctx, ct.params.TestNamespace, k8s.NewServiceAccount(nm.ServerName()), metav1.CreateOptions{})
452456
if err != nil {
@@ -493,7 +497,8 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
493497
{Key: "name", Operator: metav1.LabelSelectorOpIn, Values: []string{nm.ClientName()}}}},
494498
TopologyKey: "kubernetes.io/hostname"}}}},
495499
},
496-
HostNetwork: ct.params.PerfHostNet,
500+
NodeSelector: ct.params.NodeSelector,
501+
HostNetwork: ct.params.PerfHostNet,
497502
})
498503
_, err = ct.clients.src.CreateServiceAccount(ctx, ct.params.TestNamespace, k8s.NewServiceAccount(nm.ClientAcrossName()), metav1.CreateOptions{})
499504
if err != nil {
@@ -629,12 +634,13 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
629634
if err != nil {
630635
ct.Logf("✨ [%s] Deploying %s deployment...", ct.clients.src.ClusterName(), clientDeploymentName)
631636
clientDeployment := newDeployment(deploymentParameters{
632-
Name: clientDeploymentName,
633-
Kind: kindClientName,
634-
NamedPort: "http-8080",
635-
Port: 8080,
636-
Image: ct.params.CurlImage,
637-
Command: []string{"/bin/ash", "-c", "sleep 10000000"},
637+
Name: clientDeploymentName,
638+
Kind: kindClientName,
639+
NamedPort: "http-8080",
640+
Port: 8080,
641+
Image: ct.params.CurlImage,
642+
Command: []string{"/bin/ash", "-c", "sleep 10000000"},
643+
NodeSelector: ct.params.NodeSelector,
638644
})
639645
_, err = ct.clients.src.CreateServiceAccount(ctx, ct.params.TestNamespace, k8s.NewServiceAccount(clientDeploymentName), metav1.CreateOptions{})
640646
if err != nil {
@@ -672,6 +678,7 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
672678
},
673679
},
674680
},
681+
NodeSelector: ct.params.NodeSelector,
675682
})
676683
_, err = ct.clients.src.CreateServiceAccount(ctx, ct.params.TestNamespace, k8s.NewServiceAccount(client2DeploymentName), metav1.CreateOptions{})
677684
if err != nil {
@@ -727,6 +734,7 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
727734
},
728735
},
729736
},
737+
NodeSelector: ct.params.NodeSelector,
730738
ReadinessProbe: newLocalReadinessProbe(containerPort, "/"),
731739
}, ct.params.DNSTestServerImage)
732740
_, err = ct.clients.dst.CreateServiceAccount(ctx, ct.params.TestNamespace, k8s.NewServiceAccount(echoOtherNodeDeploymentName), metav1.CreateOptions{})

internal/cli/cmd/connectivity.go

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func newCmdConnectivityTest() *cobra.Command {
119119
cmd.Flags().StringVar(&params.TestNamespace, "test-namespace", defaults.ConnectivityCheckNamespace, "Namespace to perform the connectivity test in")
120120
cmd.Flags().StringVar(&params.AgentDaemonSetName, "agent-daemonset-name", defaults.AgentDaemonSetName, "Name of cilium agent daemonset")
121121
cmd.Flags().StringVar(&params.AgentPodSelector, "agent-pod-selector", defaults.AgentPodSelector, "Label on cilium-agent pods to select with")
122+
cmd.Flags().StringToStringVar(&params.NodeSelector, "node-selector", map[string]string{}, "Restrict connectivity test pods to nodes matching this label")
122123
cmd.Flags().StringVar(&params.MultiCluster, "multi-cluster", "", "Test across clusters to given context")
123124
cmd.Flags().StringSliceVar(&tests, "test", []string{}, "Run tests that match one of the given regular expressions, skip tests by starting the expression with '!', target Scenarios with e.g. '/pod-to-cidr'")
124125
cmd.Flags().StringVar(&params.FlowValidation, "flow-validation", check.FlowValidationModeWarning, "Enable Hubble flow validation { disabled | warning | strict }")

0 commit comments

Comments
 (0)