Skip to content

e2e: fix kubectl-ko trace test #5108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions test/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ const (
Dual = "dual"
)

const (
Overlay = "overlay"
Underlay = "underlay"
)

const (
// poll is how often to Poll resources.
poll = 2 * time.Second
Expand Down Expand Up @@ -173,6 +178,14 @@ func (f *Framework) HasIPv6() bool {
return !f.IsIPv4()
}

func (f *Framework) IsOverlay() bool {
return f.ClusterNetworkMode == Overlay
}

func (f *Framework) IsUnderlay() bool {
return f.ClusterNetworkMode == Underlay
}

// BeforeEach gets a kube-ovn client
func (f *Framework) BeforeEach() {
ginkgo.By("Setting kubernetes context")
Expand Down
16 changes: 13 additions & 3 deletions test/e2e/kube-ovn/kubectl-ko/kubectl-ko.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,25 +316,35 @@ var _ = framework.Describe("[group:kubectl-ko]", func() {
pod = podClient.CreateSync(pod)

ginkgo.By("Checking trace output")
var traceService bool
subCmd := "ovn-trace"
if f.VersionPriorTo(1, 12) {
subCmd = "trace"
}
outputMatch := fmt.Sprintf("output to %q", ovs.PodNameToPortName(pod2Name, pod2.Namespace, util.OvnProvider))
matchPod := fmt.Sprintf("output to %q", ovs.PodNameToPortName(pod2Name, pod2.Namespace, util.OvnProvider))
matchLocalnet := fmt.Sprintf("output to %q", fmt.Sprintf("localnet.%s", util.DefaultSubnet))
checkFunc := func(output string) {
ginkgo.GinkgoHelper()
var match string
if traceService && f.VersionPriorTo(1, 11) && f.IsUnderlay() {
match = matchLocalnet
} else {
match = matchPod
}
Comment on lines +328 to +333

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This conditional logic could be simplified by combining the version and network mode checks. This would make the code easier to read and understand. Consider using a single if statement with combined conditions.

Suggested change
var match string
if traceService && f.VersionPriorTo(1, 11) && f.IsUnderlay() {
match = matchLocalnet
} else {
match = matchPod
}
var match string
if traceService && f.VersionPriorTo(1, 11) && f.IsUnderlay() {
match = matchLocalnet
} else {
match = matchPod
}

if subCmd == "ovn-trace" {
lines := strings.Split(strings.TrimSpace(output), "\n")
framework.ExpectContainSubstring(lines[len(lines)-1], outputMatch)
framework.ExpectContainSubstring(lines[len(lines)-1], match)
} else {
framework.ExpectContainSubstring(output, outputMatch)
framework.ExpectContainSubstring(output, match)
}
}
for protocol, port := range map[corev1.Protocol]int32{corev1.ProtocolTCP: tcpPort, corev1.ProtocolUDP: udpPort} {
proto := strings.ToLower(string(protocol))
traceService = false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Add a comment here to explain the purpose of traceService. For example, what does it mean when traceService is true vs. false, and how does it affect the trace output?

// traceService is a flag to indicate whether we are tracing a service IP.
// When tracing a service IP, the output should match the localnet interface.
traceService = false

for _, ip := range pod2.Status.PodIPs {
execOrDie(fmt.Sprintf("ko %s %s/%s %s %s %d", subCmd, pod.Namespace, pod.Name, ip.IP, proto, port), checkFunc)
}
traceService = true
for _, ip := range service.Spec.ClusterIPs {
execOrDie(fmt.Sprintf("ko %s %s/%s %s %s %d", subCmd, pod.Namespace, pod.Name, ip, proto, port), checkFunc)
}
Expand Down
Loading