Skip to content

Commit 5f1910f

Browse files
authored
fix(controllers): remove conflicting status update in storeInstallationData (platform9#120)
When r.Status().Update() is called in storeInstallationData, it overwrites the local scope.Config with the server's response. But also the .Status update only updates the .status of the object. Which means, any finalizers added to the object before this but yet to be updated into the k8s data store, are over-written (effectively reseting to what it was before the reconcile loop). This causes the .Patch invocation in the defer-ed func (in .Reconcile) to not see any new finalizers: - both before and after, there are no changes to finalziers, leaving the finalizer change unsaved Additionally, Status().Update bumps the ResourceVersion, causing a conflict in the defer-patch's patchStatus step when the resource is updated. As a result, remove the Status().Update call and let the outer reconcile's defer-patch handle both status and metadata updates atomically. Also fix test assertions: - k8sinstallerconfig_controller_test.go: check for "uninstall" key in the separate uninstallation secret, not the installation secret - byomachine_controller_test.go: set UninstallationSecret in the test status patch, as the reconciler requires both secrets when Ready=true
1 parent 62eb7e9 commit 5f1910f

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

controllers/infrastructure/byomachine_controller_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@ var _ = Describe("Controllers/ByomachineController", func() {
463463
Name: "K8sInstallationSecret",
464464
APIVersion: "v1",
465465
},
466+
UninstallationSecret: &corev1.ObjectReference{
467+
Kind: "Secret",
468+
Namespace: defaultNamespace,
469+
Name: "K8sUninstallationSecret",
470+
APIVersion: "v1",
471+
},
466472
}
467473
Expect(ph.Patch(ctx, k8sInstallerConfig, patch.WithStatusObservedGeneration{})).Should(Succeed())
468474

controllers/infrastructure/k8sinstallerconfig_controller.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,9 @@ func (r *K8sInstallerConfigReconciler) storeInstallationData(ctx context.Context
247247
scope.Config.Status.Ready = true
248248
logger.Info("created installation and uninstallation secrets")
249249

250-
// Persist the status update
251-
if err := r.Status().Update(ctx, scope.Config); err != nil {
252-
return errors.Wrapf(err, "failed to update K8sInstallerConfig status with installation/uninstallation secret references")
253-
}
250+
// Status fields are set in-memory; the outer reconcile's defer-patch persists
251+
// them alongside the finalizer. Using r.Status().Update here would overwrite
252+
// the local object's ResourceVersion and cause a conflict in the defer-patch.
254253

255254
return nil
256255
}

controllers/infrastructure/k8sinstallerconfig_controller_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,21 @@ var _ = Describe("Controllers/K8sInstallerConfigController", func() {
287287
Namespace: k8sinstallerConfig.Namespace}})
288288
Expect(err).NotTo(HaveOccurred())
289289

290-
createdSecret := &corev1.Secret{}
291-
err = k8sClientUncached.Get(ctx, installerSecretLookupKey, createdSecret)
290+
installSecret := &corev1.Secret{}
291+
err = k8sClientUncached.Get(ctx, installerSecretLookupKey, installSecret)
292292
Expect(err).ToNot(HaveOccurred())
293-
_, exists := createdSecret.Data["install"]
293+
_, exists := installSecret.Data["install"]
294294
Expect(exists).To(BeTrue())
295-
_, exists = createdSecret.Data["uninstall"]
295+
296+
// The controller creates a separate secret for the uninstall script.
297+
uninstallSecretLookupKey := types.NamespacedName{
298+
Name: "byoh-uninstall-" + k8sinstallerConfig.Name,
299+
Namespace: k8sinstallerConfig.Namespace,
300+
}
301+
uninstallSecret := &corev1.Secret{}
302+
err = k8sClientUncached.Get(ctx, uninstallSecretLookupKey, uninstallSecret)
303+
Expect(err).ToNot(HaveOccurred())
304+
_, exists = uninstallSecret.Data["uninstall"]
296305
Expect(exists).To(BeTrue())
297306
})
298307

0 commit comments

Comments
 (0)