Skip to content

Commit 2f4469c

Browse files
committed
feat(tests): custom provider/nad for slrs
Signed-off-by: SkalaNetworks <contact@skala.network>
1 parent bfcb4a1 commit 2f4469c

2 files changed

Lines changed: 45 additions & 20 deletions

File tree

pkg/controller/switch_lb_rule_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import (
44
"reflect"
55
"testing"
66

7-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8-
97
kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
108
"github.com/kubeovn/kube-ovn/pkg/util"
119

1210
corev1 "k8s.io/api/core/v1"
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1312
)
1413

1514
func Test_getIPFamilies(t *testing.T) {

test/e2e/kube-ovn/switch_lb_rule/switch_lb_rule.go

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
1515

1616
kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
17+
"github.com/kubeovn/kube-ovn/pkg/request"
1718
"github.com/kubeovn/kube-ovn/pkg/util"
1819
"github.com/kubeovn/kube-ovn/test/e2e/framework"
1920
)
@@ -52,12 +53,14 @@ var _ = framework.Describe("[group:slr]", func() {
5253
podClient *framework.PodClient
5354
subnetClient *framework.SubnetClient
5455
vpcClient *framework.VpcClient
56+
nadClient *framework.NetworkAttachmentDefinitionClient
5557

5658
namespaceName, suffix string
5759
vpcName, subnetName, clientPodName, label string
5860
stsName, stsSvcName string
5961
selSlrName, selSvcName string
6062
epSlrName, epSvcName string
63+
nadName string
6164
overlaySubnetCidr, vip string
6265
// TODO:// slr support dual-stack
6366
frontPort, selSlrFrontPort, epSlrFrontPort, backendPort int32
@@ -71,9 +74,8 @@ var _ = framework.Describe("[group:slr]", func() {
7174
podClient = f.PodClient()
7275
subnetClient = f.SubnetClient()
7376
vpcClient = f.VpcClient()
74-
77+
nadClient = f.NetworkAttachmentDefinitionClient()
7578
suffix = framework.RandomSuffix()
76-
7779
namespaceName = f.Namespace.Name
7880
selSlrName = "sel-" + generateSwitchLBRuleName(suffix)
7981
selSvcName = generateServiceName(selSlrName)
@@ -84,6 +86,7 @@ var _ = framework.Describe("[group:slr]", func() {
8486
label = "slr"
8587
clientPodName = "client-" + suffix
8688
subnetName = generateSubnetName(suffix)
89+
nadName = subnetName
8790
vpcName = generateVpcName(suffix)
8891
frontPort = 8090
8992
selSlrFrontPort = 8091
@@ -94,15 +97,6 @@ var _ = framework.Describe("[group:slr]", func() {
9497
ginkgo.By("Creating custom vpc")
9598
vpc := framework.MakeVpc(vpcName, "", false, false, []string{namespaceName})
9699
_ = vpcClient.CreateSync(vpc)
97-
ginkgo.By("Creating custom overlay subnet")
98-
overlaySubnet := framework.MakeSubnet(subnetName, "", overlaySubnetCidr, "", vpcName, "", nil, nil, nil)
99-
_ = subnetClient.CreateSync(overlaySubnet)
100-
annotations := map[string]string{
101-
util.LogicalSwitchAnnotation: subnetName,
102-
}
103-
ginkgo.By("Creating client pod " + clientPodName)
104-
clientPod := framework.MakePod(namespaceName, clientPodName, nil, annotations, framework.AgnhostImage, nil, nil)
105-
podClient.CreateSync(clientPod)
106100
})
107101

108102
ginkgo.AfterEach(func() {
@@ -120,10 +114,39 @@ var _ = framework.Describe("[group:slr]", func() {
120114
subnetClient.DeleteSync(subnetName)
121115
ginkgo.By("Deleting vpc " + vpcName)
122116
vpcClient.DeleteSync(vpcName)
117+
ginkgo.By("Deleting network attachment definition " + nadName)
118+
nadClient.Delete(nadName)
123119
})
124120

125-
framework.ConformanceIt("should access sts and slr svc ok", func() {
121+
ginkgo.DescribeTable("Test SLR connectivity", ginkgo.Label("Conformance"), func(customProvider bool) {
126122
f.SkipVersionPriorTo(1, 12, "This feature was introduced in v1.12")
123+
124+
ginkgo.By("Creating custom overlay subnet")
125+
126+
var provider string
127+
annotations := make(map[string]string)
128+
129+
if customProvider {
130+
f.SkipVersionPriorTo(1, 15, "This feature was introduced in v1.15")
131+
provider = fmt.Sprintf("%s.%s.%s", subnetName, f.Namespace.Name, util.OvnProvider)
132+
annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, provider)] = subnetName
133+
annotations[util.DefaultNetworkAnnotation] = fmt.Sprintf("%s/%s", f.Namespace.Name, nadName)
134+
} else {
135+
annotations[util.LogicalSwitchAnnotation] = subnetName
136+
}
137+
138+
overlaySubnet := framework.MakeSubnet(subnetName, "", overlaySubnetCidr, "", vpcName, provider, nil, nil, nil)
139+
_ = subnetClient.CreateSync(overlaySubnet)
140+
141+
if customProvider {
142+
nad := framework.MakeOVNNetworkAttachmentDefinition(subnetName, f.Namespace.Namespace, provider, []request.Route{})
143+
nadClient.Create(nad)
144+
}
145+
146+
ginkgo.By("Creating client pod " + clientPodName)
147+
newClientPod := framework.MakePod(namespaceName, clientPodName, nil, annotations, framework.AgnhostImage, nil, nil)
148+
podClient.CreateSync(newClientPod)
149+
127150
ginkgo.By("1. Creating sts svc with slr")
128151
var (
129152
clientPod *corev1.Pod
@@ -136,9 +159,9 @@ var _ = framework.Describe("[group:slr]", func() {
136159
ginkgo.By("Creating statefulset " + stsName + " with subnet " + subnetName)
137160
sts := framework.MakeStatefulSet(stsName, stsSvcName, int32(replicas), labels, framework.AgnhostImage)
138161
ginkgo.By("Creating sts " + stsName)
139-
sts.Spec.Template.Annotations = map[string]string{
140-
util.LogicalSwitchAnnotation: subnetName,
141-
}
162+
163+
sts.Spec.Template.Annotations = annotations
164+
142165
portStr := strconv.Itoa(80)
143166
webServerCmd := []string{"/agnhost", "netexec", "--http-port", portStr}
144167
sts.Spec.Template.Spec.Containers[0].Command = webServerCmd
@@ -151,10 +174,10 @@ var _ = framework.Describe("[group:slr]", func() {
151174
TargetPort: intstr.FromInt32(80),
152175
}}
153176
selector := map[string]string{"app": label}
154-
annotations := map[string]string{
177+
svcAnnotations := map[string]string{
155178
util.LogicalSwitchAnnotation: subnetName,
156179
}
157-
stsSvc = framework.MakeService(stsSvcName, corev1.ServiceTypeClusterIP, annotations, selector, ports, corev1.ServiceAffinityNone)
180+
stsSvc = framework.MakeService(stsSvcName, corev1.ServiceTypeClusterIP, svcAnnotations, selector, ports, corev1.ServiceAffinityNone)
158181
stsSvc = serviceClient.CreateSync(stsSvc, func(s *corev1.Service) (bool, error) {
159182
return len(s.Spec.ClusterIPs) != 0, nil
160183
}, "cluster ips are not empty")
@@ -352,5 +375,8 @@ var _ = framework.Describe("[group:slr]", func() {
352375
}
353376
ginkgo.By("Checking endpoint switch lb service " + epSvc.Name)
354377
curlSvc(f, clientPodName, vip, epSlrFrontPort)
355-
})
378+
},
379+
ginkgo.Entry("SLR with default provider", false),
380+
ginkgo.Entry("SLR with custom provider", true),
381+
)
356382
})

0 commit comments

Comments
 (0)