From c52f15b5102e805356236fee4631f62e2a54656c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E7=A5=96=E5=BB=BA?= Date: Sat, 5 Aug 2023 13:03:44 +0800 Subject: [PATCH] some fixes in e2e --- pkg/controller/subnet.go | 4 ++-- test/e2e/framework/daemonset.go | 2 ++ test/e2e/framework/deployment.go | 2 ++ test/e2e/framework/endpoints.go | 2 ++ test/e2e/framework/event.go | 4 +++- test/e2e/framework/network-policy.go | 2 ++ test/e2e/framework/pod.go | 7 ++++--- test/e2e/framework/service.go | 2 ++ test/e2e/framework/statefulset.go | 2 ++ test/e2e/framework/switch-lb-rule.go | 2 ++ test/e2e/kube-ovn/subnet/subnet.go | 9 +++++---- test/e2e/kube-ovn/underlay/underlay.go | 21 +++++++++++++++++++++ 12 files changed, 49 insertions(+), 10 deletions(-) diff --git a/pkg/controller/subnet.go b/pkg/controller/subnet.go index cc8e28d8871..bfea5f61a64 100644 --- a/pkg/controller/subnet.go +++ b/pkg/controller/subnet.go @@ -111,12 +111,12 @@ func (c *Controller) enqueueUpdateSubnet(old, new interface{}) { if oldSubnet.Spec.GatewayType != newSubnet.Spec.GatewayType { c.recorder.Eventf(newSubnet, v1.EventTypeNormal, "SubnetGatewayTypeChanged", - "subnet gateway type changes from %s to %s ", oldSubnet.Spec.GatewayType, newSubnet.Spec.GatewayType) + "subnet gateway type changes from %q to %q", oldSubnet.Spec.GatewayType, newSubnet.Spec.GatewayType) } if oldSubnet.Spec.GatewayNode != newSubnet.Spec.GatewayNode { c.recorder.Eventf(newSubnet, v1.EventTypeNormal, "SubnetGatewayNodeChanged", - "gateway node changes from %s to %s ", oldSubnet.Spec.GatewayNode, newSubnet.Spec.GatewayNode) + "gateway node changes from %q to %q", oldSubnet.Spec.GatewayNode, newSubnet.Spec.GatewayNode) } c.addOrUpdateSubnetQueue.Add(key) diff --git a/test/e2e/framework/daemonset.go b/test/e2e/framework/daemonset.go index 182926af7b5..941cc320c3a 100644 --- a/test/e2e/framework/daemonset.go +++ b/test/e2e/framework/daemonset.go @@ -22,6 +22,7 @@ import ( type DaemonSetClient struct { f *Framework v1apps.DaemonSetInterface + namespace string } func (f *Framework) DaemonSetClient() *DaemonSetClient { @@ -32,6 +33,7 @@ func (f *Framework) DaemonSetClientNS(namespace string) *DaemonSetClient { return &DaemonSetClient{ f: f, DaemonSetInterface: f.ClientSet.AppsV1().DaemonSets(namespace), + namespace: namespace, } } diff --git a/test/e2e/framework/deployment.go b/test/e2e/framework/deployment.go index d277a6d9389..59e41e540bc 100644 --- a/test/e2e/framework/deployment.go +++ b/test/e2e/framework/deployment.go @@ -29,6 +29,7 @@ import ( type DeploymentClient struct { f *Framework v1apps.DeploymentInterface + namespace string } func (f *Framework) DeploymentClient() *DeploymentClient { @@ -39,6 +40,7 @@ func (f *Framework) DeploymentClientNS(namespace string) *DeploymentClient { return &DeploymentClient{ f: f, DeploymentInterface: f.ClientSet.AppsV1().Deployments(namespace), + namespace: namespace, } } diff --git a/test/e2e/framework/endpoints.go b/test/e2e/framework/endpoints.go index 21bc23c9e70..ae9685b1e56 100644 --- a/test/e2e/framework/endpoints.go +++ b/test/e2e/framework/endpoints.go @@ -21,6 +21,7 @@ import ( type EndpointsClient struct { f *Framework v1core.EndpointsInterface + namespace string } func (f *Framework) EndpointClient() *EndpointsClient { @@ -31,6 +32,7 @@ func (f *Framework) EndpointsClientNS(namespace string) *EndpointsClient { return &EndpointsClient{ f: f, EndpointsInterface: f.ClientSet.CoreV1().Endpoints(namespace), + namespace: namespace, } } diff --git a/test/e2e/framework/event.go b/test/e2e/framework/event.go index 4fd72ea100a..d346f16a16a 100644 --- a/test/e2e/framework/event.go +++ b/test/e2e/framework/event.go @@ -13,6 +13,7 @@ import ( type EventClient struct { f *Framework typedcorev1.EventInterface + namespace string } func (f *Framework) EventClient() *EventClient { @@ -23,6 +24,7 @@ func (f *Framework) EventClientNS(namespace string) *EventClient { return &EventClient{ f: f, EventInterface: f.ClientSet.CoreV1().Events(namespace), + namespace: namespace, } } @@ -30,7 +32,7 @@ func (f *Framework) EventClientNS(namespace string) *EventClient { func (c *EventClient) WaitToHaveEvent(kind, name, eventType, reason, sourceComponent, sourceHost string) []corev1.Event { var result []corev1.Event err := wait.PollUntilContextTimeout(context.Background(), poll, timeout, false, func(ctx context.Context) (bool, error) { - Logf("Waiting for %s %s/%s to have event %s/%s", kind, c.f.Namespace.Name, name, eventType, reason) + Logf("Waiting for %s %s/%s to have event %s/%s", kind, c.namespace, name, eventType, reason) selector := fields.Set{ "involvedObject.kind": kind, "involvedObject.name": name, diff --git a/test/e2e/framework/network-policy.go b/test/e2e/framework/network-policy.go index 174bbfc1cd7..6c08df8651f 100644 --- a/test/e2e/framework/network-policy.go +++ b/test/e2e/framework/network-policy.go @@ -18,6 +18,7 @@ import ( type NetworkPolicyClient struct { f *Framework v1net.NetworkPolicyInterface + namespace string } func (f *Framework) NetworkPolicyClient() *NetworkPolicyClient { @@ -28,6 +29,7 @@ func (f *Framework) NetworkPolicyClientNS(namespace string) *NetworkPolicyClient return &NetworkPolicyClient{ f: f, NetworkPolicyInterface: f.ClientSet.NetworkingV1().NetworkPolicies(namespace), + namespace: namespace, } } diff --git a/test/e2e/framework/pod.go b/test/e2e/framework/pod.go index 8f3921ba0bb..3a3a57bc822 100644 --- a/test/e2e/framework/pod.go +++ b/test/e2e/framework/pod.go @@ -17,6 +17,7 @@ import ( type PodClient struct { f *Framework *e2epod.PodClient + namespace string } func (f *Framework) PodClient() *PodClient { @@ -24,7 +25,7 @@ func (f *Framework) PodClient() *PodClient { } func (f *Framework) PodClientNS(namespace string) *PodClient { - return &PodClient{f, e2epod.PodClientNS(f.Framework, namespace)} + return &PodClient{f, e2epod.PodClientNS(f.Framework, namespace), namespace} } func (c *PodClient) GetPod(name string) *corev1.Pod { @@ -75,12 +76,12 @@ func (c *PodClient) Patch(original, modified *corev1.Pod) *corev1.Pod { } func (c *PodClient) WaitForRunning(name string) { - err := e2epod.WaitTimeoutForPodRunningInNamespace(context.TODO(), c.f.ClientSet, name, c.f.Namespace.Name, timeout) + err := e2epod.WaitTimeoutForPodRunningInNamespace(context.TODO(), c.f.ClientSet, name, c.namespace, timeout) ExpectNoError(err) } func (c *PodClient) WaitForNotFound(name string) { - err := e2epod.WaitForPodNotFoundInNamespace(context.TODO(), c.f.ClientSet, name, c.f.Namespace.Name, timeout) + err := e2epod.WaitForPodNotFoundInNamespace(context.TODO(), c.f.ClientSet, name, c.namespace, timeout) ExpectNoError(err) } diff --git a/test/e2e/framework/service.go b/test/e2e/framework/service.go index 54a2742f3aa..78083d11e97 100644 --- a/test/e2e/framework/service.go +++ b/test/e2e/framework/service.go @@ -23,6 +23,7 @@ import ( type ServiceClient struct { f *Framework v1core.ServiceInterface + namespace string } func (f *Framework) ServiceClient() *ServiceClient { @@ -33,6 +34,7 @@ func (f *Framework) ServiceClientNS(namespace string) *ServiceClient { return &ServiceClient{ f: f, ServiceInterface: f.ClientSet.CoreV1().Services(namespace), + namespace: namespace, } } diff --git a/test/e2e/framework/statefulset.go b/test/e2e/framework/statefulset.go index a5677c201c5..f98bc70d705 100644 --- a/test/e2e/framework/statefulset.go +++ b/test/e2e/framework/statefulset.go @@ -19,6 +19,7 @@ import ( type StatefulSetClient struct { f *Framework v1apps.StatefulSetInterface + namespace string } func (f *Framework) StatefulSetClient() *StatefulSetClient { @@ -29,6 +30,7 @@ func (f *Framework) StatefulSetClientNS(namespace string) *StatefulSetClient { return &StatefulSetClient{ f: f, StatefulSetInterface: f.ClientSet.AppsV1().StatefulSets(namespace), + namespace: namespace, } } diff --git a/test/e2e/framework/switch-lb-rule.go b/test/e2e/framework/switch-lb-rule.go index a3b8737e1a9..b5038c0039a 100644 --- a/test/e2e/framework/switch-lb-rule.go +++ b/test/e2e/framework/switch-lb-rule.go @@ -23,6 +23,7 @@ import ( type SwitchLBRuleClient struct { f *Framework v1.SwitchLBRuleInterface + namespace string } func (f *Framework) SwitchLBRuleClient() *SwitchLBRuleClient { @@ -33,6 +34,7 @@ func (f *Framework) SwitchLBRuleClientNS(namespace string) *SwitchLBRuleClient { return &SwitchLBRuleClient{ f: f, SwitchLBRuleInterface: f.KubeOVNClientSet.KubeovnV1().SwitchLBRules(), + namespace: namespace, } } diff --git a/test/e2e/kube-ovn/subnet/subnet.go b/test/e2e/kube-ovn/subnet/subnet.go index 6a1b470646f..b4267aebe27 100644 --- a/test/e2e/kube-ovn/subnet/subnet.go +++ b/test/e2e/kube-ovn/subnet/subnet.go @@ -1032,10 +1032,10 @@ var _ = framework.Describe("[group:subnet]", func() { eventClient = f.EventClientNS("default") events := eventClient.WaitToHaveEvent("Subnet", subnetName, "Normal", "SubnetGatewayTypeChanged", "kube-ovn-controller", "") - message := fmt.Sprintf("subnet gateway type changes from %s to %s ", apiv1.GWDistributedType, apiv1.GWCentralizedType) + message := fmt.Sprintf("subnet gateway type changes from %q to %q", apiv1.GWDistributedType, apiv1.GWCentralizedType) found := false for _, event := range events { - if strings.Contains(event.Message, message) { + if event.Message == message { found = true break } @@ -1043,9 +1043,9 @@ var _ = framework.Describe("[group:subnet]", func() { framework.ExpectTrue(found, "no SubnetGatewayTypeChanged event") found = false events = eventClient.WaitToHaveEvent("Subnet", subnetName, "Normal", "SubnetGatewayNodeChanged", "kube-ovn-controller", "") - message = fmt.Sprintf("gateway node changes from %s to %s ", "", modifiedSubnet.Spec.GatewayNode) + message = fmt.Sprintf("gateway node changes from %q to %q", "", modifiedSubnet.Spec.GatewayNode) for _, event := range events { - if strings.Contains(event.Message, message) { + if event.Message == message { found = true break } @@ -1073,6 +1073,7 @@ var _ = framework.Describe("[group:subnet]", func() { } } }) + framework.ConformanceIt("should support subnet add nat outgoing policy rules ", func() { f.SkipVersionPriorTo(1, 12, "Support for subnet add nat outgoing policy rules in v1.12") diff --git a/test/e2e/kube-ovn/underlay/underlay.go b/test/e2e/kube-ovn/underlay/underlay.go index 526c886fed1..1808147cb7a 100644 --- a/test/e2e/kube-ovn/underlay/underlay.go +++ b/test/e2e/kube-ovn/underlay/underlay.go @@ -47,6 +47,18 @@ func makeProviderNetwork(providerNetworkName string, exchangeLinkName bool, link return framework.MakeProviderNetwork(providerNetworkName, exchangeLinkName, defaultInterface, customInterfaces, nil) } +func waitSubnetStatusUpdate(subnetName string, subnetClient *framework.SubnetClient, expectedUsingIPs float64) { + ginkgo.By("Waiting for status of subnet " + subnetName + " to be updated") + framework.WaitUntil(2*time.Second, 30*time.Second, func(_ context.Context) (bool, error) { + subnet := subnetClient.Get(subnetName) + if (subnet.Status.V4AvailableIPs != 0 && subnet.Status.V4UsingIPs != expectedUsingIPs) || + (subnet.Status.V6AvailableIPs != 0 && subnet.Status.V6UsingIPs != expectedUsingIPs) { + return false, nil + } + return true, nil + }, "") +} + var _ = framework.SerialDescribe("[group:underlay]", func() { f := framework.NewDefaultFramework("underlay") @@ -521,6 +533,7 @@ var _ = framework.SerialDescribe("[group:underlay]", func() { args := []string{"netexec", "--http-port", strconv.Itoa(curlListenPort)} originUnderlayPod := framework.MakePod(namespaceName, u2oPodNameUnderlay, nil, annotations, framework.AgnhostImage, nil, args) underlayPod := podClient.CreateSync(originUnderlayPod) + waitSubnetStatusUpdate(subnetName, subnetClient, 2) ginkgo.By("Creating overlay subnet " + u2oOverlaySubnetName) cidr := framework.RandomCIDR(f.ClusterIpFamily) @@ -552,6 +565,7 @@ var _ = framework.SerialDescribe("[group:underlay]", func() { ginkgo.By("Creating underlay pod " + u2oPodNameUnderlay) underlayPod = podClient.CreateSync(originUnderlayPod) + waitSubnetStatusUpdate(subnetName, subnetClient, 1) subnet = subnetClient.Get(subnetName) checkU2OItems(f, subnet, underlayPod, overlayPod, false) @@ -569,6 +583,7 @@ var _ = framework.SerialDescribe("[group:underlay]", func() { ginkgo.By("Creating underlay pod " + u2oPodNameUnderlay) underlayPod = podClient.CreateSync(originUnderlayPod) + waitSubnetStatusUpdate(subnetName, subnetClient, 2) subnet = subnetClient.Get(subnetName) checkU2OItems(f, subnet, underlayPod, overlayPod, false) @@ -596,6 +611,7 @@ var _ = framework.SerialDescribe("[group:underlay]", func() { ginkgo.By("Creating underlay pod " + u2oPodNameUnderlay) underlayPod = podClient.CreateSync(originUnderlayPod) + waitSubnetStatusUpdate(subnetName, subnetClient, 1) subnet = subnetClient.Get(subnetName) checkU2OItems(f, subnet, underlayPod, overlayPod, false) @@ -613,6 +629,7 @@ var _ = framework.SerialDescribe("[group:underlay]", func() { ginkgo.By("Creating underlay pod " + u2oPodNameUnderlay) underlayPod = podClient.CreateSync(originUnderlayPod) + waitSubnetStatusUpdate(subnetName, subnetClient, 2) subnet = subnetClient.Get(subnetName) checkU2OItems(f, subnet, underlayPod, overlayPod, false) @@ -654,6 +671,7 @@ var _ = framework.SerialDescribe("[group:underlay]", func() { ginkgo.By("Creating underlay pod " + u2oPodNameUnderlay) underlayPod = podClient.CreateSync(originUnderlayPod) + waitSubnetStatusUpdate(subnetName, subnetClient, 2) subnet = subnetClient.Get(subnetName) checkU2OItems(f, subnet, underlayPod, overlayPod, false) @@ -694,6 +712,7 @@ var _ = framework.SerialDescribe("[group:underlay]", func() { ginkgo.By("Creating underlay pod " + u2oPodNameUnderlay) underlayPod = podClient.CreateSync(originUnderlayPod) + waitSubnetStatusUpdate(subnetName, subnetClient, 2) subnet = subnetClient.Get(subnetName) checkU2OItems(f, subnet, underlayPod, podOverlayCustomVPC, true) @@ -712,6 +731,7 @@ var _ = framework.SerialDescribe("[group:underlay]", func() { ginkgo.By("Creating underlay pod " + u2oPodNameUnderlay) underlayPod = podClient.CreateSync(originUnderlayPod) + waitSubnetStatusUpdate(subnetName, subnetClient, 2) subnet = subnetClient.Get(subnetName) checkU2OItems(f, subnet, underlayPod, overlayPod, false) @@ -729,6 +749,7 @@ var _ = framework.SerialDescribe("[group:underlay]", func() { ginkgo.By("Creating underlay pod " + u2oPodNameUnderlay) underlayPod = podClient.CreateSync(originUnderlayPod) + waitSubnetStatusUpdate(subnetName, subnetClient, 1) subnet = subnetClient.Get(subnetName) checkU2OItems(f, subnet, underlayPod, overlayPod, false)