Skip to content

Commit 266d4fb

Browse files
authored
⚠️ Change .status.replicas fields to pointer + omitempty (#12250)
* Change .status.replicas fields to pointer + omitempty * Fix review finding, update migration doc
1 parent 9789bf9 commit 266d4fb

File tree

53 files changed

+288
-134
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+288
-134
lines changed

api/v1beta1/conversion_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,11 @@ func hubMachineSetStatus(in *clusterv1.MachineSetStatus, c fuzz.Continue) {
275275
if in.Deprecated.V1Beta1 == nil {
276276
in.Deprecated.V1Beta1 = &clusterv1.MachineSetV1Beta1DeprecatedStatus{}
277277
}
278+
// nil becomes &0 after hub => spoke => hub conversion
279+
// This is acceptable as usually Replicas is set and controllers using older apiVersions are not writing MachineSet status.
280+
if in.Replicas == nil {
281+
in.Replicas = ptr.To(int32(0))
282+
}
278283
}
279284

280285
func spokeMachineSetStatus(in *MachineSetStatus, c fuzz.Continue) {
@@ -304,6 +309,11 @@ func hubMachineDeploymentStatus(in *clusterv1.MachineDeploymentStatus, c fuzz.Co
304309
if in.Deprecated.V1Beta1 == nil {
305310
in.Deprecated.V1Beta1 = &clusterv1.MachineDeploymentV1Beta1DeprecatedStatus{}
306311
}
312+
// nil becomes &0 after hub => spoke => hub conversion
313+
// This is acceptable as usually Replicas is set and controllers using older apiVersions are not writing MachineSet status.
314+
if in.Replicas == nil {
315+
in.Replicas = ptr.To(int32(0))
316+
}
307317
}
308318

309319
func spokeMachineDeploymentSpec(in *MachineDeploymentSpec, c fuzz.Continue) {

api/v1beta1/zz_generated.conversion.go

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/machinedeployment_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ type MachineDeploymentStatus struct {
463463
// replicas is the total number of non-terminated machines targeted by this deployment
464464
// (their labels match the selector).
465465
// +optional
466-
Replicas int32 `json:"replicas"`
466+
Replicas *int32 `json:"replicas,omitempty"`
467467

468468
// readyReplicas is the number of ready replicas for this MachineDeployment. A machine is considered ready when Machine's Ready condition is true.
469469
// +optional

api/v1beta2/machineset_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ type MachineSetStatus struct {
301301

302302
// replicas is the most recently observed number of replicas.
303303
// +optional
304-
Replicas int32 `json:"replicas"`
304+
Replicas *int32 `json:"replicas,omitempty"`
305305

306306
// readyReplicas is the number of ready replicas for this MachineSet. A machine is considered ready when Machine's Ready condition is true.
307307
// +optional

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/zz_generated.openapi.go

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/kubeadm/api/v1beta1/conversion_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
fuzz "github.com/google/gofuzz"
2626
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
2727
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
28+
"k8s.io/utils/ptr"
2829

2930
bootstrapv1beta1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1"
3031
controlplanev1 "sigs.k8s.io/cluster-api/controlplane/kubeadm/api/v1beta2"
@@ -70,6 +71,12 @@ func hubKubeadmControlPlaneStatus(in *controlplanev1.KubeadmControlPlaneStatus,
7071
in.Initialization = nil
7172
}
7273
}
74+
75+
// nil becomes &0 after hub => spoke => hub conversion
76+
// This is acceptable as usually Replicas is set and controllers using older apiVersions are not writing MachineSet status.
77+
if in.Replicas == nil {
78+
in.Replicas = ptr.To(int32(0))
79+
}
7380
}
7481

7582
func spokeKubeadmControlPlaneStatus(in *KubeadmControlPlaneStatus, c fuzz.Continue) {

controlplane/kubeadm/api/v1beta1/zz_generated.conversion.go

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/kubeadm/api/v1beta2/kubeadm_control_plane_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ type KubeadmControlPlaneStatus struct {
650650
// replicas is the total number of non-terminated machines targeted by this control plane
651651
// (their labels match the selector).
652652
// +optional
653-
Replicas int32 `json:"replicas"`
653+
Replicas *int32 `json:"replicas,omitempty"`
654654

655655
// readyReplicas is the number of ready replicas for this KubeadmControlPlane. A machine is considered ready when Machine's Ready condition is true.
656656
// +optional

controlplane/kubeadm/api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)