Skip to content

Commit aba0462

Browse files
zszabo-rhopenshift-merge-bot[bot]
authored andcommitted
ensures that RequirementsMet condition always reflects BootTime value
1 parent 9efb3e9 commit aba0462

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

controllers/imageclusterinstall_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ func (r *ImageClusterInstallReconciler) Reconcile(ctx context.Context, req ctrl.
150150
}
151151
// Nothing to do if the installation process started and the config.iso exists
152152
if !ici.Status.BootTime.IsZero() {
153+
cond := findCondition(ici.Status.Conditions, hivev1.ClusterInstallRequirementsMet)
154+
if cond != nil && cond.Status == corev1.ConditionFalse {
155+
r.setRequirementsMetCondition(ctx, ici,
156+
corev1.ConditionTrue,
157+
v1alpha1.HostConfigurationSucceededReason,
158+
"configuration image is attached to the referenced host")
159+
}
153160
clusterConfigDir := GetClusterConfigDir(filepath.Join(r.Options.DataDir, "namespaces"), ici.Namespace, string(ici.UID))
154161
if verifyIsoAndAuthExists(clusterConfigDir) {
155162
return ctrl.Result{}, nil

controllers/imageclusterinstall_controller_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,54 @@ var _ = Describe("Reconcile", func() {
17921792
Expect(res).To(Equal(ctrl.Result{}))
17931793
})
17941794
})
1795+
// Generated by Cursor
1796+
It("ensures RequirementsMet condition is True when BootTime is set after reconcile", func() {
1797+
// Create BMH in the correct state (StateExternallyProvisioned)
1798+
bmh := bmhInState(bmh_v1alpha1.StateExternallyProvisioned)
1799+
Expect(c.Create(ctx, bmh)).To(Succeed())
1800+
1801+
clusterInstall.Spec.BareMetalHostRef = &v1alpha1.BareMetalHostReference{
1802+
Name: bmh.Name,
1803+
Namespace: bmh.Namespace,
1804+
}
1805+
1806+
// Simulate the bug scenario: Set a stale condition that shows False status
1807+
// This simulates what could happen if the condition was set in a previous reconcile cycle
1808+
clusterInstall.Status.Conditions = []hivev1.ClusterInstallCondition{
1809+
{
1810+
Type: hivev1.ClusterInstallRequirementsMet,
1811+
Status: corev1.ConditionFalse,
1812+
Reason: v1alpha1.HostConfigurationPendingReason,
1813+
Message: "waiting for BMH provisioning state to be StateAvailable or StateExternallyProvisioned, current state is: registering",
1814+
LastTransitionTime: metav1.Now(),
1815+
},
1816+
}
1817+
1818+
Expect(c.Create(ctx, clusterInstall)).To(Succeed())
1819+
Expect(c.Create(ctx, clusterDeployment)).To(Succeed())
1820+
1821+
key := types.NamespacedName{
1822+
Namespace: clusterInstallNamespace,
1823+
Name: clusterInstallName,
1824+
}
1825+
installerSuccess()
1826+
res, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: key})
1827+
Expect(err).NotTo(HaveOccurred())
1828+
Expect(res).To(Equal(ctrl.Result{}))
1829+
1830+
// Verify the reconcile result
1831+
Expect(c.Get(ctx, key, clusterInstall)).To(Succeed())
1832+
1833+
// The critical test: BootTime is set and RequirementsMet MUST be True after successful reconcile
1834+
Expect(clusterInstall.Status.BootTime).ToNot(BeZero(), "BootTime should be set after successful reconcile")
1835+
cond := findCondition(clusterInstall.Status.Conditions, hivev1.ClusterInstallRequirementsMet)
1836+
Expect(cond).NotTo(BeNil())
1837+
Expect(cond.Status).To(Equal(corev1.ConditionTrue),
1838+
"RequirementsMet condition must be True when BootTime is set. Found: status=%s, reason=%s, message=%s",
1839+
cond.Status, cond.Reason, cond.Message)
1840+
Expect(cond.Reason).To(Equal(v1alpha1.HostConfigurationSucceededReason))
1841+
Expect(cond.Message).To(Equal("configuration image is attached to the referenced host"))
1842+
})
17951843
})
17961844

17971845
var _ = Describe("Reconcile with DataImageCoolDownPeriod set to 1 second", func() {

0 commit comments

Comments
 (0)