Skip to content

Commit 1bfb595

Browse files
committed
Fix test cleanup for TTL feature and regenerate API docs
This commit fixes two CI failures: 1. Test failures - TTL tests were not properly cleaning up BMCSecrets - BMCUsers create secrets with owner references - envtest has no garbage collector, so secrets persist after user deletion - Added proper cleanup using owner reference matching (like existing rotation test) - All 4 new TTL tests now pass cleanly 2. Code generation check failure - API docs were stale - Regenerated docs/api-reference/api.md to include TTL/ExpiresAt fields - Docs now include spec.ttl, spec.expiresAt, status.expiresAt, status.conditions Test results: - All 9 BMCUser tests pass (5 existing + 4 new TTL tests) - AfterEach cleanup validates no leaked resources Signed-off-by: Stefan Hipfel <stefan.hipfel@sap.com>
1 parent 643dcf9 commit 1bfb595

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

docs/api-reference/api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,8 @@ _Appears in:_
714714
| `rotationPeriod` _[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#duration-v1-meta)_ | RotationPeriod defines how often the password should be rotated.<br />If not set, the password will not be rotated. | | |
715715
| `bmcSecretRef` _[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#localobjectreference-v1-core)_ | BMCSecretRef references the BMCSecret containing the credentials for this user.<br />If not set, the operator will generate a secure password based on BMC manufacturer requirements. | | |
716716
| `bmcRef` _[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#localobjectreference-v1-core)_ | BMCRef references the BMC this user should be created on. | | |
717+
| `ttl` _[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#duration-v1-meta)_ | TTL specifies the time-to-live duration for this user.<br />When set, the user will be automatically deleted after this duration from creation.<br />This is useful for temporary debugging users.<br />If not set, the user is permanent (no automatic deletion).<br />Mutually exclusive with ExpiresAt - only one should be set. | | Pattern: `^([0-9]+(\.[0-9]+)?(ns\|us\|µs\|ms\|s\|m\|h))+$` <br />Type: string <br /> |
718+
| `expiresAt` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#time-v1-meta)_ | ExpiresAt specifies an absolute timestamp when this user should be deleted.<br />This is useful for users that need to expire at a specific time.<br />If not set along with TTL, the user is permanent.<br />Mutually exclusive with TTL - only one should be set. | | |
717719

718720

719721
#### BMCUserStatus
@@ -733,6 +735,8 @@ _Appears in:_
733735
| `lastRotation` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#time-v1-meta)_ | LastRotation is the timestamp of the last password rotation. | | |
734736
| `passwordExpiration` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#time-v1-meta)_ | PasswordExpiration is the timestamp when the password will expire. | | |
735737
| `id` _string_ | ID is the identifier of the user in the BMC system. | | |
738+
| `expiresAt` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#time-v1-meta)_ | ExpiresAt is the calculated absolute time when this user will be deleted.<br />Set by the controller based on TTL or spec.ExpiresAt.<br />Only set for temporary users (when spec.TTL or spec.ExpiresAt is set). | | |
739+
| `conditions` _[Condition](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#condition-v1-meta) array_ | Conditions represents the latest available observations of the BMCUser's current state. | | |
736740

737741

738742
#### BMCVersion

internal/controller/bmcuser_controller_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,18 @@ var _ = Describe("BMCUser Controller", func() {
435435
expectedExpiry := user.CreationTimestamp.Add(1 * time.Hour)
436436
Expect(user.Status.ExpiresAt.Time).To(BeTemporally("~", expectedExpiry, 5*time.Second))
437437

438+
By("Cleaning up resources")
438439
Expect(k8sClient.Delete(ctx, user)).To(Succeed())
440+
// Clean up all secrets owned by this user since envtest has no garbage collector
441+
secretList := &metalv1alpha1.BMCSecretList{}
442+
Expect(k8sClient.List(ctx, secretList)).To(Succeed())
443+
for _, s := range secretList.Items {
444+
for _, ref := range s.OwnerReferences {
445+
if ref.UID == user.UID {
446+
Expect(client.IgnoreNotFound(k8sClient.Delete(ctx, &s))).To(Succeed())
447+
}
448+
}
449+
}
439450
})
440451

441452
It("should use absolute expiration time from ExpiresAt", func(ctx SpecContext) {
@@ -459,7 +470,18 @@ var _ = Describe("BMCUser Controller", func() {
459470
HaveField("Status.ExpiresAt.Time", BeTemporally("~", expiryTime.Time, 1*time.Second)),
460471
)
461472

473+
By("Cleaning up resources")
462474
Expect(k8sClient.Delete(ctx, user)).To(Succeed())
475+
// Clean up all secrets owned by this user since envtest has no garbage collector
476+
secretList := &metalv1alpha1.BMCSecretList{}
477+
Expect(k8sClient.List(ctx, secretList)).To(Succeed())
478+
for _, s := range secretList.Items {
479+
for _, ref := range s.OwnerReferences {
480+
if ref.UID == user.UID {
481+
Expect(client.IgnoreNotFound(k8sClient.Delete(ctx, &s))).To(Succeed())
482+
}
483+
}
484+
}
463485
})
464486

465487
It("should ignore TTL changes after expiration is calculated", func(ctx SpecContext) {
@@ -491,7 +513,18 @@ var _ = Describe("BMCUser Controller", func() {
491513
HaveField("Status.ExpiresAt.Time", BeTemporally("~", originalExpiry.Time, 1*time.Second)),
492514
)
493515

516+
By("Cleaning up resources")
494517
Expect(k8sClient.Delete(ctx, user)).To(Succeed())
518+
// Clean up all secrets owned by this user since envtest has no garbage collector
519+
secretList := &metalv1alpha1.BMCSecretList{}
520+
Expect(k8sClient.List(ctx, secretList)).To(Succeed())
521+
for _, s := range secretList.Items {
522+
for _, ref := range s.OwnerReferences {
523+
if ref.UID == user.UID {
524+
Expect(client.IgnoreNotFound(k8sClient.Delete(ctx, &s))).To(Succeed())
525+
}
526+
}
527+
}
495528
})
496529

497530
It("should not set expiration for users without TTL or ExpiresAt", func(ctx SpecContext) {
@@ -514,7 +547,18 @@ var _ = Describe("BMCUser Controller", func() {
514547
HaveField("Status.ExpiresAt", BeNil()),
515548
)
516549

550+
By("Cleaning up resources")
517551
Expect(k8sClient.Delete(ctx, user)).To(Succeed())
552+
// Clean up all secrets owned by this user since envtest has no garbage collector
553+
secretList := &metalv1alpha1.BMCSecretList{}
554+
Expect(k8sClient.List(ctx, secretList)).To(Succeed())
555+
for _, s := range secretList.Items {
556+
for _, ref := range s.OwnerReferences {
557+
if ref.UID == user.UID {
558+
Expect(client.IgnoreNotFound(k8sClient.Delete(ctx, &s))).To(Succeed())
559+
}
560+
}
561+
}
518562
})
519563

520564
})

0 commit comments

Comments
 (0)