Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/core/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions api/core/v1beta2/machinedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,8 @@ type MachineRollingUpdateDeployment struct {
// deletePolicy defines the policy used by the MachineDeployment to identify nodes to delete when downscaling.
// Valid values are "Random, "Newest", "Oldest"
// When no value is supplied, the default DeletePolicy of MachineSet is used
// +kubebuilder:validation:Enum=Random;Newest;Oldest
// +optional
DeletePolicy *string `json:"deletePolicy,omitempty"`
DeletePolicy *MachineSetDeletePolicy `json:"deletePolicy,omitempty"`
}

// ANCHOR_END: MachineRollingUpdateDeployment
Expand Down
4 changes: 2 additions & 2 deletions api/core/v1beta2/machineset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ type MachineSetSpec struct {

// deletePolicy defines the policy used to identify nodes to delete when downscaling.
// Defaults to "Random". Valid values are "Random, "Newest", "Oldest"
// +kubebuilder:validation:Enum=Random;Newest;Oldest
// +optional
DeletePolicy string `json:"deletePolicy,omitempty"`
DeletePolicy MachineSetDeletePolicy `json:"deletePolicy,omitempty"`

// selector is a label query over machines that should match the replica count.
// Label keys and values that must match in order to be controlled by this MachineSet.
Expand Down Expand Up @@ -249,6 +248,7 @@ type MachineTemplateSpec struct {

// MachineSetDeletePolicy defines how priority is assigned to nodes to delete when
// downscaling a MachineSet. Defaults to "Random".
// +kubebuilder:validation:Enum=Random;Newest;Oldest
type MachineSetDeletePolicy string

const (
Expand Down
2 changes: 1 addition & 1 deletion api/core/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/api/core/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions internal/api/core/v1alpha4/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestMachineDeploymentReconciler(t *testing.T) {
RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{
MaxUnavailable: intOrStrPtr(0),
MaxSurge: intOrStrPtr(1),
DeletePolicy: ptr.To("Oldest"),
DeletePolicy: ptr.To(clusterv1.OldestMachineSetDeletePolicy),
},
},
Template: clusterv1.MachineTemplateSpec{
Expand Down Expand Up @@ -204,7 +204,7 @@ func TestMachineDeploymentReconciler(t *testing.T) {
}, timeout).Should(BeEquivalentTo(1))

t.Log("Verifying that the deployment's deletePolicy was propagated to the machineset")
g.Expect(machineSets.Items[0].Spec.DeletePolicy).To(Equal("Oldest"))
g.Expect(machineSets.Items[0].Spec.DeletePolicy).To(Equal(clusterv1.OldestMachineSetDeletePolicy))

t.Log("Verifying the linked infrastructure template has a cluster owner reference")
g.Eventually(func() bool {
Expand Down Expand Up @@ -379,18 +379,18 @@ func TestMachineDeploymentReconciler(t *testing.T) {
// expect the Reconcile to be called and the MachineSet to be updated in-place.
t.Log("Updating deletePolicy on the MachineDeployment")
modifyFunc = func(d *clusterv1.MachineDeployment) {
d.Spec.Strategy.RollingUpdate.DeletePolicy = ptr.To("Newest")
d.Spec.Strategy.RollingUpdate.DeletePolicy = ptr.To(clusterv1.NewestMachineSetDeletePolicy)
}
g.Expect(updateMachineDeployment(ctx, env, deployment, modifyFunc)).To(Succeed())
g.Eventually(func(g Gomega) {
g.Expect(env.List(ctx, machineSets, msListOpts...)).Should(Succeed())
// Verify we still only have 2 MachineSets.
g.Expect(machineSets.Items).To(HaveLen(2))
// Verify the DeletePolicy value is updated
g.Expect(machineSets.Items[0].Spec.DeletePolicy).Should(Equal("Newest"))
g.Expect(machineSets.Items[0].Spec.DeletePolicy).Should(Equal(clusterv1.NewestMachineSetDeletePolicy))

// Verify that the old machine set retains its delete policy
g.Expect(machineSets.Items[1].Spec.DeletePolicy).To(Equal("Oldest"))
g.Expect(machineSets.Items[1].Spec.DeletePolicy).To(Equal(clusterv1.OldestMachineSetDeletePolicy))
}).Should(Succeed())

// Verify that all the MachineSets have the expected OwnerRef.
Expand Down Expand Up @@ -541,7 +541,7 @@ func TestMachineDeploymentReconciler_CleanUpManagedFieldsForSSAAdoption(t *testi
RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{
MaxUnavailable: intOrStrPtr(0),
MaxSurge: intOrStrPtr(1),
DeletePolicy: ptr.To("Oldest"),
DeletePolicy: ptr.To(clusterv1.OldestMachineSetDeletePolicy),
},
},
Template: clusterv1.MachineTemplateSpec{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func newTestMachineDeployment(replicas, statusReplicas, upToDateReplicas, availa
RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{
MaxUnavailable: intOrStrPtr(0),
MaxSurge: intOrStrPtr(1),
DeletePolicy: ptr.To("Oldest"),
DeletePolicy: ptr.To(clusterv1.OldestMachineSetDeletePolicy),
},
},
},
Expand Down Expand Up @@ -544,7 +544,7 @@ func TestComputeDesiredMachineSet(t *testing.T) {
Type: clusterv1.RollingUpdateMachineDeploymentStrategyType,
RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{
MaxSurge: intOrStrPtr(1),
DeletePolicy: ptr.To("Random"),
DeletePolicy: ptr.To(clusterv1.RandomMachineSetDeletePolicy),
MaxUnavailable: intOrStrPtr(0),
},
},
Expand Down Expand Up @@ -584,7 +584,7 @@ func TestComputeDesiredMachineSet(t *testing.T) {
Spec: clusterv1.MachineSetSpec{
ClusterName: "test-cluster",
Replicas: ptr.To[int32](3),
DeletePolicy: string(clusterv1.RandomMachineSetDeletePolicy),
DeletePolicy: clusterv1.RandomMachineSetDeletePolicy,
Selector: metav1.LabelSelector{MatchLabels: map[string]string{"k1": "v1"}},
Template: *deployment.Spec.Template.DeepCopy(),
MachineNamingStrategy: &clusterv1.MachineNamingStrategy{
Expand Down Expand Up @@ -640,7 +640,7 @@ func TestComputeDesiredMachineSet(t *testing.T) {
existingMS.Spec.Template.Spec.NodeDrainTimeoutSeconds = duration5s
existingMS.Spec.Template.Spec.NodeDeletionTimeoutSeconds = duration5s
existingMS.Spec.Template.Spec.NodeVolumeDetachTimeoutSeconds = duration5s
existingMS.Spec.DeletePolicy = string(clusterv1.NewestMachineSetDeletePolicy)
existingMS.Spec.DeletePolicy = clusterv1.NewestMachineSetDeletePolicy
existingMS.Spec.Template.Spec.MinReadySeconds = ptr.To[int32](0)

expectedMS := skeletonMSBasedOnMD.DeepCopy()
Expand Down Expand Up @@ -680,7 +680,7 @@ func TestComputeDesiredMachineSet(t *testing.T) {
existingMS.Spec.Template.Spec.NodeDrainTimeoutSeconds = duration5s
existingMS.Spec.Template.Spec.NodeDeletionTimeoutSeconds = duration5s
existingMS.Spec.Template.Spec.NodeVolumeDetachTimeoutSeconds = duration5s
existingMS.Spec.DeletePolicy = string(clusterv1.NewestMachineSetDeletePolicy)
existingMS.Spec.DeletePolicy = clusterv1.NewestMachineSetDeletePolicy
existingMS.Spec.Template.Spec.MinReadySeconds = ptr.To[int32](0)

oldMS := skeletonMSBasedOnMD.DeepCopy()
Expand Down Expand Up @@ -734,7 +734,7 @@ func TestComputeDesiredMachineSet(t *testing.T) {
existingMS.Spec.Template.Spec.NodeDrainTimeoutSeconds = duration5s
existingMS.Spec.Template.Spec.NodeDeletionTimeoutSeconds = duration5s
existingMS.Spec.Template.Spec.NodeVolumeDetachTimeoutSeconds = duration5s
existingMS.Spec.DeletePolicy = string(clusterv1.NewestMachineSetDeletePolicy)
existingMS.Spec.DeletePolicy = clusterv1.NewestMachineSetDeletePolicy
existingMS.Spec.Template.Spec.MinReadySeconds = ptr.To[int32](0)

expectedMS := skeletonMSBasedOnMD.DeepCopy()
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/machineset/machineset_delete_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func getMachinesToDeletePrioritized(filteredMachines []*clusterv1.Machine, diff

func getDeletePriorityFunc(ms *clusterv1.MachineSet) (deletePriorityFunc, error) {
// Map the Spec.DeletePolicy value to the appropriate delete priority function
switch msdp := clusterv1.MachineSetDeletePolicy(ms.Spec.DeletePolicy); msdp {
switch ms.Spec.DeletePolicy {
case clusterv1.RandomMachineSetDeletePolicy:
return randomDeletePolicy, nil
case clusterv1.NewestMachineSetDeletePolicy:
Expand All @@ -134,7 +134,7 @@ func getDeletePriorityFunc(ms *clusterv1.MachineSet) (deletePriorityFunc, error)
case "":
return randomDeletePolicy, nil
default:
return nil, errors.Errorf("Unsupported delete policy %s. Must be one of 'Random', 'Newest', or 'Oldest'", msdp)
return nil, errors.Errorf("Unsupported delete policy %s. Must be one of 'Random', 'Newest', or 'Oldest'", ms.Spec.DeletePolicy)
}
}

Expand Down
3 changes: 1 addition & 2 deletions internal/webhooks/machineset.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func (webhook *MachineSet) Default(ctx context.Context, obj runtime.Object) erro
m.Spec.Replicas = ptr.To[int32](replicas)

if m.Spec.DeletePolicy == "" {
randomPolicy := string(clusterv1.RandomMachineSetDeletePolicy)
m.Spec.DeletePolicy = randomPolicy
m.Spec.DeletePolicy = clusterv1.RandomMachineSetDeletePolicy
}

if m.Spec.Selector.MatchLabels == nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/webhooks/machineset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestMachineSetDefault(t *testing.T) {
g.Expect(webhook.Default(reqCtx, ms)).To(Succeed())

g.Expect(ms.Labels[clusterv1.ClusterNameLabel]).To(Equal(ms.Spec.ClusterName))
g.Expect(ms.Spec.DeletePolicy).To(Equal(string(clusterv1.RandomMachineSetDeletePolicy)))
g.Expect(ms.Spec.DeletePolicy).To(Equal(clusterv1.RandomMachineSetDeletePolicy))
g.Expect(ms.Spec.Selector.MatchLabels).To(HaveKeyWithValue(clusterv1.MachineSetNameLabel, "test-ms"))
g.Expect(ms.Spec.Template.Labels).To(HaveKeyWithValue(clusterv1.MachineSetNameLabel, "test-ms"))
g.Expect(*ms.Spec.Template.Spec.Version).To(Equal("v1.19.10"))
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/clusterclass_rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func ClusterClassRolloutSpec(ctx context.Context, inputGetter func() ClusterClas
RollingUpdate: &clusterv1.MachineRollingUpdateDeployment{
MaxUnavailable: &intstr.IntOrString{Type: intstr.Int, IntVal: 0},
MaxSurge: &intstr.IntOrString{Type: intstr.Int, IntVal: 5 + rand.Int31n(20)}, //nolint:gosec
DeletePolicy: ptr.To(string(clusterv1.NewestMachineSetDeletePolicy)),
DeletePolicy: ptr.To(clusterv1.NewestMachineSetDeletePolicy),
},
Remediation: &clusterv1.RemediationStrategy{
MaxInFlight: &intstr.IntOrString{Type: intstr.Int, IntVal: 2 + rand.Int31n(20)}, //nolint:gosec
Expand Down