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 authored and tklauser committed Nov 10, 2023
1 parent 5c7423a commit 8a2621a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions connectivity/tests/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"context"
"fmt"

corev1 "k8s.io/api/core/v1"

"github.com/cilium/cilium-cli/connectivity/check"
"github.com/cilium/cilium-cli/utils/features"
)
Expand All @@ -28,7 +30,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 +44,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 +65,6 @@ func (s *podToHost) Run(ctx context.Context, t *check.Test) {

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

i++
}
})
}
Expand Down

0 comments on commit 8a2621a

Please sign in to comment.