From a19602388329c07dad3f0bea3017cbc7656de21c Mon Sep 17 00:00:00 2001 From: darox Date: Wed, 11 Oct 2023 17:11:17 +0200 Subject: [PATCH] Add node addr type to pod to host test This commit changes the output format of the `pod-to-host` test cases. From: ``` Action [allow-all-except-world/pod-to-host/ping-ipv4-1 ``` to: ``` Action [allow-all-except-world/pod-to-host/ping-ipv4-internal-ip ``` by utilizing the `field Type v1.NodeAddressType` With this change, a user can immediately see if the ping to the ExternalIP or InternalIP of the node is failing. Without the need to run `kubectl get po -o wide` separately. Signed-off-by: darox --- connectivity/tests/host.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/connectivity/tests/host.go b/connectivity/tests/host.go index f243313894..7d17efdd41 100644 --- a/connectivity/tests/host.go +++ b/connectivity/tests/host.go @@ -9,6 +9,7 @@ import ( "github.com/cilium/cilium-cli/connectivity/check" "github.com/cilium/cilium-cli/utils/features" + corev1 "k8s.io/api/core/v1" ) // PodToHost sends an ICMP ping from all client Pods to all nodes @@ -28,7 +29,7 @@ func (s *podToHost) Run(ctx context.Context, t *check.Test) { ct := t.Context() // Construct a unique list of all nodes in the cluster running workloads. - var i int + var addrType string for _, pod := range ct.ClientPods() { pod := pod // copy to avoid memory aliasing when using reference @@ -42,10 +43,19 @@ func (s *podToHost) Run(ctx context.Context, t *check.Test) { continue } + switch { + case addr.Type == corev1.NodeInternalIP: + addrType = "internal-ip" + case addr.Type == corev1.NodeExternalIP: + addrType = "external-ip" + case addr.Type == corev1.NodeHostName: + addrType = "hostname" + } + dst := check.ICMPEndpoint("", addr.Address) ipFam := features.GetIPFamily(addr.Address) - t.NewAction(s, fmt.Sprintf("ping-%s-%d", ipFam, i), &pod, dst, ipFam).Run(func(a *check.Action) { + t.NewAction(s, fmt.Sprintf("ping-%s-%s", ipFam, addrType), &pod, dst, ipFam).Run(func(a *check.Action) { a.ExecInPod(ctx, ct.PingCommand(dst, ipFam)) a.ValidateFlows(ctx, pod, a.GetEgressRequirements(check.FlowParameters{ @@ -54,8 +64,6 @@ func (s *podToHost) Run(ctx context.Context, t *check.Test) { a.ValidateMetrics(ctx, pod, a.GetEgressMetricsRequirements()) }) - - i++ } }) }