Skip to content

Commit c1b2fd2

Browse files
Audit patch withOwnedConditions
1 parent e13abea commit c1b2fd2

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

internal/controllers/cluster/cluster_controller.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,20 @@ func patchCluster(ctx context.Context, patchHelper *patch.Helper, cluster *clust
251251
clusterv1.ControlPlaneReadyCondition,
252252
clusterv1.InfrastructureReadyCondition,
253253
}},
254+
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
255+
clusterv1.ClusterInfrastructureReadyV1Beta2Condition,
256+
clusterv1.ClusterControlPlaneAvailableV1Beta2Condition,
257+
clusterv1.ClusterControlPlaneInitializedV1Beta2Condition,
258+
clusterv1.ClusterWorkersAvailableV1Beta2Condition,
259+
clusterv1.ClusterMachinesReadyV1Beta2Condition,
260+
clusterv1.ClusterMachinesUpToDateV1Beta2Condition,
261+
clusterv1.ClusterRemoteConnectionProbeV1Beta2Condition,
262+
clusterv1.ClusterScalingUpV1Beta2Condition,
263+
clusterv1.ClusterScalingDownV1Beta2Condition,
264+
clusterv1.ClusterRemediatingV1Beta2Condition,
265+
clusterv1.ClusterDeletingV1Beta2Condition,
266+
clusterv1.ClusterAvailableV1Beta2Condition,
267+
}},
254268
)
255269
return patchHelper.Patch(ctx, cluster, options...)
256270
}

internal/controllers/machinehealthcheck/machinehealthcheck_controller.go

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
160160
defer func() {
161161
// Always attempt to patch the object and status after each reconciliation.
162162
// Patch ObservedGeneration only if the reconciliation completed successfully
163-
patchOpts := []patch.Option{}
163+
patchOpts := []patch.Option{
164+
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
165+
clusterv1.RemediationAllowedCondition,
166+
}},
167+
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
168+
clusterv1.MachineHealthCheckRemediationAllowedV1Beta2Condition,
169+
}},
170+
}
164171
if reterr == nil {
165172
patchOpts = append(patchOpts, patch.WithStatusObservedGeneration{})
166173
}
@@ -300,7 +307,18 @@ func (r *Reconciler) reconcile(ctx context.Context, logger logr.Logger, cluster
300307
}
301308
errList := []error{}
302309
for _, t := range append(healthy, unhealthy...) {
303-
if err := t.patchHelper.Patch(ctx, t.Machine); err != nil {
310+
patchOpts := []patch.Option{
311+
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
312+
clusterv1.MachineHealthCheckSucceededCondition,
313+
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
314+
}},
315+
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
316+
clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
317+
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
318+
// (Same for ExternallyRemediated condition)
319+
}},
320+
}
321+
if err := t.patchHelper.Patch(ctx, t.Machine, patchOpts...); err != nil {
304322
errList = append(errList, errors.Wrapf(err, "failed to patch machine status for machine: %s/%s", t.Machine.Namespace, t.Machine.Name))
305323
continue
306324
}
@@ -380,7 +398,18 @@ func (r *Reconciler) patchHealthyTargets(ctx context.Context, logger logr.Logger
380398
}
381399
}
382400

383-
if err := t.patchHelper.Patch(ctx, t.Machine); err != nil {
401+
patchOpts := []patch.Option{
402+
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
403+
clusterv1.MachineHealthCheckSucceededCondition,
404+
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
405+
}},
406+
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
407+
clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
408+
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
409+
// (Same for ExternallyRemediated condition)
410+
}},
411+
}
412+
if err := t.patchHelper.Patch(ctx, t.Machine, patchOpts...); err != nil {
384413
logger.Error(err, "failed to patch healthy machine status for machine", "Machine", klog.KObj(t.Machine))
385414
errList = append(errList, errors.Wrapf(err, "failed to patch healthy machine status for machine: %s/%s", t.Machine.Namespace, t.Machine.Name))
386415
}
@@ -486,7 +515,18 @@ func (r *Reconciler) patchUnhealthyTargets(ctx context.Context, logger logr.Logg
486515
}
487516
}
488517

489-
if err := t.patchHelper.Patch(ctx, t.Machine); err != nil {
518+
patchOpts := []patch.Option{
519+
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
520+
clusterv1.MachineHealthCheckSucceededCondition,
521+
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
522+
}},
523+
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
524+
clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
525+
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
526+
// (Same for ExternallyRemediated condition)
527+
}},
528+
}
529+
if err := t.patchHelper.Patch(ctx, t.Machine, patchOpts...); err != nil {
490530
errList = append(errList, errors.Wrapf(err, "failed to patch unhealthy machine status for machine: %s/%s", t.Machine.Namespace, t.Machine.Name))
491531
continue
492532
}

0 commit comments

Comments
 (0)