Skip to content

Commit

Permalink
Add node addr type to pod to host test
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
darox committed Nov 10, 2023
1 parent 408b445 commit a196023
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions connectivity/tests/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

Check failure on line 9 in connectivity/tests/host.go

View workflow job for this annotation

GitHub Actions / build

File is not `goimports`-ed with -local github.com/cilium/cilium-cli (goimports)
"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
Expand All @@ -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
Expand All @@ -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{
Expand All @@ -54,8 +64,6 @@ func (s *podToHost) Run(ctx context.Context, t *check.Test) {

a.ValidateMetrics(ctx, pod, a.GetEgressMetricsRequirements())
})

i++
}
})
}
Expand Down

0 comments on commit a196023

Please sign in to comment.