-
Notifications
You must be signed in to change notification settings - Fork 209
feat: add tenant list to status of capsuleconfiguration #1935
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
oliverbaehler
merged 1 commit into
projectcapsule:main
from
sandert-k8s:capsule-configuration-status
Jun 3, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,111 @@ | ||
| // Copyright 2020-2026 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" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| capsulev1beta2 "github.com/projectcapsule/capsule/api/v1beta2" | ||
| capmeta "github.com/projectcapsule/capsule/pkg/api/meta" | ||
| "github.com/projectcapsule/capsule/pkg/api/rbac" | ||
| ) | ||
|
|
||
| // configStatus returns the current CapsuleConfiguration status. | ||
| func configStatus(g Gomega) capsulev1beta2.CapsuleConfigurationStatus { | ||
| cfg := &capsulev1beta2.CapsuleConfiguration{} | ||
| g.Expect(k8sClient.Get(context.TODO(), client.ObjectKey{Name: defaultConfigurationName}, cfg)).To(Succeed()) | ||
|
|
||
| return cfg.Status | ||
| } | ||
|
|
||
| // configTenantStatus returns the current Tenants list from the default CapsuleConfiguration. | ||
| func configTenantStatus(g Gomega) []string { | ||
| return configStatus(g).Tenants | ||
| } | ||
|
|
||
| var _ = Describe("CapsuleConfiguration status tenants", Ordered, Label("config", "status", "tenants"), func() { | ||
| tnt := &capsulev1beta2.Tenant{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "e2e-cfg-tenants-tnt", | ||
| Labels: map[string]string{ | ||
| "env": "e2e", | ||
| }, | ||
| }, | ||
| Spec: capsulev1beta2.TenantSpec{ | ||
| Owners: rbac.OwnerListSpec{ | ||
| { | ||
| CoreOwnerSpec: rbac.CoreOwnerSpec{ | ||
| UserSpec: rbac.UserSpec{ | ||
| Name: "e2e-cfg-tenants-owner", | ||
| Kind: "User", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| JustAfterEach(func() { | ||
| // Safety-net cleanup; EventuallyDeletion is idempotent for already-deleted objects. | ||
| EventuallyDeletion(tnt) | ||
| }) | ||
|
|
||
| It("reflects Tenant create/delete in status.tenants list", func() { | ||
| var baseNames []string | ||
|
|
||
| // Wait for the controller to have populated the tenants list at least once. | ||
| // status.tenants is nil until the first reconcile runs; a non-nil slice | ||
| // (even empty) means the controller has initialised it. | ||
| Eventually(func(g Gomega) { | ||
| baseNames = configTenantStatus(g) | ||
| g.Expect(baseNames).NotTo(BeNil(), "status.tenants must be initialized before taking baseline") | ||
| }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) | ||
|
sandert-k8s marked this conversation as resolved.
|
||
|
|
||
| By("creating a Tenant and asserting its name appears in status.tenants") | ||
|
|
||
| EventuallyCreation(func() error { | ||
| tnt.ResourceVersion = "" | ||
|
|
||
| return k8sClient.Create(context.TODO(), tnt) | ||
| }).Should(Succeed()) | ||
|
|
||
| TenantReady(tnt, metav1.ConditionTrue, defaultTimeoutInterval) | ||
|
|
||
| Eventually(func(g Gomega) { | ||
| names := configTenantStatus(g) | ||
| g.Expect(names).To(HaveLen(len(baseNames)+1), "status.tenants should grow by one after Tenant creation") | ||
| g.Expect(names).To(ContainElement(tnt.Name), "status.tenants should contain the new Tenant name") | ||
| }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) | ||
|
|
||
| By("deleting the Tenant and asserting its name is removed from status.tenants") | ||
|
|
||
| EventuallyDeletion(tnt) | ||
|
|
||
| Eventually(func(g Gomega) { | ||
| names := configTenantStatus(g) | ||
| g.Expect(names).To(HaveLen(len(baseNames)), "status.tenants should return to baseline after Tenant deletion") | ||
| g.Expect(names).NotTo(ContainElement(tnt.Name), "status.tenants must not contain the deleted Tenant name") | ||
| }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) | ||
| }) | ||
| }) | ||
|
|
||
| var _ = Describe("CapsuleConfiguration status Ready condition", Ordered, Label("config", "status", "ready"), func() { | ||
| It("has Ready=True with Reason=Succeeded after a successful reconcile", func() { | ||
| // After the controller has reconciled at least once the Ready condition | ||
| // must be True with the Succeeded reason. This guards against regressions | ||
| // where a prior failure leaves the condition stuck at Ready=False. | ||
| Eventually(func(g Gomega) { | ||
| st := configStatus(g) | ||
| cond := st.Conditions.GetConditionByType(capmeta.ReadyCondition) | ||
| g.Expect(cond).NotTo(BeNil(), "Ready condition must be present") | ||
| g.Expect(cond.Status).To(Equal(metav1.ConditionTrue), "Ready condition must be True after successful reconcile") | ||
| g.Expect(cond.Reason).To(Equal(capmeta.SucceededReason), "Ready condition reason must be Succeeded") | ||
| }, defaultTimeoutInterval, defaultPollInterval).Should(Succeed()) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.