Skip to content

Commit c7a6a71

Browse files
authored
e2e: fix kubectl-ko trace test (#5108)
Signed-off-by: zhangzujian <[email protected]>
1 parent 6f88e19 commit c7a6a71

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

test/e2e/framework/framework.go

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ const (
2727
Dual = "dual"
2828
)
2929

30+
const (
31+
Overlay = "overlay"
32+
Underlay = "underlay"
33+
)
34+
3035
const (
3136
// poll is how often to Poll resources.
3237
poll = 2 * time.Second
@@ -173,6 +178,14 @@ func (f *Framework) HasIPv6() bool {
173178
return !f.IsIPv4()
174179
}
175180

181+
func (f *Framework) IsOverlay() bool {
182+
return f.ClusterNetworkMode == Overlay
183+
}
184+
185+
func (f *Framework) IsUnderlay() bool {
186+
return f.ClusterNetworkMode == Underlay
187+
}
188+
176189
// BeforeEach gets a kube-ovn client
177190
func (f *Framework) BeforeEach() {
178191
ginkgo.By("Setting kubernetes context")

test/e2e/kube-ovn/kubectl-ko/kubectl-ko.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -316,25 +316,35 @@ var _ = framework.Describe("[group:kubectl-ko]", func() {
316316
pod = podClient.CreateSync(pod)
317317

318318
ginkgo.By("Checking trace output")
319+
var traceService bool
319320
subCmd := "ovn-trace"
320321
if f.VersionPriorTo(1, 12) {
321322
subCmd = "trace"
322323
}
323-
outputMatch := fmt.Sprintf("output to %q", ovs.PodNameToPortName(pod2Name, pod2.Namespace, util.OvnProvider))
324+
matchPod := fmt.Sprintf("output to %q", ovs.PodNameToPortName(pod2Name, pod2.Namespace, util.OvnProvider))
325+
matchLocalnet := fmt.Sprintf("output to %q", fmt.Sprintf("localnet.%s", util.DefaultSubnet))
324326
checkFunc := func(output string) {
325327
ginkgo.GinkgoHelper()
328+
var match string
329+
if traceService && f.VersionPriorTo(1, 11) && f.IsUnderlay() {
330+
match = matchLocalnet
331+
} else {
332+
match = matchPod
333+
}
326334
if subCmd == "ovn-trace" {
327335
lines := strings.Split(strings.TrimSpace(output), "\n")
328-
framework.ExpectContainSubstring(lines[len(lines)-1], outputMatch)
336+
framework.ExpectContainSubstring(lines[len(lines)-1], match)
329337
} else {
330-
framework.ExpectContainSubstring(output, outputMatch)
338+
framework.ExpectContainSubstring(output, match)
331339
}
332340
}
333341
for protocol, port := range map[corev1.Protocol]int32{corev1.ProtocolTCP: tcpPort, corev1.ProtocolUDP: udpPort} {
334342
proto := strings.ToLower(string(protocol))
343+
traceService = false
335344
for _, ip := range pod2.Status.PodIPs {
336345
execOrDie(fmt.Sprintf("ko %s %s/%s %s %s %d", subCmd, pod.Namespace, pod.Name, ip.IP, proto, port), checkFunc)
337346
}
347+
traceService = true
338348
for _, ip := range service.Spec.ClusterIPs {
339349
execOrDie(fmt.Sprintf("ko %s %s/%s %s %s %d", subCmd, pod.Namespace, pod.Name, ip, proto, port), checkFunc)
340350
}

0 commit comments

Comments
 (0)