Skip to content

Bug 1833426: Update Webhook E2E Namespace Labels #1515

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

Merged
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
41 changes: 20 additions & 21 deletions test/e2e/webhook_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,42 @@ var _ = Describe("CSVs with a Webhook", func() {
var crc versioned.Interface
var namespace *corev1.Namespace
var nsCleanupFunc cleanupFunc
var nsLabels map[string]string
BeforeEach(func() {
c = newKubeClient(GinkgoT())
crc = newCRClient(GinkgoT())
namespace, nsCleanupFunc = newNamespace(GinkgoT(), c, genName("webhook-test-"))
nsLabels = map[string]string{
"foo": "bar",
}
namespace = &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: genName("webhook-test-"),
Labels: nsLabels,
},
}

var err error
namespace, err = c.KubernetesInterface().CoreV1().Namespaces().Create(context.TODO(), namespace, metav1.CreateOptions{})
Expect(err).Should(BeNil())
Expect(namespace).ShouldNot(BeNil())

nsCleanupFunc = func() {
err := c.KubernetesInterface().CoreV1().Namespaces().Delete(context.TODO(), namespace.GetName(), metav1.DeleteOptions{})
Expect(err).Should(BeNil())
}
})
AfterEach(func() {
if nsCleanupFunc != nil {
Copy link
Member

Choose a reason for hiding this comment

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

should this ever be nil?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should not - but it prevents a potential nil pointer problem. It might be worth changing the if statement to Expect(nsCleanupFunc).ShouldNot(BeNil())

nsCleanupFunc()
}
})
When("Installed in an OperatorGroup that defines a selector", func() {
var nsLabels map[string]string
var cleanupCSV cleanupFunc
var ogSelector *metav1.LabelSelector
BeforeEach(func() {
nsLabels = map[string]string{
"foo": "bar",
}
ogSelector = &metav1.LabelSelector{
MatchLabels: nsLabels,
}
// Add a label to the namespace
Eventually(func() error {
var err error
namespace, err = c.KubernetesInterface().CoreV1().Namespaces().Get(context.TODO(), namespace.Name, metav1.GetOptions{})
if err != nil {
return err
}

if namespace.GetLabels() == nil {
namespace.SetLabels(map[string]string{})
}
namespace.Labels["foo"] = "bar"

c.KubernetesInterface().CoreV1().Namespaces().Update(context.TODO(), namespace, metav1.UpdateOptions{})
return err
}, time.Minute, 5*time.Second).Should(Succeed())

og := newOperatorGroup(namespace.Name, genName("selector-og-"), nil, ogSelector, nil, false)
_, err := crc.OperatorsV1().OperatorGroups(namespace.Name).Create(context.TODO(), og, metav1.CreateOptions{})
Expand Down