Skip to content

Commit

Permalink
some fixes in e2e (#3116)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian authored Aug 7, 2023
1 parent d8fa839 commit 02f8c63
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/framework/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
type DaemonSetClient struct {
f *Framework
v1apps.DaemonSetInterface
namespace string
}

func (f *Framework) DaemonSetClient() *DaemonSetClient {
Expand All @@ -32,6 +33,7 @@ func (f *Framework) DaemonSetClientNS(namespace string) *DaemonSetClient {
return &DaemonSetClient{
f: f,
DaemonSetInterface: f.ClientSet.AppsV1().DaemonSets(namespace),
namespace: namespace,
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/e2e/framework/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
type DeploymentClient struct {
f *Framework
v1apps.DeploymentInterface
namespace string
}

func (f *Framework) DeploymentClient() *DeploymentClient {
Expand All @@ -39,6 +40,7 @@ func (f *Framework) DeploymentClientNS(namespace string) *DeploymentClient {
return &DeploymentClient{
f: f,
DeploymentInterface: f.ClientSet.AppsV1().Deployments(namespace),
namespace: namespace,
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/e2e/framework/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
type EndpointsClient struct {
f *Framework
v1core.EndpointsInterface
namespace string
}

func (f *Framework) EndpointClient() *EndpointsClient {
Expand All @@ -31,6 +32,7 @@ func (f *Framework) EndpointsClientNS(namespace string) *EndpointsClient {
return &EndpointsClient{
f: f,
EndpointsInterface: f.ClientSet.CoreV1().Endpoints(namespace),
namespace: namespace,
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/e2e/framework/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
type EventClient struct {
f *Framework
typedcorev1.EventInterface
namespace string
}

func (f *Framework) EventClient() *EventClient {
Expand All @@ -23,14 +24,15 @@ func (f *Framework) EventClientNS(namespace string) *EventClient {
return &EventClient{
f: f,
EventInterface: f.ClientSet.CoreV1().Events(namespace),
namespace: namespace,
}
}

// WaitToHaveEvent waits the provided resource to have the specified event(s)
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,
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/framework/network-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type NetworkPolicyClient struct {
f *Framework
v1net.NetworkPolicyInterface
namespace string
}

func (f *Framework) NetworkPolicyClient() *NetworkPolicyClient {
Expand All @@ -28,6 +29,7 @@ func (f *Framework) NetworkPolicyClientNS(namespace string) *NetworkPolicyClient
return &NetworkPolicyClient{
f: f,
NetworkPolicyInterface: f.ClientSet.NetworkingV1().NetworkPolicies(namespace),
namespace: namespace,
}
}

Expand Down
7 changes: 4 additions & 3 deletions test/e2e/framework/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import (
type PodClient struct {
f *Framework
*e2epod.PodClient
namespace string
}

func (f *Framework) PodClient() *PodClient {
return f.PodClientNS(f.Namespace.Name)
}

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 {
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 2 additions & 0 deletions test/e2e/framework/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
type ServiceClient struct {
f *Framework
v1core.ServiceInterface
namespace string
}

func (f *Framework) ServiceClient() *ServiceClient {
Expand All @@ -33,6 +34,7 @@ func (f *Framework) ServiceClientNS(namespace string) *ServiceClient {
return &ServiceClient{
f: f,
ServiceInterface: f.ClientSet.CoreV1().Services(namespace),
namespace: namespace,
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/e2e/framework/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
type StatefulSetClient struct {
f *Framework
v1apps.StatefulSetInterface
namespace string
}

func (f *Framework) StatefulSetClient() *StatefulSetClient {
Expand All @@ -29,6 +30,7 @@ func (f *Framework) StatefulSetClientNS(namespace string) *StatefulSetClient {
return &StatefulSetClient{
f: f,
StatefulSetInterface: f.ClientSet.AppsV1().StatefulSets(namespace),
namespace: namespace,
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/e2e/framework/switch-lb-rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
type SwitchLBRuleClient struct {
f *Framework
v1.SwitchLBRuleInterface
namespace string
}

func (f *Framework) SwitchLBRuleClient() *SwitchLBRuleClient {
Expand All @@ -33,6 +34,7 @@ func (f *Framework) SwitchLBRuleClientNS(namespace string) *SwitchLBRuleClient {
return &SwitchLBRuleClient{
f: f,
SwitchLBRuleInterface: f.KubeOVNClientSet.KubeovnV1().SwitchLBRules(),
namespace: namespace,
}
}

Expand Down
9 changes: 5 additions & 4 deletions test/e2e/kube-ovn/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,20 +1032,20 @@ 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
}
}
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
}
Expand Down Expand Up @@ -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")

Expand Down
21 changes: 21 additions & 0 deletions test/e2e/kube-ovn/underlay/underlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 02f8c63

Please sign in to comment.