Skip to content

Commit 095bc73

Browse files
authored
Merge pull request #943 from l1b0k/fix/e2e
Fix/e2e
2 parents f479336 + 6b33db4 commit 095bc73

File tree

7 files changed

+498
-69
lines changed

7 files changed

+498
-69
lines changed

tests/config_test.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ func TestIPPool(t *testing.T) {
2424
t.Skipf("skip ipam type not crd")
2525
}
2626

27+
// Check if all nodes are exclusive ENI or Lingjun nodes, skip pool test in this case
28+
nodeInfo, err := DiscoverNodeTypes(ctx, config.Client())
29+
if err != nil {
30+
t.Fatalf("failed to discover node types: %v", err)
31+
}
32+
if len(nodeInfo.ECSSharedENINodes) == 0 && len(nodeInfo.LingjunSharedENINodes) == 0 {
33+
t.Skipf("TestIPPool requires shared ENI nodes, all nodes are exclusive ENI or Lingjun nodes")
34+
}
35+
2736
// Check terway daemonset name is terway-eniip
2837
isTerwayENIIP, err := CheckTerwayDaemonSetName(ctx, config, "terway-eniip")
2938
if err != nil {
@@ -33,15 +42,15 @@ func TestIPPool(t *testing.T) {
3342
t.Skipf("TestIPPool requires terway-eniip daemonset")
3443
}
3544

36-
// Check terway version >= v1.16.1
37-
versionOK, err := CheckTerwayVersion(ctx, config, "v1.16.1")
38-
if err != nil {
39-
t.Fatalf("failed to check terway version: %v", err)
40-
}
41-
if !versionOK {
42-
terwayVersion, _ := GetTerwayVersion(ctx, config)
43-
t.Skipf("TestIPPool requires terway version >= v1.16.1, current version: %s", terwayVersion)
44-
}
45+
// Check terway version >= v1.16.1
46+
versionOK, err := CheckTerwayVersion(ctx, config, "v1.16.1")
47+
if err != nil {
48+
t.Fatalf("failed to check terway version: %v", err)
49+
}
50+
if !versionOK {
51+
terwayVersion, _ := GetTerwayVersion(ctx, config)
52+
t.Skipf("TestIPPool requires terway version >= v1.16.1, current version: %s", terwayVersion)
53+
}
4554

4655
return ctx
4756
}).
@@ -89,6 +98,9 @@ func TestIPPool(t *testing.T) {
8998
return false, err
9099
}
91100
for _, node := range nodes.Items {
101+
if isExclusiveENINode(&node) {
102+
continue
103+
}
92104
idle := 0
93105
for _, eni := range node.Status.NetworkInterfaces {
94106
if eni.Status != aliyunClient.ENIStatusInUse {
@@ -162,6 +174,9 @@ func TestIPPool(t *testing.T) {
162174
return false, err
163175
}
164176
for _, node := range nodes.Items {
177+
if isExclusiveENINode(&node) {
178+
continue
179+
}
165180
idle := 0
166181
for _, eni := range node.Status.NetworkInterfaces {
167182
if eni.Status != aliyunClient.ENIStatusInUse {
@@ -232,6 +247,9 @@ func TestIPPool(t *testing.T) {
232247
t.Fatalf("failed to get node cr: %v", err)
233248
}
234249
for _, node := range nodes.Items {
250+
if isExclusiveENINode(&node) {
251+
continue
252+
}
235253
idle := 0
236254
for _, eni := range node.Status.NetworkInterfaces {
237255
if eni.Status != aliyunClient.ENIStatusInUse {

tests/connective_test.go

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,12 @@ func TestNormal_NetworkPolicy(t *testing.T) {
546546
}
547547
}
548548

549+
// hostPortTestState stores state for HostPort test configuration and restoration
550+
type hostPortTestState struct {
551+
backup *ENIConfigBackup
552+
configured bool
553+
}
554+
549555
func TestNormal_HostPort(t *testing.T) {
550556
// Check terway daemonset name is terway-eniip
551557
if terway != "terway-eniip" {
@@ -554,6 +560,7 @@ func TestNormal_HostPort(t *testing.T) {
554560
}
555561

556562
var feats []features.Feature
563+
state := &hostPortTestState{}
557564

558565
mutateConfig := generatePodConfigs("HostPort")
559566
if mutateConfig == nil {
@@ -592,6 +599,45 @@ func TestNormal_HostPort(t *testing.T) {
592599
t.Skipf("TestNormal_HostPort requires k8s version >= v1.34.0, current version: %s", k8sVersion)
593600
}
594601

602+
// Check if nodes have no-kube-proxy label (kube-proxy replacement / Datapath V2)
603+
hasNoKubeProxy, err := CheckNoKubeProxyLabel(ctx, config.Client())
604+
if err != nil {
605+
t.Fatalf("failed to check no-kube-proxy label: %v", err)
606+
}
607+
608+
if hasNoKubeProxy {
609+
t.Log("Node has k8s.aliyun.com/no-kube-proxy=true label, HostPort can be tested directly")
610+
} else {
611+
t.Log("Node does not have k8s.aliyun.com/no-kube-proxy=true label, configuring CNI chain with portmap plugin")
612+
613+
// Backup current eni-config
614+
state.backup, err = BackupENIConfig(ctx, config)
615+
if err != nil {
616+
t.Fatalf("failed to backup eni-config: %v", err)
617+
}
618+
619+
// Check if Datapath V2 is enabled
620+
isDatapathV2, err := IsDatapathV2Enabled(ctx, config)
621+
if err != nil {
622+
t.Fatalf("failed to check datapath v2: %v", err)
623+
}
624+
625+
// Configure CNI chain with portmap plugin
626+
err = ConfigureHostPortCNIChain(ctx, config, isDatapathV2)
627+
if err != nil {
628+
t.Fatalf("failed to configure CNI chain for HostPort: %v", err)
629+
}
630+
631+
// Restart terway to apply new configuration
632+
err = restartTerway(ctx, config)
633+
if err != nil {
634+
t.Fatalf("failed to restart terway: %v", err)
635+
}
636+
637+
state.configured = true
638+
t.Log("CNI chain configured with portmap plugin and terway restarted")
639+
}
640+
595641
var objs []k8s.Object
596642

597643
// Create server pod with hostPort
@@ -701,6 +747,76 @@ func TestNormal_HostPort(t *testing.T) {
701747
t.Skipf("TestNormal_HostPort requires k8s version >= v1.34.0, current version: %s", k8sVersion)
702748
}
703749

750+
// Check if any node has external IP before running the test
751+
nodes := &corev1.NodeList{}
752+
err = config.Client().Resources().List(ctx, nodes)
753+
if err != nil {
754+
t.Fatalf("failed to list nodes: %v", err)
755+
}
756+
757+
hasExternalIP := false
758+
for _, node := range nodes.Items {
759+
for _, stack := range getStack() {
760+
isIPv6 := stack == "ipv6"
761+
_, externalIP := getNodeIPs(&node, isIPv6)
762+
if externalIP != "" {
763+
hasExternalIP = true
764+
break
765+
}
766+
}
767+
if hasExternalIP {
768+
break
769+
}
770+
}
771+
772+
if !hasExternalIP {
773+
t.Skipf("No node has external IP, skipping HostPort/ExternalIP test")
774+
}
775+
776+
// Check if nodes have no-kube-proxy label (kube-proxy replacement / Datapath V2)
777+
hasNoKubeProxy, err := CheckNoKubeProxyLabel(ctx, config.Client())
778+
if err != nil {
779+
t.Fatalf("failed to check no-kube-proxy label: %v", err)
780+
}
781+
782+
if hasNoKubeProxy {
783+
t.Log("Node has k8s.aliyun.com/no-kube-proxy=true label, HostPort can be tested directly")
784+
} else {
785+
// Only configure if not already configured by the first test case
786+
if !state.configured {
787+
t.Log("Node does not have k8s.aliyun.com/no-kube-proxy=true label, configuring CNI chain with portmap plugin")
788+
789+
// Backup current eni-config
790+
state.backup, err = BackupENIConfig(ctx, config)
791+
if err != nil {
792+
t.Fatalf("failed to backup eni-config: %v", err)
793+
}
794+
795+
// Check if Datapath V2 is enabled
796+
isDatapathV2, err := IsDatapathV2Enabled(ctx, config)
797+
if err != nil {
798+
t.Fatalf("failed to check datapath v2: %v", err)
799+
}
800+
801+
// Configure CNI chain with portmap plugin
802+
err = ConfigureHostPortCNIChain(ctx, config, isDatapathV2)
803+
if err != nil {
804+
t.Fatalf("failed to configure CNI chain for HostPort: %v", err)
805+
}
806+
807+
// Restart terway to apply new configuration
808+
err = restartTerway(ctx, config)
809+
if err != nil {
810+
t.Fatalf("failed to restart terway: %v", err)
811+
}
812+
813+
state.configured = true
814+
t.Log("CNI chain configured with portmap plugin and terway restarted")
815+
} else {
816+
t.Log("CNI chain already configured with portmap plugin from previous test case")
817+
}
818+
}
819+
704820
var objs []k8s.Object
705821

706822
// Create server pod with hostPort on different port
@@ -783,12 +899,34 @@ func TestNormal_HostPort(t *testing.T) {
783899

784900
return MarkTestSuccess(ctx)
785901
}).
902+
Teardown(func(ctx context.Context, t *testing.T, config *envconf.Config) context.Context {
903+
// Restore eni-config if we configured it (do this in the last feature's teardown)
904+
if state.configured && state.backup != nil {
905+
err := RestoreENIConfig(ctx, config, state.backup)
906+
if err != nil {
907+
t.Logf("Warning: failed to restore eni-config: %v", err)
908+
} else {
909+
t.Log("Restored original eni-config")
910+
// Restart terway to apply restored configuration
911+
err = restartTerway(ctx, config)
912+
if err != nil {
913+
t.Logf("Warning: failed to restart terway after restoration: %v", err)
914+
} else {
915+
t.Log("Terway restarted with restored configuration")
916+
}
917+
}
918+
state.configured = false
919+
state.backup = nil
920+
}
921+
return ctx
922+
}).
786923
Feature()
787924

788925
feats = append(feats, hostPortNodeIP, hostPortExternalIP)
789926
}
790927

791928
testenv.Test(t, feats...)
929+
792930
if t.Failed() {
793931
isFailed.Store(true)
794932
}

tests/idle_ip_reclaim_test.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ func TestIdleIPReclaimPolicy(t *testing.T) {
9090
t.Skipf("TestIdleIPReclaimPolicy requires terway-eniip daemonset")
9191
}
9292

93-
// Check terway version >= v1.16.1
94-
versionOK, err := CheckTerwayVersion(ctx, config, "v1.16.1")
95-
if err != nil {
96-
t.Fatalf("failed to check terway version: %v", err)
97-
}
98-
if !versionOK {
99-
terwayVersion, _ := GetTerwayVersion(ctx, config)
100-
t.Skipf("TestIdleIPReclaimPolicy requires terway version >= v1.16.1, current version: %s", terwayVersion)
101-
}
93+
// Check terway version >= v1.16.1
94+
versionOK, err := CheckTerwayVersion(ctx, config, "v1.16.1")
95+
if err != nil {
96+
t.Fatalf("failed to check terway version: %v", err)
97+
}
98+
if !versionOK {
99+
terwayVersion, _ := GetTerwayVersion(ctx, config)
100+
t.Skipf("TestIdleIPReclaimPolicy requires terway version >= v1.16.1, current version: %s", terwayVersion)
101+
}
102102

103103
// Cleanup pool configuration before tests
104104
err = cleanupPoolConfig(ctx, t, config)
@@ -232,6 +232,10 @@ func TestIdleIPReclaimPolicy(t *testing.T) {
232232

233233
allNodesOk := true
234234
for _, node := range nodes.Items {
235+
if isExclusiveENINode(&node) {
236+
continue
237+
}
238+
235239
idleCount := countIdleIPs(&node)
236240
// After reclaim, idle IPs should be between min_pool_size and max_pool_size
237241
// Due to batch processing, it might not reach exactly min_pool_size
@@ -366,6 +370,9 @@ func TestIdleIPReclaimPolicy(t *testing.T) {
366370
}
367371

368372
for _, node := range nodes.Items {
373+
if isExclusiveENINode(&node) {
374+
continue
375+
}
369376
idleCount := countIdleIPs(&node)
370377
t.Logf("Node %s: idle IPs = %d", node.Name, idleCount)
371378
if idleCount < 5 {
@@ -582,7 +589,7 @@ func waitForIdleIPCount(ctx context.Context, config *envconf.Config, t *testing.
582589
allNodesReady := true
583590
for _, node := range nodes.Items {
584591
// Skip nodes that should be excluded from idle IP checks (Lingjun and exclusive ENI nodes)
585-
if ShouldExcludeNodeForIdleIPCheck(&node) {
592+
if isExclusiveENINode(&node) {
586593
t.Logf("[%s] Skipping node %s (excluded from idle IP checks)", phase, node.Name)
587594
continue
588595
}

tests/multi_network_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@ func createMultiNetworkTestFeature(testName string, nodeType NodeType, mode stri
126126
return features.New(testName).
127127
WithLabel("env", "multi-network").
128128
Setup(func(ctx context.Context, t *testing.T, config *envconf.Config) context.Context {
129-
// Check terway version >= v1.16.1
130-
versionOK, err := CheckTerwayVersion(ctx, config, "v1.16.1")
131-
if err != nil {
132-
t.Fatalf("failed to check terway version: %v", err)
133-
}
134-
if !versionOK {
135-
terwayVersion, _ := GetTerwayVersion(ctx, config)
136-
t.Skipf("TestMultiNetwork requires terway version >= v1.16.1, current version: %s", terwayVersion)
137-
}
129+
// Check terway version >= v1.16.1
130+
versionOK, err := CheckTerwayVersion(ctx, config, "v1.16.1")
131+
if err != nil {
132+
t.Fatalf("failed to check terway version: %v", err)
133+
}
134+
if !versionOK {
135+
terwayVersion, _ := GetTerwayVersion(ctx, config)
136+
t.Skipf("TestMultiNetwork requires terway version >= v1.16.1, current version: %s", terwayVersion)
137+
}
138138

139139
// Check if required node type is available
140140
nodeInfo, err := DiscoverNodeTypes(context.Background(), config.Client())
@@ -147,6 +147,11 @@ func createMultiNetworkTestFeature(testName string, nodeType NodeType, mode stri
147147
t.Skipf("No nodes of type %s available", nodeType)
148148
}
149149

150+
switch nodeType {
151+
case NodeTypeLingjunSharedENI, NodeTypeLingjunExclusiveENI:
152+
t.Skipf("Lingjun nodes are not supported yet")
153+
}
154+
150155
// Create primary PodNetworking (always use default config)
151156
pn1 := NewPodNetworking(pnPrimary)
152157
if nodeType == NodeTypeECSExclusiveENI || nodeType == NodeTypeLingjunExclusiveENI {

0 commit comments

Comments
 (0)