Skip to content

Commit

Permalink
add WaitUntil check for ns (#4695)
Browse files Browse the repository at this point in the history
Signed-off-by: 马洪贞 <[email protected]>
  • Loading branch information
hongzhen-ma authored Nov 5, 2024
1 parent e4d1d38 commit 451a463
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions test/e2e/kube-ovn/subnet/subnet-selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ var _ = framework.Describe("[group:subnet]", func() {
subnet = subnetClient.PatchSync(subnet, modifiedSubnet)

checkNs2 := nsClient.Get(ns2Name)
framework.ExpectHaveKeyWithValue(checkNs2.Annotations, util.LogicalSwitchAnnotation, subnet.Name)
framework.WaitUntil(time.Second, 30*time.Second, func(_ context.Context) (bool, error) {
checkNs2 = nsClient.Get(ns2Name)
if checkNs2.Annotations[util.LogicalSwitchAnnotation] == subnet.Name {
return true, nil
}
return false, nil
}, fmt.Sprintf("failed to update annotation for ns %s", checkNs2.Name))

// 3. delete namespaceSelector
ginkgo.By("Delete subnet namespaceSelector matched with namespace " + ns2Name + ", should delete annotation with subnet " + subnet.Name)
Expand All @@ -99,8 +105,13 @@ var _ = framework.Describe("[group:subnet]", func() {
subnet = subnetClient.PatchSync(subnet, modifiedSubnet)

checkNs2 = nsClient.Get(ns2Name)
lsAnnotation := checkNs2.Annotations[util.LogicalSwitchAnnotation]
framework.ExpectNotEqual(lsAnnotation, subnet.Name)
framework.WaitUntil(time.Second, 30*time.Second, func(_ context.Context) (bool, error) {
checkNs2 = nsClient.Get(ns2Name)
if checkNs2.Annotations[util.LogicalSwitchAnnotation] != subnet.Name {
return true, nil
}
return false, nil
}, fmt.Sprintf("failed to update annotation for ns %s", checkNs2.Name))
})

framework.ConformanceIt("create subnet with namespaceSelector, update namespaces to match with selector", func() {
Expand All @@ -127,7 +138,6 @@ var _ = framework.Describe("[group:subnet]", func() {
}
return false, nil
}, fmt.Sprintf("failed to update annotation for ns %s", checkNs3.Name))
framework.ExpectHaveKeyWithValue(checkNs3.Annotations, util.LogicalSwitchAnnotation, subnet.Name)

// 3. delete labels matched witch subnet namespaceSelector
ginkgo.By("Delete labels for namespace " + ns3Name + ", should not annotate with subnet " + subnet.Name)
Expand All @@ -142,8 +152,6 @@ var _ = framework.Describe("[group:subnet]", func() {
}
return false, nil
}, fmt.Sprintf("failed to update annotation for ns %s", checkNs3.Name))
lsAnnotation = checkNs3.Annotations[util.LogicalSwitchAnnotation]
framework.ExpectNotEqual(lsAnnotation, subnet.Name)
})

framework.ConformanceIt("update namespace with labelSelector, and set subnet spec namespaces with selected namespace", func() {
Expand All @@ -153,7 +161,13 @@ var _ = framework.Describe("[group:subnet]", func() {
modifiedSubnet.Spec.Namespaces = append(modifiedSubnet.Spec.Namespaces, ns2Name)
subnet = subnetClient.PatchSync(subnet, modifiedSubnet)
checkNs2 := nsClient.Get(ns2Name)
framework.ExpectHaveKeyWithValue(checkNs2.Annotations, util.LogicalSwitchAnnotation, subnet.Name)
framework.WaitUntil(time.Second, 30*time.Second, func(_ context.Context) (bool, error) {
checkNs2 = nsClient.Get(ns2Name)
if checkNs2.Annotations[util.LogicalSwitchAnnotation] == subnet.Name {
return true, nil
}
return false, nil
}, fmt.Sprintf("failed to update annotation for ns %s", checkNs2.Name))

// 2. add namespaceSelector for subnet, which select with ns2
ginkgo.By("Add subnet namespaceSelector matched with " + ns2Name + ", should update annotation with subnet " + subnet.Name)
Expand All @@ -176,6 +190,7 @@ var _ = framework.Describe("[group:subnet]", func() {
modifiedSubnet.Spec.NamespaceSelectors = []metav1.LabelSelector{ns1Selector}
subnet = subnetClient.PatchSync(subnet, modifiedSubnet)

ginkgo.By("Check namespace " + ns2Name + " to annotate with subnet " + subnet.Name)
checkNs2 = nsClient.Get(ns2Name)
framework.ExpectHaveKeyWithValue(checkNs2.Annotations, util.LogicalSwitchAnnotation, subnet.Name)

Expand All @@ -194,6 +209,8 @@ var _ = framework.Describe("[group:subnet]", func() {
modifiedSubnet = subnet.DeepCopy()
modifiedSubnet.Spec.Namespaces = []string{}
subnet = subnetClient.PatchSync(subnet, modifiedSubnet)

ginkgo.By("Check namespace " + ns2Name + " to annotate with subnet " + subnet.Name)
checkNs2 = nsClient.Get(ns2Name)
framework.ExpectHaveKeyWithValue(checkNs2.Annotations, util.LogicalSwitchAnnotation, subnet.Name)

Expand All @@ -204,7 +221,12 @@ var _ = framework.Describe("[group:subnet]", func() {
subnet = subnetClient.PatchSync(subnet, modifiedSubnet)

checkNs2 = nsClient.Get(ns2Name)
lsAnnotation := checkNs2.Annotations[util.LogicalSwitchAnnotation]
framework.ExpectNotEqual(lsAnnotation, subnet.Name)
framework.WaitUntil(time.Second, 30*time.Second, func(_ context.Context) (bool, error) {
checkNs2 = nsClient.Get(ns2Name)
if checkNs2.Annotations[util.LogicalSwitchAnnotation] != subnet.Name {
return true, nil
}
return false, nil
}, fmt.Sprintf("failed to update annotation for ns %s", checkNs2.Name))
})
})

0 comments on commit 451a463

Please sign in to comment.