Skip to content

Commit d46f07c

Browse files
committed
Avoid unnecessary status updates in v1beta1 dual-write
Compare existing Deprecated.V1Beta1.Conditions with the new conditions before writing. Skip the SetV1Beta1Conditions call if Type, Status, Reason, and Message all match for every condition. This prevents unnecessary resourceVersion bumps on stable objects, which was causing the apiversion-upgrade e2e test's resource version stability check to fail.
1 parent c696836 commit d46f07c

7 files changed

Lines changed: 35 additions & 7 deletions

File tree

azure/scope/cluster.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ func (s *ClusterScope) PatchObject(ctx context.Context) error {
942942
}
943943

944944
// Populate deprecated v1beta1 conditions from v1beta2 conditions for backward compat.
945-
setV1Beta1ConditionsFromV1Beta2(s.AzureCluster, s.AzureCluster.GetConditions())
945+
setV1Beta1ConditionsFromV1Beta2(s.AzureCluster, s.AzureCluster, s.AzureCluster.GetConditions())
946946

947947
// v1beta1 owned conditions for backward compat patch conflict resolution.
948948
ownedV1Beta1Conditions := []clusterv1.ConditionType{ //nolint:staticcheck // intentional use of deprecated type for v1beta1 backward compat

azure/scope/deprecated_conditions.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@ import (
2626
// to v1beta1 format (clusterv1.Conditions) and stores them via the setter.
2727
// This populates Deprecated.V1Beta1.Conditions so that v1beta1 clients see conditions
2828
// when the v1beta2→v1beta1 conversion webhook runs.
29+
// To avoid unnecessary status updates (which bump resourceVersion), we only write
30+
// when the number of conditions changes or when a condition type/status/reason differs.
2931
//
3032
//nolint:staticcheck // intentional use of deprecated types for v1beta1 backward compat
31-
func setV1Beta1ConditionsFromV1Beta2(setter interface{ SetV1Beta1Conditions(clusterv1.Conditions) }, v1beta2Conditions []metav1.Condition) {
33+
func setV1Beta1ConditionsFromV1Beta2(
34+
getter interface{ GetV1Beta1Conditions() clusterv1.Conditions },
35+
setter interface{ SetV1Beta1Conditions(clusterv1.Conditions) },
36+
v1beta2Conditions []metav1.Condition,
37+
) {
3238
if len(v1beta2Conditions) == 0 {
3339
return
3440
}
41+
42+
// Build the new v1beta1 conditions from v1beta2.
3543
v1beta1Conds := make(clusterv1.Conditions, 0, len(v1beta2Conditions))
3644
for _, c := range v1beta2Conditions {
3745
v1beta1Conds = append(v1beta1Conds, clusterv1.Condition{
@@ -42,5 +50,25 @@ func setV1Beta1ConditionsFromV1Beta2(setter interface{ SetV1Beta1Conditions(clus
4250
Message: c.Message,
4351
})
4452
}
53+
54+
// Skip the write if the existing v1beta1 conditions already match.
55+
// This prevents unnecessary resourceVersion bumps on stable objects.
56+
existing := getter.GetV1Beta1Conditions()
57+
if len(existing) == len(v1beta1Conds) {
58+
changed := false
59+
for i := range v1beta1Conds {
60+
if existing[i].Type != v1beta1Conds[i].Type ||
61+
existing[i].Status != v1beta1Conds[i].Status ||
62+
existing[i].Reason != v1beta1Conds[i].Reason ||
63+
existing[i].Message != v1beta1Conds[i].Message {
64+
changed = true
65+
break
66+
}
67+
}
68+
if !changed {
69+
return
70+
}
71+
}
72+
4573
setter.SetV1Beta1Conditions(v1beta1Conds)
4674
}

azure/scope/machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ func (m *MachineScope) PatchObject(ctx context.Context) error {
679679
}
680680

681681
// Populate deprecated v1beta1 conditions from v1beta2 conditions for backward compat.
682-
setV1Beta1ConditionsFromV1Beta2(m.AzureMachine, m.AzureMachine.GetConditions())
682+
setV1Beta1ConditionsFromV1Beta2(m.AzureMachine, m.AzureMachine, m.AzureMachine.GetConditions())
683683

684684
// v1beta1 owned conditions for backward compat patch conflict resolution.
685685
ownedV1Beta1Conditions := []clusterv1.ConditionType{ //nolint:staticcheck // intentional use of deprecated type for v1beta1 backward compat

azure/scope/machinepool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ func (m *MachinePoolScope) PatchObject(ctx context.Context) error {
694694
}
695695

696696
// Populate deprecated v1beta1 conditions from v1beta2 conditions for backward compat.
697-
setV1Beta1ConditionsFromV1Beta2(m.AzureMachinePool, m.AzureMachinePool.GetConditions())
697+
setV1Beta1ConditionsFromV1Beta2(m.AzureMachinePool, m.AzureMachinePool, m.AzureMachinePool.GetConditions())
698698

699699
// v1beta1 owned conditions for backward compat patch conflict resolution.
700700
ownedV1Beta1Conditions := []clusterv1.ConditionType{ //nolint:staticcheck // intentional use of deprecated type for v1beta1 backward compat

azure/scope/machinepoolmachine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func (s *MachinePoolMachineScope) PatchObject(ctx context.Context) error {
321321
}
322322

323323
// Populate deprecated v1beta1 conditions from v1beta2 conditions for backward compat.
324-
setV1Beta1ConditionsFromV1Beta2(s.AzureMachinePoolMachine, s.AzureMachinePoolMachine.GetConditions())
324+
setV1Beta1ConditionsFromV1Beta2(s.AzureMachinePoolMachine, s.AzureMachinePoolMachine, s.AzureMachinePoolMachine.GetConditions())
325325

326326
// v1beta1 owned conditions for backward compat patch conflict resolution.
327327
ownedV1Beta1Conditions := []clusterv1.ConditionType{ //nolint:staticcheck // intentional use of deprecated type for v1beta1 backward compat

azure/scope/managedcontrolplane.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func (s *ManagedControlPlaneScope) PatchObject(ctx context.Context) error {
244244
}
245245

246246
// Populate deprecated v1beta1 conditions from v1beta2 conditions for backward compat.
247-
setV1Beta1ConditionsFromV1Beta2(s.ControlPlane, s.ControlPlane.GetConditions())
247+
setV1Beta1ConditionsFromV1Beta2(s.ControlPlane, s.ControlPlane, s.ControlPlane.GetConditions())
248248

249249
// v1beta1 owned conditions for backward compat patch conflict resolution.
250250
ownedV1Beta1Conditions := []clusterv1.ConditionType{ //nolint:staticcheck // intentional use of deprecated type for v1beta1 backward compat

azure/scope/managedmachinepool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (s *ManagedMachinePoolScope) PatchObject(ctx context.Context) error {
116116
}
117117

118118
// Populate deprecated v1beta1 conditions from v1beta2 conditions for backward compat.
119-
setV1Beta1ConditionsFromV1Beta2(s.InfraMachinePool, s.InfraMachinePool.GetConditions())
119+
setV1Beta1ConditionsFromV1Beta2(s.InfraMachinePool, s.InfraMachinePool, s.InfraMachinePool.GetConditions())
120120

121121
// v1beta1 owned conditions for backward compat patch conflict resolution.
122122
ownedV1Beta1Conditions := []clusterv1.ConditionType{ //nolint:staticcheck // intentional use of deprecated type for v1beta1 backward compat

0 commit comments

Comments
 (0)