@@ -218,7 +218,7 @@ func (r *ProxmoxClusterReconciler) reconcileNormal(ctx context.Context, clusterS
218218 // when a Cluster is marked failed cause the Proxmox client is nil.
219219 // the cluster doesn't reconcile the failed state if we restart the controller.
220220 // so we need to check if the ProxmoxClient is not nil and the ProxmoxCluster has a failure reason.
221- err := r .reconcileFailedClusterState (clusterScope )
221+ err := r .reconcileFailedClusterState (ctx , clusterScope )
222222 if err != nil {
223223 return ctrl.Result {}, err
224224 }
@@ -248,28 +248,28 @@ func (r *ProxmoxClusterReconciler) reconcileNormal(ctx context.Context, clusterS
248248 return ctrl.Result {}, nil
249249}
250250
251- func (r * ProxmoxClusterReconciler ) reconcileFailedClusterState (clusterScope * scope.ClusterScope ) error {
251+ //nolint:staticcheck
252+ func (r * ProxmoxClusterReconciler ) reconcileFailedClusterState (ctx context.Context , clusterScope * scope.ClusterScope ) error {
252253 if clusterScope .ProxmoxClient != nil &&
253- clusterScope .ProxmoxCluster .Status .FailureReason != nil &&
254- clusterScope .ProxmoxCluster .Status .FailureMessage != nil &&
255- ptr .Deref (clusterScope .ProxmoxCluster .Status .FailureReason , "" ) == clustererrors .InvalidConfigurationClusterError &&
256- strings .Contains (ptr .Deref (clusterScope .ProxmoxCluster .Status .FailureMessage , "" ), "No credentials found" ) {
257- // clear the failure reason
254+ ptr .Deref (clusterScope .Cluster .Status .FailureReason , "" ) == clustererrors .InvalidConfigurationClusterError &&
255+ strings .Contains (ptr .Deref (clusterScope .Cluster .Status .FailureMessage , "" ), "No credentials found" ) {
256+ // Clear the failure reason and patch the proxmox cluster.
258257 clusterScope .ProxmoxCluster .Status .FailureMessage = nil
259258 clusterScope .ProxmoxCluster .Status .FailureReason = nil
260- if err := clusterScope .Close (); err != nil {
259+ if err := clusterScope .PatchObject (); err != nil {
261260 return err
262261 }
263262
264- cHelper , err := patch .NewHelper (clusterScope .Cluster , r .Client )
263+ // Clear the failure reason and patch the root cluster.
264+ newCluster := clusterScope .Cluster .DeepCopy ()
265+ newCluster .Status .FailureMessage = nil //nolint:staticcheck
266+ newCluster .Status .FailureReason = nil //nolint:staticcheck
267+
268+ err := r .Status ().Patch (ctx , newCluster , client .MergeFrom (clusterScope .Cluster ))
265269 if err != nil {
266- return errors .Wrap (err , "failed to init patch helper" )
267- }
268- clusterScope .Cluster .Status .FailureMessage = nil //nolint:staticcheck
269- clusterScope .Cluster .Status .FailureReason = nil //nolint:staticcheck
270- if err = cHelper .Patch (context .TODO (), clusterScope .Cluster ); err != nil {
271- return err
270+ return errors .Wrapf (err , "failed to patch cluster %s/%s" , newCluster .Namespace , newCluster .Name )
272271 }
272+
273273 return errors .New ("reconciling cluster failure state" )
274274 }
275275
0 commit comments