Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for the UDN namespaces to have SA's created #29522

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 26 additions & 76 deletions test/extended/networking/network_segmentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,8 @@ var _ = Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Feature:User
f.Namespace = ns
By("Creating second namespace for default network pods")
defaultNetNamespace := f.Namespace.Name + "-default"
_, err = cs.CoreV1().Namespaces().Create(context.Background(), &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: defaultNetNamespace,
},
}, metav1.CreateOptions{})
_, err = f.CreateNamespace(context.TODO(), defaultNetNamespace, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question @tssurya: don't we need to err = udnWaitForOpenShift(oc, namespace) here ?

Copy link
Contributor Author

@tssurya tssurya Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because that namespaces isn't a UDN namespace... unsure if that udnWaitForOCP is doing generic things or not.
but on a high level - it does make to add this wait also for the non UDN namespaces huh? i had thought of adding it for the default namespaces as well.. maybe we should like you are saying

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure ...

Expect(err).NotTo(HaveOccurred())
defer func() {
Expect(cs.CoreV1().Namespaces().Delete(context.Background(), defaultNetNamespace, metav1.DeleteOptions{})).To(Succeed())
}()

By("creating the network")
netConfigParams.namespace = f.Namespace.Name
Expand Down Expand Up @@ -501,21 +494,10 @@ var _ = Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Feature:User

for _, namespace := range []string{namespaceRed, namespaceBlue} {
By("Creating namespace " + namespace)
_, err := cs.CoreV1().Namespaces().Create(context.Background(), &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
Labels: l,
},
}, metav1.CreateOptions{})
_, err := f.CreateNamespace(context.TODO(), namespace, l)
Expect(err).NotTo(HaveOccurred())
err = udnWaitForOpenShift(oc, namespace)
Expect(err).NotTo(HaveOccurred())
defer func() {
By("Removing namespace " + namespace)
Expect(cs.CoreV1().Namespaces().Delete(
context.Background(),
namespace,
metav1.DeleteOptions{},
)).To(Succeed())
}()
}
networkNamespaceMap := map[string]string{namespaceRed: red, namespaceBlue: blue}
for namespace, network := range networkNamespaceMap {
Expand Down Expand Up @@ -835,7 +817,7 @@ var _ = Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Feature:User
const clusterUserDefinedNetworkResource = "clusteruserdefinednetwork"

var testTenantNamespaces []string
var defaultNetNamespace *v1.Namespace
var defaultNetNamespace string

BeforeEach(func() {
namespace, err := f.CreateNamespace(context.TODO(), f.BaseName, map[string]string{
Expand All @@ -853,27 +835,17 @@ var _ = Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Feature:User

By("Creating test tenants namespaces")
for _, nsName := range testTenantNamespaces {
_, err := cs.CoreV1().Namespaces().Create(context.Background(), &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: nsName,
Labels: map[string]string{RequiredUDNNamespaceLabel: ""},
}}, metav1.CreateOptions{})
l := map[string]string{RequiredUDNNamespaceLabel: ""}
_, err := f.CreateNamespace(context.TODO(), nsName, l)
Expect(err).NotTo(HaveOccurred())
err = udnWaitForOpenShift(oc, nsName)
Expect(err).NotTo(HaveOccurred())
DeferCleanup(func() error {
err := cs.CoreV1().Namespaces().Delete(context.Background(), nsName, metav1.DeleteOptions{})
return err
})
}
// default cluster network namespace, for use when only testing secondary UDNs/NADs
defaultNetNamespace = &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: f.Namespace.Name + "-default",
},
}
f.AddNamespacesToDelete(defaultNetNamespace)
_, err = cs.CoreV1().Namespaces().Create(context.Background(), defaultNetNamespace, metav1.CreateOptions{})
defaultNetNamespace = f.Namespace.Name + "-default"
_, err = f.CreateNamespace(context.TODO(), defaultNetNamespace, nil)
Expect(err).NotTo(HaveOccurred())
testTenantNamespaces = append(testTenantNamespaces, defaultNetNamespace.Name)
testTenantNamespaces = append(testTenantNamespaces, defaultNetNamespace)
})

var testClusterUdnName string
Expand Down Expand Up @@ -938,16 +910,11 @@ var _ = Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Feature:User
1*time.Minute, 3*time.Second).Should(Succeed())

By("create the new target namespace")
_, err = cs.CoreV1().Namespaces().Create(context.Background(), &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testNewNs,
Labels: map[string]string{RequiredUDNNamespaceLabel: ""},
}}, metav1.CreateOptions{})
l := map[string]string{RequiredUDNNamespaceLabel: ""}
_, err = f.CreateNamespace(context.TODO(), testNewNs, l)
Expect(err).NotTo(HaveOccurred())
err = udnWaitForOpenShift(oc, testNewNs)
Expect(err).NotTo(HaveOccurred())
DeferCleanup(func() error {
err := cs.CoreV1().Namespaces().Delete(context.Background(), testNewNs, metav1.DeleteOptions{})
return err
})

expectedActiveNamespaces := append(testTenantNamespaces, testNewNs)
Eventually(
Expand All @@ -967,16 +934,11 @@ var _ = Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Feature:User
testNewNs := f.Namespace.Name + "green"

By("create new namespace")
_, err := cs.CoreV1().Namespaces().Create(context.Background(), &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testNewNs,
Labels: map[string]string{RequiredUDNNamespaceLabel: ""},
}}, metav1.CreateOptions{})
l := map[string]string{RequiredUDNNamespaceLabel: ""}
_, err := f.CreateNamespace(context.TODO(), testNewNs, l)
Expect(err).NotTo(HaveOccurred())
err = udnWaitForOpenShift(oc, testNewNs)
Expect(err).NotTo(HaveOccurred())
DeferCleanup(func() error {
err := cs.CoreV1().Namespaces().Delete(context.Background(), testNewNs, metav1.DeleteOptions{})
return err
})

By("add new namespace to CR namespace-selector")
patch := fmt.Sprintf(`[{"op": "add", "path": "./spec/namespaceSelector/matchExpressions/0/values/-", "value": "%s"}]`, testNewNs)
Expand Down Expand Up @@ -1031,7 +993,7 @@ var _ = Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Feature:User
)

BeforeEach(func() {
inUseNetTestTenantNamespace = defaultNetNamespace.Name
inUseNetTestTenantNamespace = defaultNetNamespace

By("create pod in one of the test tenant namespaces")
networkAttachments := []nadapi.NetworkSelectionElement{
Expand Down Expand Up @@ -1101,16 +1063,11 @@ var _ = Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Feature:User
}
By("Creating test tenants namespaces")
for _, nsName := range testTenantNamespaces {
_, err := cs.CoreV1().Namespaces().Create(context.Background(), &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: nsName,
Labels: map[string]string{RequiredUDNNamespaceLabel: ""},
}}, metav1.CreateOptions{})
l := map[string]string{RequiredUDNNamespaceLabel: ""}
_, err = f.CreateNamespace(context.TODO(), nsName, l)
Expect(err).NotTo(HaveOccurred())
err = udnWaitForOpenShift(oc, nsName)
Expect(err).NotTo(HaveOccurred())
DeferCleanup(func() error {
err := cs.CoreV1().Namespaces().Delete(context.Background(), nsName, metav1.DeleteOptions{})
return err
})
}

By("create primary network NAD in one of the tenant namespaces")
Expand Down Expand Up @@ -1193,15 +1150,8 @@ var _ = Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Feature:User
It("should react to k8s.ovn.org/open-default-ports annotations changes", func() {
By("Creating second namespace for default network pod")
defaultNetNamespace := f.Namespace.Name + "-default"
_, err := cs.CoreV1().Namespaces().Create(context.Background(), &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: defaultNetNamespace,
},
}, metav1.CreateOptions{})
_, err := f.CreateNamespace(context.TODO(), defaultNetNamespace, nil)
Expect(err).NotTo(HaveOccurred())
defer func() {
Expect(cs.CoreV1().Namespaces().Delete(context.Background(), defaultNetNamespace, metav1.DeleteOptions{})).To(Succeed())
}()

By("creating default network client pod")
defaultClientPod := frameworkpod.CreateExecPodOrFail(
Expand Down
11 changes: 4 additions & 7 deletions test/extended/networking/network_segmentation_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,11 @@ var _ = ginkgo.Describe("[sig-network][OCPFeatureGate:NetworkSegmentation][Featu
namespaceBlue := getNamespaceName(f, namespaceBlueSuffix)
for _, namespace := range []string{namespaceYellow, namespaceBlue} {
ginkgo.By("Creating namespace " + namespace)
ns, err := cs.CoreV1().Namespaces().Create(context.Background(), &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
Labels: map[string]string{RequiredUDNNamespaceLabel: ""},
},
}, metav1.CreateOptions{})
l := map[string]string{RequiredUDNNamespaceLabel: ""}
_, err := f.CreateNamespace(context.TODO(), namespace, l)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
err = udnWaitForOpenShift(oc, namespace)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
f.AddNamespacesToDelete(ns)
}
})

Expand Down