Skip to content

Commit 49f04a2

Browse files
author
Karina Ranadive
committed
adjustment for earlier k8s
1 parent b947a40 commit 49f04a2

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

test/integration/lrp/lrp_test.go

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package lrp
44

55
import (
66
"context"
7+
"fmt"
78
"os"
89
"strings"
910
"testing"
@@ -340,6 +341,29 @@ func validateCiliumLRP(t *testing.T, ctx context.Context, cs *k8sclient.Clientse
340341
require.NotEmpty(t, ciliumPods.Items)
341342
ciliumPod := TakeOne(ciliumPods.Items)
342343

344+
// Get Kubernetes version to determine validation approach
345+
serverVersion, err := cs.Discovery().ServerVersion()
346+
require.NoError(t, err)
347+
t.Logf("Detected Kubernetes version: %s", serverVersion.String())
348+
349+
// Parse version to determine if we should use modern or legacy validation
350+
// K8s 1.32.0+ should use modern Cilium format (v1.17+)
351+
useModernFormat := false
352+
if serverVersion.Major == "1" {
353+
// Parse minor version
354+
var minorVersion int
355+
_, err := fmt.Sscanf(serverVersion.Minor, "%d", &minorVersion)
356+
if err == nil && minorVersion >= 32 {
357+
useModernFormat = true
358+
}
359+
}
360+
361+
if useModernFormat {
362+
t.Log("Using modern validation approach based on Kubernetes version >= 1.32.0")
363+
} else {
364+
t.Log("Using legacy validation approach based on Kubernetes version < 1.32.0")
365+
}
366+
343367
// Get kube-dns service IP for validation
344368
svc, err := kubernetes.GetService(ctx, cs, kubeSystemNamespace, dnsService)
345369
require.NoError(t, err)
@@ -405,21 +429,34 @@ func validateCiliumLRP(t *testing.T, ctx context.Context, cs *k8sclient.Clientse
405429
if strings.Contains(line, "LocalRedirect") && strings.Contains(line, kubeDNSIP) {
406430
// Check if this line contains the expected frontend (kube-dns) and backend (node-local-dns) IPs
407431
if strings.Contains(line, nodeLocalDNSIP) {
408-
if strings.Contains(line, "/TCP") {
409-
tcpFound = true
410-
t.Logf("Found TCP LocalRedirect: %s", strings.TrimSpace(line))
411-
}
412-
if strings.Contains(line, "/UDP") {
413-
udpFound = true
414-
t.Logf("Found UDP LocalRedirect: %s", strings.TrimSpace(line))
432+
if useModernFormat {
433+
// Modern format (K8s 1.32.0+/Cilium v1.17+): Check for explicit protocol
434+
if strings.Contains(line, "/TCP") {
435+
tcpFound = true
436+
t.Logf("Found TCP LocalRedirect: %s", strings.TrimSpace(line))
437+
} else if strings.Contains(line, "/UDP") {
438+
udpFound = true
439+
t.Logf("Found UDP LocalRedirect: %s", strings.TrimSpace(line))
440+
}
441+
} else {
442+
// Legacy format (K8s < 1.32.0/Cilium < v1.17): No protocol specified
443+
t.Logf("Found legacy LocalRedirect: %s", strings.TrimSpace(line))
415444
}
416445
}
417446
}
418447
}
419448

420-
// Verify both TCP and UDP LocalRedirect entries exist
421-
require.True(t, tcpFound, "TCP LocalRedirect entry not found with frontend IP %s and backend IP %s on node %s", kubeDNSIP, nodeLocalDNSIP, selectedNode)
422-
require.True(t, udpFound, "UDP LocalRedirect entry not found with frontend IP %s and backend IP %s on node %s", kubeDNSIP, nodeLocalDNSIP, selectedNode)
449+
// Validate based on determined format
450+
if useModernFormat {
451+
// Modern format (K8s 1.32.0+/Cilium v1.17+): Separate TCP and UDP entries
452+
t.Log("Validating modern Cilium format - expecting separate TCP and UDP LocalRedirect entries")
453+
require.True(t, tcpFound, "TCP LocalRedirect entry not found with frontend IP %s and backend IP %s on node %s", kubeDNSIP, nodeLocalDNSIP, selectedNode)
454+
require.True(t, udpFound, "UDP LocalRedirect entry not found with frontend IP %s and backend IP %s on node %s", kubeDNSIP, nodeLocalDNSIP, selectedNode)
455+
} else {
456+
// Legacy format (K8s < 1.32.0/Cilium < v1.17): Just one LocalRedirect entry without protocol
457+
t.Log("Validating legacy Cilium format - expecting single LocalRedirect entry without protocol")
458+
require.False(t, useModernFormat, "Legacy LocalRedirect entry not found with frontend IP %s and backend IP %s on node %s", kubeDNSIP, nodeLocalDNSIP, selectedNode)
459+
}
423460

424461
t.Logf("Cilium LRP List Output:\n%s", string(lrpOutput))
425462
t.Logf("Cilium Service List Output:\n%s", string(serviceOutput))

0 commit comments

Comments
 (0)