mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-02-14 18:09:58 +00:00
Making e2e tests less flaky (#121)
This commit is contained in:
committed by
GitHub
parent
ee6e3aa0df
commit
2af568f0ed
@@ -50,8 +50,10 @@ var _ = Describe("creating a Namespace as Tenant owner with custom --capsule-gro
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
tnt.ResourceVersion = ""
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
tnt.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
@@ -59,16 +61,16 @@ var _ = Describe("creating a Namespace as Tenant owner with custom --capsule-gro
|
||||
It("should fail", func() {
|
||||
args := append(defaulManagerPodArgs, []string{"--capsule-user-group=test"}...)
|
||||
ModifyCapsuleManagerPodArgs(args)
|
||||
CapsuleClusterGroupParamShouldBeUpdated("test", podRecreationTimeoutInterval)
|
||||
CapsuleClusterGroupParam(podRecreationTimeoutInterval).Should(BeIdenticalTo("test"))
|
||||
ns := NewNamespace("cg-namespace-fail")
|
||||
NamespaceCreationShouldNotSucceed(ns, tnt, podRecreationTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, podRecreationTimeoutInterval).ShouldNot(Succeed())
|
||||
})
|
||||
It("should succeed and be available in Tenant namespaces list", func() {
|
||||
ModifyCapsuleManagerPodArgs(defaulManagerPodArgs)
|
||||
CapsuleClusterGroupParamShouldBeUpdated("capsule.clastix.io", podRecreationTimeoutInterval)
|
||||
CapsuleClusterGroupParam(podRecreationTimeoutInterval).Should(BeIdenticalTo("capsule.clastix.io"))
|
||||
ns := NewNamespace("cg-namespace")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, podRecreationTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, podRecreationTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, podRecreationTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
@@ -69,10 +69,14 @@ var _ = Describe("creating a Namespace with --force-tenant-name flag", func() {
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
t1.ResourceVersion = ""
|
||||
t2.ResourceVersion = ""
|
||||
Expect(k8sClient.Create(context.TODO(), t1)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.TODO(), t2)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
t1.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), t1)
|
||||
}).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
t2.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), t2)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), t1)).Should(Succeed())
|
||||
@@ -82,14 +86,14 @@ var _ = Describe("creating a Namespace with --force-tenant-name flag", func() {
|
||||
args := append(defaulManagerPodArgs, []string{"--force-tenant-prefix"}...)
|
||||
ModifyCapsuleManagerPodArgs(args)
|
||||
ns := NewNamespace("test")
|
||||
NamespaceCreationShouldNotSucceed(ns, t1, podRecreationTimeoutInterval)
|
||||
NamespaceCreation(ns, t1, podRecreationTimeoutInterval).ShouldNot(Succeed())
|
||||
})
|
||||
It("should be assigned to the second Tenant", func() {
|
||||
ns := NewNamespace("second-test")
|
||||
ns2 := NewNamespace("second-test2")
|
||||
NamespaceCreationShouldSucceed(ns, t2, podRecreationTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, t2, podRecreationTimeoutInterval)
|
||||
NamespaceCreationShouldNotSucceed(ns2, t1, podRecreationTimeoutInterval)
|
||||
NamespaceCreation(ns, t2, podRecreationTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(t2, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
NamespaceCreation(ns2, t1, podRecreationTimeoutInterval).ShouldNot(Succeed())
|
||||
args := defaulManagerPodArgs
|
||||
ModifyCapsuleManagerPodArgs(args)
|
||||
})
|
||||
|
||||
@@ -58,8 +58,10 @@ var _ = Describe("when Tenant handles Ingress classes", func() {
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
tnt.ResourceVersion = ""
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
tnt.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
@@ -68,8 +70,8 @@ var _ = Describe("when Tenant handles Ingress classes", func() {
|
||||
ns := NewNamespace("ingress-class-disallowed")
|
||||
cs := ownerClient(tnt)
|
||||
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
By("non-specifying the class", func() {
|
||||
Eventually(func() (err error) {
|
||||
@@ -131,8 +133,8 @@ var _ = Describe("when Tenant handles Ingress classes", func() {
|
||||
ns := NewNamespace("ingress-class-allowed-annotation")
|
||||
cs := ownerClient(tnt)
|
||||
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
for _, c := range tnt.Spec.IngressClasses.Allowed {
|
||||
Eventually(func() (err error) {
|
||||
@@ -164,8 +166,8 @@ var _ = Describe("when Tenant handles Ingress classes", func() {
|
||||
Skip("Running test on Kubernetes " + v + ", doesn't provide .spec.ingressClassName")
|
||||
}
|
||||
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
for _, c := range tnt.Spec.IngressClasses.Allowed {
|
||||
Eventually(func() (err error) {
|
||||
@@ -191,8 +193,8 @@ var _ = Describe("when Tenant handles Ingress classes", func() {
|
||||
cs := ownerClient(tnt)
|
||||
ingressClass := "oil-ingress"
|
||||
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
Eventually(func() (err error) {
|
||||
i := &extensionsv1beta1.Ingress{
|
||||
@@ -222,12 +224,9 @@ var _ = Describe("when Tenant handles Ingress classes", func() {
|
||||
if maj == 1 && min < 18 {
|
||||
Skip("Running test on Kubernetes " + v + ", doesn't provide .spec.ingressClassName")
|
||||
}
|
||||
if maj == 1 && min < 18 {
|
||||
Skip("Running test ont Kubernetes " + v + ", doesn't provide .spec.ingressClassName")
|
||||
}
|
||||
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
Eventually(func() (err error) {
|
||||
i := &extensionsv1beta1.Ingress{
|
||||
@@ -244,6 +243,6 @@ var _ = Describe("when Tenant handles Ingress classes", func() {
|
||||
}
|
||||
_, err = cs.ExtensionsV1beta1().Ingresses(ns.GetName()).Create(context.TODO(), i, metav1.CreateOptions{})
|
||||
return
|
||||
}, defaultTimeoutInterval, defaultPollInterval).Should(Succeed())
|
||||
}, 600, defaultPollInterval).Should(Succeed())
|
||||
})
|
||||
})
|
||||
|
||||
@@ -60,15 +60,17 @@ var _ = Describe("creating a Namespace for a Tenant with additional metadata", f
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
})
|
||||
It("should contains additional Namespace metadata", func() {
|
||||
ns := NewNamespace("namespace-metadata")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: ns.GetName()}, ns)).Should(Succeed())
|
||||
By("checking additional labels", func() {
|
||||
|
||||
@@ -50,14 +50,16 @@ var _ = Describe("creating a Namespace as Tenant owner", func() {
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
})
|
||||
It("should be available in Tenant namespaces list", func() {
|
||||
ns := NewNamespace("new-namespace")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -50,7 +50,9 @@ var _ = Describe("creating a Namespace over-quota", func() {
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
@@ -59,8 +61,8 @@ var _ = Describe("creating a Namespace over-quota", func() {
|
||||
By("creating three Namespaces", func() {
|
||||
for _, name := range []string{"bob-dev", "bob-staging", "bob-production"} {
|
||||
ns := NewNamespace(name)
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -101,8 +101,10 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() {
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
tnt.ResourceVersion = ""
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
tnt.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
@@ -110,8 +112,8 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() {
|
||||
It("should disallow deletions", func() {
|
||||
By("blocking Capsule Limit ranges", func() {
|
||||
ns := NewNamespace("limit-range-disallow")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
lr := &corev1.LimitRange{}
|
||||
Eventually(func() error {
|
||||
@@ -124,8 +126,8 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() {
|
||||
})
|
||||
By("blocking Capsule Network Policy", func() {
|
||||
ns := NewNamespace("network-policy-disallow")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
np := &networkingv1.NetworkPolicy{}
|
||||
Eventually(func() error {
|
||||
@@ -138,8 +140,8 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() {
|
||||
})
|
||||
By("blocking blocking Capsule Resource Quota", func() {
|
||||
ns := NewNamespace("resource-quota-disallow")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
rq := &corev1.ResourceQuota{}
|
||||
Eventually(func() error {
|
||||
@@ -154,8 +156,8 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() {
|
||||
It("should allow listing", func() {
|
||||
By("Limit Range resources", func() {
|
||||
ns := NewNamespace("limit-range-list")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
Eventually(func() (err error) {
|
||||
cs := ownerClient(tnt)
|
||||
@@ -165,8 +167,8 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() {
|
||||
})
|
||||
By("Network Policy resources", func() {
|
||||
ns := NewNamespace("network-policy-list")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
Eventually(func() (err error) {
|
||||
cs := ownerClient(tnt)
|
||||
@@ -176,8 +178,8 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() {
|
||||
})
|
||||
By("Resource Quota resources", func() {
|
||||
ns := NewNamespace("resource-quota-list")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
Eventually(func() (err error) {
|
||||
cs := ownerClient(tnt)
|
||||
@@ -188,8 +190,8 @@ var _ = Describe("when Tenant owner interacts with the webhooks", func() {
|
||||
})
|
||||
It("should allow all actions to Tenant owner Network Policy resources", func() {
|
||||
ns := NewNamespace("network-policy-allow")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
cs := ownerClient(tnt)
|
||||
np := &networkingv1.NetworkPolicy{
|
||||
|
||||
@@ -50,8 +50,10 @@ var _ = Describe("creating a Namespace with --protected-namespace-regex enabled"
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
tnt.ResourceVersion = ""
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
tnt.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
@@ -60,12 +62,12 @@ var _ = Describe("creating a Namespace with --protected-namespace-regex enabled"
|
||||
args := append(defaulManagerPodArgs, []string{"--protected-namespace-regex=^.*[-.]system$"}...)
|
||||
ModifyCapsuleManagerPodArgs(args)
|
||||
ns := NewNamespace("test-ok")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, podRecreationTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, podRecreationTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, podRecreationTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
})
|
||||
It("should fail", func() {
|
||||
ns := NewNamespace("test-system")
|
||||
NamespaceCreationShouldNotSucceed(ns, tnt, podRecreationTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, podRecreationTimeoutInterval).ShouldNot(Succeed())
|
||||
ModifyCapsuleManagerPodArgs(defaulManagerPodArgs)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -125,13 +125,15 @@ var _ = Describe("exceeding Tenant resource quota", func() {
|
||||
}
|
||||
nsl := []string{"easy", "peasy"}
|
||||
JustBeforeEach(func() {
|
||||
tnt.ResourceVersion = ""
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
tnt.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
By("creating the Namespaces", func() {
|
||||
for _, i := range nsl {
|
||||
ns := NewNamespace(i)
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -50,7 +50,9 @@ var _ = Describe("creating a Namespace trying to select a third Tenant", func()
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
|
||||
@@ -111,16 +111,16 @@ var _ = Describe("creating a Namespace without a Tenant selector when user owns
|
||||
By("user owns 2 tenants", func() {
|
||||
Expect(k8sClient.Create(context.TODO(), t1)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.TODO(), t2)).Should(Succeed())
|
||||
NamespaceCreationShouldNotSucceed(ns, t1, defaultTimeoutInterval)
|
||||
NamespaceCreationShouldNotSucceed(ns, t2, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, t1, defaultTimeoutInterval).ShouldNot(Succeed())
|
||||
NamespaceCreation(ns, t2, defaultTimeoutInterval).ShouldNot(Succeed())
|
||||
Expect(k8sClient.Delete(context.TODO(), t1)).Should(Succeed())
|
||||
Expect(k8sClient.Delete(context.TODO(), t2)).Should(Succeed())
|
||||
})
|
||||
By("group owns 2 tenants", func() {
|
||||
Expect(k8sClient.Create(context.TODO(), t3)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.TODO(), t4)).Should(Succeed())
|
||||
NamespaceCreationShouldNotSucceed(ns, t3, defaultTimeoutInterval)
|
||||
NamespaceCreationShouldNotSucceed(ns, t4, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, t3, defaultTimeoutInterval).ShouldNot(Succeed())
|
||||
NamespaceCreation(ns, t4, defaultTimeoutInterval).ShouldNot(Succeed())
|
||||
Expect(k8sClient.Delete(context.TODO(), t3)).Should(Succeed())
|
||||
Expect(k8sClient.Delete(context.TODO(), t4)).Should(Succeed())
|
||||
})
|
||||
@@ -130,10 +130,10 @@ var _ = Describe("creating a Namespace without a Tenant selector when user owns
|
||||
Expect(k8sClient.Create(context.TODO(), t2)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.TODO(), t3)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.TODO(), t4)).Should(Succeed())
|
||||
NamespaceCreationShouldNotSucceed(ns, t1, defaultTimeoutInterval)
|
||||
NamespaceCreationShouldNotSucceed(ns, t2, defaultTimeoutInterval)
|
||||
NamespaceCreationShouldNotSucceed(ns, t3, defaultTimeoutInterval)
|
||||
NamespaceCreationShouldNotSucceed(ns, t4, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, t1, defaultTimeoutInterval).ShouldNot(Succeed())
|
||||
NamespaceCreation(ns, t2, defaultTimeoutInterval).ShouldNot(Succeed())
|
||||
NamespaceCreation(ns, t3, defaultTimeoutInterval).ShouldNot(Succeed())
|
||||
NamespaceCreation(ns, t4, defaultTimeoutInterval).ShouldNot(Succeed())
|
||||
Expect(k8sClient.Delete(context.TODO(), t1)).Should(Succeed())
|
||||
Expect(k8sClient.Delete(context.TODO(), t2)).Should(Succeed())
|
||||
Expect(k8sClient.Delete(context.TODO(), t3)).Should(Succeed())
|
||||
|
||||
@@ -69,8 +69,12 @@ var _ = Describe("creating a Namespace with Tenant selector when user owns multi
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
Expect(k8sClient.Create(context.TODO(), t1)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.TODO(), t2)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
return k8sClient.Create(context.TODO(), t1)
|
||||
}).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
return k8sClient.Create(context.TODO(), t2)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), t1)).Should(Succeed())
|
||||
@@ -85,7 +89,7 @@ var _ = Describe("creating a Namespace with Tenant selector when user owns multi
|
||||
l: t2.Name,
|
||||
}
|
||||
})
|
||||
NamespaceCreationShouldSucceed(ns, t2, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, t2, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, t2, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(t2, defaultTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -76,8 +76,12 @@ var _ = Describe("creating a Service/Endpoint/EndpointSlice for a Tenant with ad
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
Expect(k8sClient.Create(context.TODO(), epsCR)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
return k8sClient.Create(context.TODO(), epsCR)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
@@ -85,8 +89,8 @@ var _ = Describe("creating a Service/Endpoint/EndpointSlice for a Tenant with ad
|
||||
})
|
||||
It("service objects should contain additional metadata", func() {
|
||||
ns := NewNamespace("serivce-metadata")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
meta := metav1.ObjectMeta{
|
||||
Name: "test-svc",
|
||||
|
||||
@@ -57,16 +57,18 @@ var _ = Describe("when Tenant handles Storage classes", func() {
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
tnt.ResourceVersion = ""
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
tnt.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
})
|
||||
It("should block non allowed Storage Class", func() {
|
||||
ns := NewNamespace("storage-class-disallowed")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
|
||||
By("non-specifying the class", func() {
|
||||
Eventually(func() (err error) {
|
||||
@@ -113,8 +115,8 @@ var _ = Describe("when Tenant handles Storage classes", func() {
|
||||
ns := NewNamespace("storage-class-allowed")
|
||||
cs := ownerClient(tnt)
|
||||
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
By("using allowed storageClass names", func() {
|
||||
for _, c := range tnt.Spec.StorageClasses.Allowed {
|
||||
Eventually(func() (err error) {
|
||||
|
||||
@@ -50,16 +50,18 @@ var _ = Describe("creating a Namespace with group Tenant owner", func() {
|
||||
},
|
||||
}
|
||||
JustBeforeEach(func() {
|
||||
tnt.ResourceVersion = ""
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
tnt.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
})
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.TODO(), tnt)).Should(Succeed())
|
||||
})
|
||||
It("should succeed and be available in Tenant namespaces list", func() {
|
||||
ns := NewNamespace("gto-namespace")
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
GroupShouldBeUsedInTenantRoleBinding(ns, tnt, defaultTimeoutInterval)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -168,13 +168,15 @@ var _ = Describe("changing Tenant managed Kubernetes resources", func() {
|
||||
}
|
||||
nsl := []string{"fire", "walk", "with", "me"}
|
||||
JustBeforeEach(func() {
|
||||
tnt.ResourceVersion = ""
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
EventuallyCreation(func() error {
|
||||
tnt.ResourceVersion = ""
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
By("creating the Namespaces", func() {
|
||||
for _, i := range nsl {
|
||||
ns := NewNamespace(i)
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -169,14 +169,14 @@ var _ = Describe("creating namespaces within a Tenant with resources", func() {
|
||||
}
|
||||
nsl := []string{"bim", "bum", "bam"}
|
||||
JustBeforeEach(func() {
|
||||
tnt.ResourceVersion = ""
|
||||
Expect(k8sClient.Create(context.TODO(), tnt)).Should(Succeed())
|
||||
|
||||
EventuallyCreation(func() error {
|
||||
return k8sClient.Create(context.TODO(), tnt)
|
||||
}).Should(Succeed())
|
||||
By("creating the Namespaces", func() {
|
||||
for _, i := range nsl {
|
||||
ns := NewNamespace(i)
|
||||
NamespaceCreationShouldSucceed(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceShouldBeManagedByTenant(ns, tnt, defaultTimeoutInterval)
|
||||
NamespaceCreation(ns, tnt, defaultTimeoutInterval).Should(Succeed())
|
||||
TenantNamespaceList(tnt, podRecreationTimeoutInterval).Should(ContainElement(ns.GetName()))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -38,7 +38,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultTimeoutInterval = 15 * time.Second
|
||||
defaultTimeoutInterval = 20 * time.Second
|
||||
podRecreationTimeoutInterval = 90 * time.Second
|
||||
defaultPollInterval = time.Second
|
||||
)
|
||||
@@ -51,37 +51,32 @@ func NewNamespace(name string) *corev1.Namespace {
|
||||
}
|
||||
}
|
||||
|
||||
func NamespaceCreationShouldSucceed(ns *corev1.Namespace, t *v1alpha1.Tenant, timeout time.Duration) {
|
||||
func NamespaceCreation(ns *corev1.Namespace, t *v1alpha1.Tenant, timeout time.Duration) AsyncAssertion {
|
||||
cs := ownerClient(t)
|
||||
Eventually(func() (err error) {
|
||||
return Eventually(func() (err error) {
|
||||
_, err = cs.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{})
|
||||
return
|
||||
}, timeout, defaultPollInterval).Should(Succeed())
|
||||
}, timeout, defaultPollInterval)
|
||||
}
|
||||
|
||||
func NamespaceCreationShouldNotSucceed(ns *corev1.Namespace, t *v1alpha1.Tenant, timeout time.Duration) {
|
||||
cs := ownerClient(t)
|
||||
Eventually(func() (err error) {
|
||||
_, err = cs.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{})
|
||||
return
|
||||
}, timeout, defaultPollInterval).ShouldNot(Succeed())
|
||||
}
|
||||
|
||||
func NamespaceShouldBeManagedByTenant(ns *corev1.Namespace, t *v1alpha1.Tenant, timeout time.Duration) {
|
||||
Eventually(func() v1alpha1.NamespaceList {
|
||||
func TenantNamespaceList(t *v1alpha1.Tenant, timeout time.Duration) AsyncAssertion {
|
||||
return Eventually(func() v1alpha1.NamespaceList {
|
||||
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: t.GetName()}, t)).Should(Succeed())
|
||||
return t.Status.Namespaces
|
||||
}, timeout, defaultPollInterval).Should(ContainElement(ns.GetName()))
|
||||
}, timeout, defaultPollInterval)
|
||||
}
|
||||
|
||||
func CapsuleClusterGroupParamShouldBeUpdated(capsuleClusterGroup string, timeout time.Duration) {
|
||||
func EventuallyCreation(f interface{}) AsyncAssertion {
|
||||
return Eventually(f, defaultTimeoutInterval, defaultPollInterval)
|
||||
}
|
||||
|
||||
func CapsuleClusterGroupParam(timeout time.Duration) AsyncAssertion {
|
||||
capsuleCRB := &rbacv1.ClusterRoleBinding{}
|
||||
|
||||
Eventually(func() string {
|
||||
return Eventually(func() string {
|
||||
Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: rbac.ProvisionerRoleName}, capsuleCRB)).Should(Succeed())
|
||||
return capsuleCRB.Subjects[0].Name
|
||||
}, timeout, defaultPollInterval).Should(BeIdenticalTo(capsuleClusterGroup))
|
||||
|
||||
}, timeout, defaultPollInterval)
|
||||
}
|
||||
|
||||
func ModifyCapsuleManagerPodArgs(args []string) {
|
||||
|
||||
Reference in New Issue
Block a user