From 2b614e30a19feec5f00b9a0b4e69c798bd665c13 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Fri, 10 Jan 2025 11:12:38 +0100 Subject: [PATCH] controller: nrop: test: add helper to ensure MCP readiness factor out common code which can't fail and which is a minor detail fro the test flow: an ideal candidate for a helper extraction. Signed-off-by: Francesco Romani --- .../numaresourcesoperator_controller_test.go | 92 ++++--------------- 1 file changed, 20 insertions(+), 72 deletions(-) diff --git a/controllers/numaresourcesoperator_controller_test.go b/controllers/numaresourcesoperator_controller_test.go index c062f7ee1..c69569b94 100644 --- a/controllers/numaresourcesoperator_controller_test.go +++ b/controllers/numaresourcesoperator_controller_test.go @@ -1190,34 +1190,12 @@ var _ = Describe("Test NUMAResourcesOperator Reconcile", func() { // on the first iteration we expect the CRDs and MCPs to be created, yet, it will wait one minute to update MC, thus RTE daemonsets and complete status update is not going to be achieved at this point Expect(reconciler.Reconcile(context.TODO(), reconcile.Request{NamespacedName: key})).To(CauseRequeue()) - // Ensure mcp1 is ready Expect(reconciler.Client.Get(context.TODO(), client.ObjectKeyFromObject(mcp1), mcp1)).To(Succeed()) - mcp1.Status.Configuration.Source = []corev1.ObjectReference{ - { - Name: objectnames.GetMachineConfigName(nro.Name, mcp1.Name), - }, - } - mcp1.Status.Conditions = []machineconfigv1.MachineConfigPoolCondition{ - { - Type: machineconfigv1.MachineConfigPoolUpdated, - Status: corev1.ConditionTrue, - }, - } + ensureMCPIsReady(mcp1, nro.Name) Expect(reconciler.Client.Update(context.TODO(), mcp1)).To(Succeed()) - // ensure mcp2 is ready Expect(reconciler.Client.Get(context.TODO(), client.ObjectKeyFromObject(mcp2), mcp2)).To(Succeed()) - mcp2.Status.Configuration.Source = []corev1.ObjectReference{ - { - Name: objectnames.GetMachineConfigName(nro.Name, mcp2.Name), - }, - } - mcp2.Status.Conditions = []machineconfigv1.MachineConfigPoolCondition{ - { - Type: machineconfigv1.MachineConfigPoolUpdated, - Status: corev1.ConditionTrue, - }, - } + ensureMCPIsReady(mcp2, nro.Name) Expect(reconciler.Client.Update(context.TODO(), mcp2)).To(Succeed()) // triggering a second reconcile will create the RTEs and fully update the statuses making the operator in Available condition -> no more reconciliation needed thus the result is clean @@ -1381,34 +1359,12 @@ var _ = Describe("Test NUMAResourcesOperator Reconcile", func() { var err error By("Ensure both MachineConfigPools are ready") - // Ensure mcp1 is ready Expect(reconciler.Client.Get(context.TODO(), client.ObjectKeyFromObject(mcp1), mcp1)).ToNot(HaveOccurred()) - mcp1.Status.Configuration.Source = []corev1.ObjectReference{ - { - Name: objectnames.GetMachineConfigName(nro.Name, mcp1.Name), - }, - } - mcp1.Status.Conditions = []machineconfigv1.MachineConfigPoolCondition{ - { - Type: machineconfigv1.MachineConfigPoolUpdated, - Status: corev1.ConditionTrue, - }, - } + ensureMCPIsReady(mcp1, nro.Name) Expect(reconciler.Client.Update(context.TODO(), mcp1)) - // ensure mcp2 is ready Expect(reconciler.Client.Get(context.TODO(), client.ObjectKeyFromObject(mcp2), mcp2)).ToNot(HaveOccurred()) - mcp2.Status.Configuration.Source = []corev1.ObjectReference{ - { - Name: objectnames.GetMachineConfigName(nro.Name, mcp2.Name), - }, - } - mcp2.Status.Conditions = []machineconfigv1.MachineConfigPoolCondition{ - { - Type: machineconfigv1.MachineConfigPoolUpdated, - Status: corev1.ConditionTrue, - }, - } + ensureMCPIsReady(mcp2, nro.Name) Expect(reconciler.Client.Update(context.TODO(), mcp2)) result, err = reconciler.Reconcile(context.TODO(), reconcile.Request{NamespacedName: key}) @@ -1664,34 +1620,12 @@ var _ = Describe("Test NUMAResourcesOperator Reconcile", func() { // on the first iteration we expect the CRDs and MCPs to be created, yet, it will wait one minute to update MC, thus RTE daemonsets and complete status update is not going to be achieved at this point Expect(reconciler.Reconcile(context.TODO(), reconcile.Request{NamespacedName: key})).To(CauseRequeue()) - // Ensure mcp1 is ready Expect(reconciler.Client.Get(context.TODO(), client.ObjectKeyFromObject(mcp1), mcp1)).To(Succeed()) - mcp1.Status.Configuration.Source = []corev1.ObjectReference{ - { - Name: objectnames.GetMachineConfigName(nro.Name, mcp1.Name), - }, - } - mcp1.Status.Conditions = []machineconfigv1.MachineConfigPoolCondition{ - { - Type: machineconfigv1.MachineConfigPoolUpdated, - Status: corev1.ConditionTrue, - }, - } + ensureMCPIsReady(mcp1, nro.Name) Expect(reconciler.Client.Update(context.TODO(), mcp1)).To(Succeed()) - // ensure mcp2 is ready Expect(reconciler.Client.Get(context.TODO(), client.ObjectKeyFromObject(mcp2), mcp2)).To(Succeed()) - mcp2.Status.Configuration.Source = []corev1.ObjectReference{ - { - Name: objectnames.GetMachineConfigName(nro.Name, mcp2.Name), - }, - } - mcp2.Status.Conditions = []machineconfigv1.MachineConfigPoolCondition{ - { - Type: machineconfigv1.MachineConfigPoolUpdated, - Status: corev1.ConditionTrue, - }, - } + ensureMCPIsReady(mcp2, nro.Name) Expect(reconciler.Client.Update(context.TODO(), mcp2)).To(Succeed()) // triggering a second reconcile will create the RTEs and fully update the statuses making the operator in Available condition -> no more reconciliation needed thus the result is clean @@ -1981,6 +1915,20 @@ func reconcileObjectsHypershift(nro *nropv1.NUMAResourcesOperator) *NUMAResource return reconciler } +func ensureMCPIsReady(mcp *machineconfigv1.MachineConfigPool, nroName string) { + mcp.Status.Configuration.Source = []corev1.ObjectReference{ + { + Name: objectnames.GetMachineConfigName(nroName, mcp.Name), + }, + } + mcp.Status.Conditions = []machineconfigv1.MachineConfigPoolCondition{ + { + Type: machineconfigv1.MachineConfigPoolUpdated, + Status: corev1.ConditionTrue, + }, + } +} + func CauseRequeue() gomegatypes.GomegaMatcher { return gcustom.MakeMatcher(func(rr reconcile.Result) (bool, error) { return rr.RequeueAfter > 0, nil