Skip to content

Commit

Permalink
Merge pull request #11396 from fabriziopandini/audit-patch-withOwnedC…
Browse files Browse the repository at this point in the history
…onditions

🌱 Audit patch withOwnedConditions
  • Loading branch information
k8s-ci-robot authored Nov 11, 2024
2 parents e22e2ca + c1b2fd2 commit 9b37a3b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
14 changes: 14 additions & 0 deletions internal/controllers/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ func patchCluster(ctx context.Context, patchHelper *patch.Helper, cluster *clust
clusterv1.ControlPlaneReadyCondition,
clusterv1.InfrastructureReadyCondition,
}},
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
clusterv1.ClusterInfrastructureReadyV1Beta2Condition,
clusterv1.ClusterControlPlaneAvailableV1Beta2Condition,
clusterv1.ClusterControlPlaneInitializedV1Beta2Condition,
clusterv1.ClusterWorkersAvailableV1Beta2Condition,
clusterv1.ClusterMachinesReadyV1Beta2Condition,
clusterv1.ClusterMachinesUpToDateV1Beta2Condition,
clusterv1.ClusterRemoteConnectionProbeV1Beta2Condition,
clusterv1.ClusterScalingUpV1Beta2Condition,
clusterv1.ClusterScalingDownV1Beta2Condition,
clusterv1.ClusterRemediatingV1Beta2Condition,
clusterv1.ClusterDeletingV1Beta2Condition,
clusterv1.ClusterAvailableV1Beta2Condition,
}},
)
return patchHelper.Patch(ctx, cluster, options...)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
defer func() {
// Always attempt to patch the object and status after each reconciliation.
// Patch ObservedGeneration only if the reconciliation completed successfully
patchOpts := []patch.Option{}
patchOpts := []patch.Option{
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
clusterv1.RemediationAllowedCondition,
}},
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
clusterv1.MachineHealthCheckRemediationAllowedV1Beta2Condition,
}},
}
if reterr == nil {
patchOpts = append(patchOpts, patch.WithStatusObservedGeneration{})
}
Expand Down Expand Up @@ -300,7 +307,18 @@ func (r *Reconciler) reconcile(ctx context.Context, logger logr.Logger, cluster
}
errList := []error{}
for _, t := range append(healthy, unhealthy...) {
if err := t.patchHelper.Patch(ctx, t.Machine); err != nil {
patchOpts := []patch.Option{
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
clusterv1.MachineHealthCheckSucceededCondition,
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
}},
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
// (Same for ExternallyRemediated condition)
}},
}
if err := t.patchHelper.Patch(ctx, t.Machine, patchOpts...); err != nil {
errList = append(errList, errors.Wrapf(err, "failed to patch machine status for machine: %s/%s", t.Machine.Namespace, t.Machine.Name))
continue
}
Expand Down Expand Up @@ -380,7 +398,18 @@ func (r *Reconciler) patchHealthyTargets(ctx context.Context, logger logr.Logger
}
}

if err := t.patchHelper.Patch(ctx, t.Machine); err != nil {
patchOpts := []patch.Option{
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
clusterv1.MachineHealthCheckSucceededCondition,
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
}},
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
// (Same for ExternallyRemediated condition)
}},
}
if err := t.patchHelper.Patch(ctx, t.Machine, patchOpts...); err != nil {
logger.Error(err, "failed to patch healthy machine status for machine", "Machine", klog.KObj(t.Machine))
errList = append(errList, errors.Wrapf(err, "failed to patch healthy machine status for machine: %s/%s", t.Machine.Namespace, t.Machine.Name))
}
Expand Down Expand Up @@ -486,7 +515,18 @@ func (r *Reconciler) patchUnhealthyTargets(ctx context.Context, logger logr.Logg
}
}

if err := t.patchHelper.Patch(ctx, t.Machine); err != nil {
patchOpts := []patch.Option{
patch.WithOwnedConditions{Conditions: []clusterv1.ConditionType{
clusterv1.MachineHealthCheckSucceededCondition,
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
}},
patch.WithOwnedV1Beta2Conditions{Conditions: []string{
clusterv1.MachineHealthCheckSucceededV1Beta2Condition,
// Note: intentionally leaving out OwnerRemediated condition which is mostly controlled by the owner.
// (Same for ExternallyRemediated condition)
}},
}
if err := t.patchHelper.Patch(ctx, t.Machine, patchOpts...); err != nil {
errList = append(errList, errors.Wrapf(err, "failed to patch unhealthy machine status for machine: %s/%s", t.Machine.Namespace, t.Machine.Name))
continue
}
Expand Down

0 comments on commit 9b37a3b

Please sign in to comment.