-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): Add forceTenantPrefix option to Tenant spec (#1244)
Signed-off-by: samir-tahir <[email protected]>
- Loading branch information
1 parent
462ff47
commit da66f40
Showing
7 changed files
with
209 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
//go:build e2e | ||
|
||
// Copyright 2020-2023 Project Capsule Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
capsulev1beta2 "github.com/projectcapsule/capsule/api/v1beta2" | ||
) | ||
|
||
var _ = Describe("creating a Namespace with Tenant name prefix enforcement at Tenant scope", func() { | ||
t1 := &capsulev1beta2.Tenant{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome", | ||
}, | ||
Spec: capsulev1beta2.TenantSpec{ | ||
ForceTenantPrefix: &[]bool{true}[0], | ||
Owners: capsulev1beta2.OwnerListSpec{ | ||
{ | ||
Name: "john", | ||
Kind: "User", | ||
}, | ||
}, | ||
}, | ||
} | ||
t2 := &capsulev1beta2.Tenant{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "awesome-tenant", | ||
}, | ||
Spec: capsulev1beta2.TenantSpec{ | ||
ForceTenantPrefix: &[]bool{false}[0], | ||
Owners: capsulev1beta2.OwnerListSpec{ | ||
{ | ||
Name: "john", | ||
Kind: "User", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
JustBeforeEach(func() { | ||
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()) | ||
Expect(k8sClient.Delete(context.TODO(), t2)).Should(Succeed()) | ||
|
||
ModifyCapsuleConfigurationOpts(func(configuration *capsulev1beta2.CapsuleConfiguration) { | ||
configuration.Spec.ForceTenantPrefix = false | ||
}) | ||
}) | ||
|
||
It("should fail when not using prefix, with tenant label for a tenant with ForceTenantPrefix true and global ForceTenantPrefix false", func() { | ||
ModifyCapsuleConfigurationOpts(func(configuration *capsulev1beta2.CapsuleConfiguration) { | ||
configuration.Spec.ForceTenantPrefix = false | ||
}) | ||
labels := map[string]string{ | ||
"capsule.clastix.io/tenant": t1.GetName(), | ||
} | ||
ns := NewNamespace("awesome", labels) | ||
NamespaceCreation(ns, t1.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) | ||
}) | ||
|
||
It("should fail using prefix without capsule.clastix.io/tenant label, where the user owns more than one Tenant, for a tenant with ForceTenantPrefix true and global ForceTenantPrefix false", func() { | ||
ns := NewNamespace("awesome-namespace") | ||
NamespaceCreation(ns, t1.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) | ||
}) | ||
|
||
It("should fail using prefix without capsule.clastix.io/tenant label, where the user owns more than one Tenant, for a tenant with ForceTenantPrefix false and global ForceTenantPrefix true", func() { | ||
ns := NewNamespace("awesome-namespace") | ||
NamespaceCreation(ns, t2.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) | ||
}) | ||
|
||
It("should succeed and be assigned with prefix and label, for a tenant with ForceTenantPrefix true and global ForceTenantPrefix false", func() { | ||
labels := map[string]string{ | ||
"capsule.clastix.io/tenant": t1.GetName(), | ||
} | ||
ns := NewNamespace("awesome-tenant", labels) | ||
NamespaceCreation(ns, t1.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) | ||
|
||
TenantNamespaceList(t1, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) | ||
}) | ||
|
||
It("should fail when not using prefix, with tenant label for a tenant with ForceTenantPrefix true and global ForceTenantPrefix true", func() { | ||
ModifyCapsuleConfigurationOpts(func(configuration *capsulev1beta2.CapsuleConfiguration) { | ||
configuration.Spec.ForceTenantPrefix = true | ||
}) | ||
labels := map[string]string{ | ||
"capsule.clastix.io/tenant": t1.GetName(), | ||
} | ||
ns := NewNamespace("awesome", labels) | ||
NamespaceCreation(ns, t1.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) | ||
}) | ||
|
||
It("should succeed and be assigned with prefix and label, for a tenant with ForceTenantPrefix true and global ForceTenantPrefix true", func() { | ||
ModifyCapsuleConfigurationOpts(func(configuration *capsulev1beta2.CapsuleConfiguration) { | ||
configuration.Spec.ForceTenantPrefix = true | ||
}) | ||
labels := map[string]string{ | ||
"capsule.clastix.io/tenant": t1.GetName(), | ||
} | ||
ns := NewNamespace("awesome-tenant", labels) | ||
NamespaceCreation(ns, t1.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) | ||
|
||
TenantNamespaceList(t1, defaultTimeoutInterval).Should(ContainElement(ns.GetName())) | ||
}) | ||
|
||
It("should fail using prefix without capsule.clastix.io/tenant label, for a tenant with ForceTenantPrefix true and global ForceTenantPrefix true", func() { | ||
ModifyCapsuleConfigurationOpts(func(configuration *capsulev1beta2.CapsuleConfiguration) { | ||
configuration.Spec.ForceTenantPrefix = true | ||
}) | ||
ns := NewNamespace("awesome-namespace") | ||
NamespaceCreation(ns, t1.Spec.Owners[0], defaultTimeoutInterval).ShouldNot(Succeed()) | ||
}) | ||
|
||
It("should succeed when not using prefix, with tenant label for a tenant with ForceTenantPrefix false and global ForceTenantPrefix false", func() { | ||
labels := map[string]string{ | ||
"capsule.clastix.io/tenant": t2.GetName(), | ||
} | ||
ns := NewNamespace("awesome", labels) | ||
NamespaceCreation(ns, t2.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) | ||
}) | ||
|
||
It("should succeed when not using prefix, with tenant label for a tenant with ForceTenantPrefix false and global ForceTenantPrefix true", func() { | ||
ModifyCapsuleConfigurationOpts(func(configuration *capsulev1beta2.CapsuleConfiguration) { | ||
configuration.Spec.ForceTenantPrefix = true | ||
}) | ||
labels := map[string]string{ | ||
"capsule.clastix.io/tenant": t2.GetName(), | ||
} | ||
ns := NewNamespace("awesome", labels) | ||
NamespaceCreation(ns, t2.Spec.Owners[0], defaultTimeoutInterval).Should(Succeed()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters