diff --git a/Makefile b/Makefile index 60836533..5addee43 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefin @go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases .PHONY: generate -generate: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. +generate: manifests fmt vet ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. @go run sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile=".reuse/boilerplate.go.txt" paths="./..." @internal/tools/generate.sh @@ -49,8 +49,8 @@ vet: ## Run go vet against code. @go vet ./... .PHONY: test -test: manifests generate fmt vet ## Run tests. - @go run github.com/onsi/ginkgo/v2/ginkgo -r --race --randomize-suites --keep-going --randomize-all --repeat=1 +test: ## Run tests. + @go run github.com/onsi/ginkgo/v2/ginkgo -r --race --randomize-suites --keep-going --randomize-all --repeat=11 .PHONY: lint lint: ## Run golangci-lint linter & yamllint. @@ -67,7 +67,7 @@ checklicense: ## Check that every file has a license header present. ##@ Build .PHONY: build -build: manifests generate fmt vet ## Build manager binary. +build: generate ## Build manager binary. @go build -o metal cmd/main.go .PHONY: docker-build diff --git a/internal/controller/machineclaim_controller_test.go b/internal/controller/machineclaim_controller_test.go index f91a13f9..d95bd836 100644 --- a/internal/controller/machineclaim_controller_test.go +++ b/internal/controller/machineclaim_controller_test.go @@ -4,12 +4,15 @@ package controller import ( + "time" + "github.com/google/uuid" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" . "sigs.k8s.io/controller-runtime/pkg/envtest/komega" metalv1alpha1 "github.com/ironcore-dev/metal/api/v1alpha1" @@ -25,7 +28,36 @@ var _ = Describe("MachineClaim Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ns)).To(Succeed()) - DeferCleanup(k8sClient.Delete, ns) + DeferCleanup(func(ctx SpecContext) { + Expect(k8sClient.Delete(ctx, ns)).To(Succeed()) + }) + + Eventually(ObjectList(&metalv1alpha1.MachineList{})).Should(HaveField("Items", HaveLen(0))) + Eventually(ObjectList(&metalv1alpha1.MachineClaimList{}, &client.ListOptions{ + Namespace: ns.Name, + })).Should(HaveField("Items", HaveLen(0))) + + DeferCleanup(func(ctx SpecContext) { + Eventually(ctx, func(g Gomega, ctx SpecContext) { + var machines metalv1alpha1.MachineList + g.Expect(ObjectList(&machines)()).To(SatisfyAll()) + if len(machines.Items) > 0 { + g.Expect(k8sClient.DeleteAllOf(ctx, &machines.Items[0])).To(Succeed()) + } + var claims metalv1alpha1.MachineClaimList + g.Expect(ObjectList(&claims)()).To(SatisfyAll()) + if len(claims.Items) > 0 { + g.Expect(k8sClient.DeleteAllOf(ctx, &claims.Items[0], &client.DeleteAllOfOptions{ + ListOptions: client.ListOptions{ + Namespace: ns.Name, + }, + })).To(Succeed()) + } + + g.Expect(ObjectList(&machines)()).To(HaveField("Items", BeEmpty())) + g.Expect(ObjectList(&claims)()).To(HaveField("Items", BeEmpty())) + }, time.Second*3).Should(Succeed()) + }) }) It("should claim a Machine by ref", func(ctx SpecContext) { @@ -42,10 +74,6 @@ var _ = Describe("MachineClaim Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, machine)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, machine)).To(Succeed()) - Eventually(Get(machine)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching Machine state to Ready") Eventually(UpdateStatus(machine, func() { @@ -112,10 +140,6 @@ var _ = Describe("MachineClaim Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, machine)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, machine)).To(Succeed()) - Eventually(Get(machine)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching Machine state to Ready") Eventually(UpdateStatus(machine, func() { @@ -190,12 +214,6 @@ var _ = Describe("MachineClaim Controller", Serial, func() { HaveField("Finalizers", ContainElement(MachineClaimFinalizer)), HaveField("Status.Phase", metalv1alpha1.MachineClaimPhaseUnbound), )) - - By("Deleting the MachineClaim") - Expect(k8sClient.Delete(ctx, claim)).To(Succeed()) - - By("Expecting MachineClaim to be removed") - Eventually(Get(claim)).Should(Satisfy(errors.IsNotFound)) }) It("should not claim a Machine with no matching selector", func(ctx SpecContext) { @@ -215,10 +233,6 @@ var _ = Describe("MachineClaim Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, machine)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, machine)).To(Succeed()) - Eventually(Get(machine)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching Machine state to Ready") Eventually(UpdateStatus(machine, func() { @@ -276,10 +290,6 @@ var _ = Describe("MachineClaim Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, machine)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, machine)).To(Succeed()) - Eventually(Get(machine)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching Machine state to Error") Eventually(UpdateStatus(machine, func() { @@ -301,10 +311,6 @@ var _ = Describe("MachineClaim Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, claim)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, claim)).To(Succeed()) - Eventually(Get(claim)).Should(Satisfy(errors.IsNotFound)) - }) By("Expecting finalizer and phase to be correct on the MachineClaim") Eventually(Object(claim)).Should(SatisfyAll( diff --git a/internal/controller/oob_controller.go b/internal/controller/oob_controller.go index 969d6b18..30313aa6 100644 --- a/internal/controller/oob_controller.go +++ b/internal/controller/oob_controller.go @@ -147,6 +147,7 @@ func (r *OOBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R if err != nil { return ctrl.Result{}, client.IgnoreNotFound(fmt.Errorf("cannot get OOB: %w", err)) } + log.Info(ctx, "OOB", "object", oob) if !oob.DeletionTimestamp.IsZero() { return ctrl.Result{}, r.finalize(ctx, &oob) @@ -415,7 +416,7 @@ func (r *OOBReconciler) runPhase(ctx context.Context, oob *metalv1alpha1.OOB, ph func (r *OOBReconciler) setCondition(ctx context.Context, oob *metalv1alpha1.OOB, apply *metalv1alpha1apply.OOBApplyConfiguration, status *metalv1alpha1apply.OOBStatusApplyConfiguration, state metalv1alpha1.OOBState, cond metav1.Condition) (context.Context, *metalv1alpha1apply.OOBApplyConfiguration, *metalv1alpha1apply.OOBStatusApplyConfiguration, error) { conds, mod := ssa.SetCondition(oob.Status.Conditions, cond) if oob.Status.State != state || mod { - log.Debug(ctx, "Setting condition", "reason", cond.Reason) + log.Debug(ctx, "Setting condition", "type", cond.Type, "status", cond.Status, "reason", cond.Reason) if status == nil { applyst, err := metalv1alpha1apply.ExtractOOBStatus(oob, OOBFieldManager) if err != nil { diff --git a/internal/controller/oob_controller_test.go b/internal/controller/oob_controller_test.go index bbf6bb49..bed26148 100644 --- a/internal/controller/oob_controller_test.go +++ b/internal/controller/oob_controller_test.go @@ -5,6 +5,7 @@ package controller import ( "fmt" + "time" ipamv1alpha1 "github.com/ironcore-dev/ipam/api/ipam/v1alpha1" . "github.com/onsi/ginkgo/v2" @@ -20,6 +21,50 @@ import ( var _ = Describe("OOB Controller", Serial, func() { mac := "aabbccddeeff" + timeToReady := time.Second * 3 + + BeforeEach(func(ctx SpecContext) { + Eventually(ObjectList(&ipamv1alpha1.IPList{}, &client.ListOptions{ + Namespace: OOBTemporaryNamespaceHack, + })).Should(HaveField("Items", HaveLen(0))) + Eventually(ObjectList(&metalv1alpha1.MachineList{})).Should(HaveField("Items", HaveLen(0))) + Eventually(ObjectList(&metalv1alpha1.OOBList{})).Should(HaveField("Items", HaveLen(0))) + Eventually(ObjectList(&metalv1alpha1.OOBSecretList{})).Should(HaveField("Items", HaveLen(0))) + + DeferCleanup(func(ctx SpecContext) { + Eventually(ctx, func(g Gomega, ctx SpecContext) { + var ips ipamv1alpha1.IPList + g.Expect(ObjectList(&ips)()).To(SatisfyAll()) + if len(ips.Items) > 0 { + g.Expect(k8sClient.DeleteAllOf(ctx, &ips.Items[0], &client.DeleteAllOfOptions{ + ListOptions: client.ListOptions{ + Namespace: OOBTemporaryNamespaceHack, + }, + })).To(Succeed()) + } + var machines metalv1alpha1.MachineList + g.Expect(ObjectList(&machines)()).To(SatisfyAll()) + if len(machines.Items) > 0 { + g.Expect(k8sClient.DeleteAllOf(ctx, &machines.Items[0])).To(Succeed()) + } + var oobs metalv1alpha1.OOBList + g.Expect(ObjectList(&oobs)()).To(SatisfyAll()) + if len(oobs.Items) > 0 { + g.Expect(k8sClient.DeleteAllOf(ctx, &oobs.Items[0])).To(Succeed()) + } + var secrets metalv1alpha1.OOBSecretList + g.Expect(ObjectList(&secrets)()).To(SatisfyAll()) + if len(secrets.Items) > 0 { + g.Expect(k8sClient.DeleteAllOf(ctx, &secrets.Items[0])).To(Succeed()) + } + + g.Expect(ObjectList(&ips)()).To(HaveField("Items", BeEmpty())) + g.Expect(ObjectList(&machines)()).To(HaveField("Items", BeEmpty())) + g.Expect(ObjectList(&oobs)()).To(HaveField("Items", BeEmpty())) + g.Expect(ObjectList(&secrets)()).To(HaveField("Items", BeEmpty())) + }, time.Second*3).Should(Succeed()) + }) + }) It("should create an OOB from an IP", func(ctx SpecContext) { oob := &metalv1alpha1.OOB{ @@ -27,17 +72,6 @@ var _ = Describe("OOB Controller", Serial, func() { Name: mac, }, } - secret := &metalv1alpha1.OOBSecret{ - ObjectMeta: metav1.ObjectMeta{ - Name: mac, - }, - } - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, oob)).To(Succeed()) - Eventually(Get(oob)).Should(Satisfy(errors.IsNotFound)) - Expect(k8sClient.Delete(ctx, secret)).To(Succeed()) - Eventually(Get(secret)).Should(Satisfy(errors.IsNotFound)) - }) By("Creating an IP") ip := &ipamv1alpha1.IP{ @@ -51,10 +85,6 @@ var _ = Describe("OOB Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ip)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, ip)).To(Succeed()) - Eventually(Get(ip)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching IP reservation and state") ipAddr, err := ipamv1alpha1.IPAddrFromString("1.2.3.4") @@ -65,7 +95,7 @@ var _ = Describe("OOB Controller", Serial, func() { })).Should(Succeed()) By("Expecting finalizer, mac, and endpointref to be correct on the OOB") - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Finalizers", ContainElement(OOBFinalizer)), HaveField("Spec.MACAddress", mac), HaveField("Spec.EndpointRef.Name", ip.Name), @@ -83,17 +113,6 @@ var _ = Describe("OOB Controller", Serial, func() { Name: mac, }, } - secret := &metalv1alpha1.OOBSecret{ - ObjectMeta: metav1.ObjectMeta{ - Name: mac, - }, - } - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, oob)).To(Succeed()) - Eventually(Get(oob)).Should(Satisfy(errors.IsNotFound)) - Expect(k8sClient.Delete(ctx, secret)).To(Succeed()) - Eventually(Get(secret)).Should(Satisfy(errors.IsNotFound)) - }) By("Creating an IP") ip := &ipamv1alpha1.IP{ @@ -107,10 +126,6 @@ var _ = Describe("OOB Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ip)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, ip)).To(Succeed()) - Eventually(Get(ip)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching IP reservation and state") ipAddr, err := ipamv1alpha1.IPAddrFromString("1.2.3.4") @@ -140,7 +155,7 @@ var _ = Describe("OOB Controller", Serial, func() { })).Should(Succeed()) By("Expecting OOB not to be ignored") - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Status.State", metalv1alpha1.OOBStateReady), WithTransform(readyReason, Equal(metalv1alpha1.OOBConditionReasonReady)), )) @@ -152,17 +167,6 @@ var _ = Describe("OOB Controller", Serial, func() { Name: mac, }, } - secret := &metalv1alpha1.OOBSecret{ - ObjectMeta: metav1.ObjectMeta{ - Name: mac, - }, - } - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, oob)).To(Succeed()) - Eventually(Get(oob)).Should(Satisfy(errors.IsNotFound)) - Expect(k8sClient.Delete(ctx, secret)).To(Succeed()) - Eventually(Get(secret)).Should(Satisfy(errors.IsNotFound)) - }) By("Creating an IP") ip := &ipamv1alpha1.IP{ @@ -176,10 +180,6 @@ var _ = Describe("OOB Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ip)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, ip)).To(Succeed()) - Eventually(Get(ip)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching IP reservation and state") ipAddr, err := ipamv1alpha1.IPAddrFromString("1.2.3.4") @@ -190,7 +190,7 @@ var _ = Describe("OOB Controller", Serial, func() { })).Should(Succeed()) By("Expecting finalizer, mac, and endpointref to be correct on the OOB") - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Finalizers", ContainElement(OOBFinalizer)), HaveField("Spec.MACAddress", mac), HaveField("Spec.EndpointRef.Name", ip.Name), @@ -227,7 +227,7 @@ var _ = Describe("OOB Controller", Serial, func() { })).Should(Succeed()) By("Expecting the OOB to have an endpoint") - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Spec.EndpointRef.Name", ip.Name), HaveField("Status.State", metalv1alpha1.OOBStateReady), WithTransform(readyReason, Equal(metalv1alpha1.OOBConditionReasonReady)), @@ -240,17 +240,6 @@ var _ = Describe("OOB Controller", Serial, func() { Name: mac, }, } - secret := &metalv1alpha1.OOBSecret{ - ObjectMeta: metav1.ObjectMeta{ - Name: mac, - }, - } - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, oob)).To(Succeed()) - Eventually(Get(oob)).Should(Satisfy(errors.IsNotFound)) - Expect(k8sClient.Delete(ctx, secret)).To(Succeed()) - Eventually(Get(secret)).Should(Satisfy(errors.IsNotFound)) - }) By("Creating an IP") ip := &ipamv1alpha1.IP{ @@ -264,10 +253,6 @@ var _ = Describe("OOB Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ip)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, ip)).To(Succeed()) - Eventually(Get(ip)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching IP reservation and state") ipAddr, err := ipamv1alpha1.IPAddrFromString("1.2.3.4") @@ -278,7 +263,7 @@ var _ = Describe("OOB Controller", Serial, func() { })).Should(Succeed()) By("Expecting finalizer, mac, and endpointref to be correct on the OOB") - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Finalizers", ContainElement(OOBFinalizer)), HaveField("Spec.MACAddress", mac), HaveField("Spec.EndpointRef.Name", ip.Name), @@ -304,7 +289,7 @@ var _ = Describe("OOB Controller", Serial, func() { })).Should(Succeed()) By("Expecting the OOB to recover") - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Status.State", metalv1alpha1.OOBStateReady), WithTransform(readyReason, Equal(metalv1alpha1.OOBConditionReasonReady)), )) @@ -327,7 +312,7 @@ var _ = Describe("OOB Controller", Serial, func() { })).Should(Succeed()) By("Expecting the OOB to recover") - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Status.State", metalv1alpha1.OOBStateReady), WithTransform(readyReason, Equal(metalv1alpha1.OOBConditionReasonReady)), )) @@ -344,12 +329,6 @@ var _ = Describe("OOB Controller", Serial, func() { Name: mac, }, } - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, oob)).To(Succeed()) - Eventually(Get(oob)).Should(Satisfy(errors.IsNotFound)) - Expect(k8sClient.Delete(ctx, secret)).To(Succeed()) - Eventually(Get(secret)).Should(Satisfy(errors.IsNotFound)) - }) By("Creating an IP") ip := &ipamv1alpha1.IP{ @@ -363,10 +342,6 @@ var _ = Describe("OOB Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ip)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, ip)).To(Succeed()) - Eventually(Get(ip)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching IP reservation and state") ipAddr, err := ipamv1alpha1.IPAddrFromString("1.2.3.4") @@ -384,7 +359,7 @@ var _ = Describe("OOB Controller", Serial, func() { HaveField("Spec.Password", Not(BeEmpty())), HaveField("Spec.ExpirationTime", Not(BeNil())), )) - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Spec.SecretRef.Name", secret.Name), HaveField("Status.State", metalv1alpha1.OOBStateReady), WithTransform(readyReason, Equal(metalv1alpha1.OOBConditionReasonReady)), @@ -404,10 +379,6 @@ var _ = Describe("OOB Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ip)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, ip)).To(Succeed()) - Eventually(Get(ip)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching IP reservation and state") ipAddr, err := ipamv1alpha1.IPAddrFromString("1.2.3.4") @@ -441,12 +412,6 @@ var _ = Describe("OOB Controller", Serial, func() { Name: mac, }, } - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, oob)).To(Succeed()) - Eventually(Get(oob)).Should(Satisfy(errors.IsNotFound)) - Expect(k8sClient.Delete(ctx, secret)).To(Succeed()) - Eventually(Get(secret)).Should(Satisfy(errors.IsNotFound)) - }) By("Creating an IP") ip := &ipamv1alpha1.IP{ @@ -460,10 +425,6 @@ var _ = Describe("OOB Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ip)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, ip)).To(Succeed()) - Eventually(Get(ip)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching IP reservation and state") ipAddr, err := ipamv1alpha1.IPAddrFromString("1.2.3.4") @@ -481,7 +442,7 @@ var _ = Describe("OOB Controller", Serial, func() { HaveField("Spec.Password", Not(BeEmpty())), HaveField("Spec.ExpirationTime", Not(BeNil())), )) - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Spec.SecretRef.Name", secret.Name), HaveField("Status.State", metalv1alpha1.OOBStateReady), WithTransform(readyReason, Equal(metalv1alpha1.OOBConditionReasonReady)), @@ -505,7 +466,7 @@ var _ = Describe("OOB Controller", Serial, func() { })).Should(Succeed()) By("Expecting the OOB to recover") - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Status.State", metalv1alpha1.OOBStateReady), WithTransform(readyReason, Equal(metalv1alpha1.OOBConditionReasonReady)), )) @@ -522,12 +483,6 @@ var _ = Describe("OOB Controller", Serial, func() { Name: mac, }, } - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, oob)).To(Succeed()) - Eventually(Get(oob)).Should(Satisfy(errors.IsNotFound)) - Expect(k8sClient.Delete(ctx, secret)).To(Succeed()) - Eventually(Get(secret)).Should(Satisfy(errors.IsNotFound)) - }) By("Creating an IP") ip := &ipamv1alpha1.IP{ @@ -541,10 +496,6 @@ var _ = Describe("OOB Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ip)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, ip)).To(Succeed()) - Eventually(Get(ip)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching IP reservation and state") ipAddr, err := ipamv1alpha1.IPAddrFromString("1.2.3.4") @@ -562,7 +513,7 @@ var _ = Describe("OOB Controller", Serial, func() { HaveField("Spec.Password", Not(BeEmpty())), HaveField("Spec.ExpirationTime", Not(BeNil())), )) - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Spec.SecretRef.Name", secret.Name), HaveField("Status.State", metalv1alpha1.OOBStateReady), WithTransform(readyReason, Equal(metalv1alpha1.OOBConditionReasonReady)), @@ -588,7 +539,7 @@ var _ = Describe("OOB Controller", Serial, func() { HaveField("Spec.Password", Not(Equal(password))), HaveField("Spec.ExpirationTime", Not(Equal(expiration))), )) - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Spec.SecretRef.Name", secret.Name), HaveField("Status.State", metalv1alpha1.OOBStateReady), WithTransform(readyReason, Equal(metalv1alpha1.OOBConditionReasonReady)), @@ -601,17 +552,6 @@ var _ = Describe("OOB Controller", Serial, func() { Name: mac, }, } - secret := &metalv1alpha1.OOBSecret{ - ObjectMeta: metav1.ObjectMeta{ - Name: mac, - }, - } - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, oob)).To(Succeed()) - Eventually(Get(oob)).Should(Satisfy(errors.IsNotFound)) - Expect(k8sClient.Delete(ctx, secret)).To(Succeed()) - Eventually(Get(secret)).Should(Satisfy(errors.IsNotFound)) - }) By("Creating an IP") ip := &ipamv1alpha1.IP{ @@ -625,10 +565,6 @@ var _ = Describe("OOB Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ip)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, ip)).To(Succeed()) - Eventually(Get(ip)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching IP reservation and state") ipAddr, err := ipamv1alpha1.IPAddrFromString("1.2.3.4") @@ -639,7 +575,7 @@ var _ = Describe("OOB Controller", Serial, func() { })).Should(Succeed()) By("Expecting the OOB to have the correct info") - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Status.Type", metalv1alpha1.OOBTypeMachine), HaveField("Status.Manufacturer", "Fake"), HaveField("Status.SerialNumber", "0"), @@ -655,19 +591,6 @@ var _ = Describe("OOB Controller", Serial, func() { Name: mac, }, } - secret := &metalv1alpha1.OOBSecret{ - ObjectMeta: metav1.ObjectMeta{ - Name: mac, - }, - } - machine := &metalv1alpha1.Machine{} - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, oob)).To(Succeed()) - Eventually(Get(oob)).Should(Satisfy(errors.IsNotFound)) - Expect(k8sClient.Delete(ctx, secret)).To(Succeed()) - Eventually(Get(secret)).Should(Satisfy(errors.IsNotFound)) - Eventually(Get(machine)).Should(Satisfy(errors.IsNotFound)) - }) By("Creating an IP") ip := &ipamv1alpha1.IP{ @@ -681,10 +604,6 @@ var _ = Describe("OOB Controller", Serial, func() { }, } Expect(k8sClient.Create(ctx, ip)).To(Succeed()) - DeferCleanup(func(ctx SpecContext) { - Expect(k8sClient.Delete(ctx, ip)).To(Succeed()) - Eventually(Get(ip)).Should(Satisfy(errors.IsNotFound)) - }) By("Patching IP reservation and state") ipAddr, err := ipamv1alpha1.IPAddrFromString("1.2.3.4") @@ -695,7 +614,7 @@ var _ = Describe("OOB Controller", Serial, func() { })).Should(Succeed()) By("Expecting the OOB to have the correct info") - Eventually(Object(oob)).Should(SatisfyAll( + Eventually(Object(oob), timeToReady).Should(SatisfyAll( HaveField("Status.Type", metalv1alpha1.OOBTypeMachine), HaveField("Status.State", metalv1alpha1.OOBStateReady), WithTransform(readyReason, Equal(metalv1alpha1.OOBConditionReasonReady)), @@ -704,7 +623,7 @@ var _ = Describe("OOB Controller", Serial, func() { By("Listing machines") machines := &metalv1alpha1.MachineList{} Eventually(ObjectList(machines)).Should(HaveField("Items", HaveLen(1))) - machine = &machines.Items[0] + machine := &machines.Items[0] By("Expecting Machine to have the correct data") Eventually(Object(machine)).Should(SatisfyAll( diff --git a/internal/controller/suite_test.go b/internal/controller/suite_test.go index b06f392e..d41506f5 100644 --- a/internal/controller/suite_test.go +++ b/internal/controller/suite_test.go @@ -39,7 +39,6 @@ var ( ) func TestControllers(t *testing.T) { - SetDefaultEventuallyTimeout(3 * time.Second) RegisterFailHandler(Fail) RunSpecs(t, "Controller") @@ -81,6 +80,7 @@ var _ = BeforeSuite(func() { Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) SetClient(k8sClient) + SetContext(ctx) ns := &v1.Namespace{ ObjectMeta: metav1.ObjectMeta{