From 52c532914ed4576b528cfde25ed7dd774217b769 Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Thu, 22 May 2025 20:56:50 +0200 Subject: [PATCH] Drop revisionHistory in MachineDeployment --- .golangci.yml | 4 - api/core/v1beta1/conversion_test.go | 3 + api/core/v1beta1/zz_generated.conversion.go | 3 +- api/core/v1beta2/machinedeployment_types.go | 14 - api/core/v1beta2/zz_generated.deepcopy.go | 5 - api/core/v1beta2/zz_generated.openapi.go | 7 - .../client/alpha/machinedeployment.go | 103 ------- cmd/clusterctl/client/alpha/rollout.go | 5 - .../client/alpha/rollout_rollbacker.go | 82 ------ .../client/alpha/rollout_rollbacker_test.go | 261 ------------------ cmd/clusterctl/client/client.go | 4 - cmd/clusterctl/client/client_test.go | 4 - cmd/clusterctl/client/rollout.go | 34 --- cmd/clusterctl/cmd/rollout.go | 6 +- cmd/clusterctl/cmd/rollout/undo.go | 91 ------ .../cluster.x-k8s.io_machinedeployments.yaml | 9 - .../providers/migrations/v1.10-to-v1.11.md | 7 +- .../apis/core/v1alpha3/conversion_test.go | 3 + .../core/v1alpha3/zz_generated.conversion.go | 3 +- .../apis/core/v1alpha4/conversion_test.go | 3 + .../core/v1alpha4/zz_generated.conversion.go | 3 +- .../machinedeployment_controller_test.go | 12 +- .../machinedeployment_sync.go | 14 +- .../machinedeployment/mdutil/util.go | 15 +- .../machinedeployment/mdutil/util_test.go | 6 +- internal/webhooks/machinedeployment.go | 4 - internal/webhooks/machinedeployment_test.go | 1 - 27 files changed, 41 insertions(+), 665 deletions(-) delete mode 100644 cmd/clusterctl/client/alpha/rollout_rollbacker.go delete mode 100644 cmd/clusterctl/client/alpha/rollout_rollbacker_test.go delete mode 100644 cmd/clusterctl/cmd/rollout/undo.go diff --git a/.golangci.yml b/.golangci.yml index 926236769782..02487971c0ea 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -232,10 +232,6 @@ linters: - linters: - staticcheck text: 'SA1019: (bootstrapv1.ClusterStatus|DockerMachine.Spec.Bootstrapped|machineStatus.Bootstrapped|dockerMachine.Spec.Backend.Docker.Bootstrapped|dockerMachine.Spec.Bootstrapped|devMachine.Spec.Backend.Docker.Bootstrapped|c.TopologyPlan|clusterv1.ClusterClassVariableMetadata|clusterv1beta1.ClusterClassVariableMetadata|(variable|currentDefinition|specVar|newVariableDefinition|statusVarDefinition|out).DeprecatedV1Beta1Metadata) is deprecated' - # Deprecations for MD revision management - - linters: - - staticcheck - text: 'SA1019: ((deployment|m|md).Spec.RevisionHistoryLimit|clusterv1.RevisionHistoryAnnotation|c.RolloutUndo) is deprecated' # Deprecations for MHC MaxUnhealthy, UnhealthyRange - linters: - staticcheck diff --git a/api/core/v1beta1/conversion_test.go b/api/core/v1beta1/conversion_test.go index 61dfd25bb85a..a6e53503d300 100644 --- a/api/core/v1beta1/conversion_test.go +++ b/api/core/v1beta1/conversion_test.go @@ -334,6 +334,9 @@ func spokeMachineDeploymentSpec(in *MachineDeploymentSpec, c fuzz.Continue) { // Drop ProgressDeadlineSeconds as we intentionally don't preserve it. in.ProgressDeadlineSeconds = nil + + // Drop RevisionHistoryLimit as we intentionally don't preserve it. + in.RevisionHistoryLimit = nil } func spokeMachineDeploymentStatus(in *MachineDeploymentStatus, c fuzz.Continue) { diff --git a/api/core/v1beta1/zz_generated.conversion.go b/api/core/v1beta1/zz_generated.conversion.go index 6f7b7ee13770..4508767eea2b 100644 --- a/api/core/v1beta1/zz_generated.conversion.go +++ b/api/core/v1beta1/zz_generated.conversion.go @@ -2280,7 +2280,7 @@ func autoConvert_v1beta1_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec( out.Strategy = (*v1beta2.MachineDeploymentStrategy)(unsafe.Pointer(in.Strategy)) out.MachineNamingStrategy = (*v1beta2.MachineNamingStrategy)(unsafe.Pointer(in.MachineNamingStrategy)) // WARNING: in.MinReadySeconds requires manual conversion: does not exist in peer-type - out.RevisionHistoryLimit = (*int32)(unsafe.Pointer(in.RevisionHistoryLimit)) + // WARNING: in.RevisionHistoryLimit requires manual conversion: does not exist in peer-type out.Paused = in.Paused // WARNING: in.ProgressDeadlineSeconds requires manual conversion: does not exist in peer-type return nil @@ -2296,7 +2296,6 @@ func autoConvert_v1beta2_MachineDeploymentSpec_To_v1beta1_MachineDeploymentSpec( } out.Strategy = (*MachineDeploymentStrategy)(unsafe.Pointer(in.Strategy)) out.MachineNamingStrategy = (*MachineNamingStrategy)(unsafe.Pointer(in.MachineNamingStrategy)) - out.RevisionHistoryLimit = (*int32)(unsafe.Pointer(in.RevisionHistoryLimit)) out.Paused = in.Paused return nil } diff --git a/api/core/v1beta2/machinedeployment_types.go b/api/core/v1beta2/machinedeployment_types.go index 8feabfcd0a68..5aecd24682d4 100644 --- a/api/core/v1beta2/machinedeployment_types.go +++ b/api/core/v1beta2/machinedeployment_types.go @@ -45,11 +45,6 @@ const ( // RevisionAnnotation is the revision annotation of a machine deployment's machine sets which records its rollout sequence. RevisionAnnotation = "machinedeployment.clusters.x-k8s.io/revision" - // RevisionHistoryAnnotation maintains the history of all old revisions that a machine set has served for a machine deployment. - // - // Deprecated: This annotation is deprecated and is going to be removed in the next apiVersion. Please see https://github.com/kubernetes-sigs/cluster-api/issues/10479 for more details. - RevisionHistoryAnnotation = "machinedeployment.clusters.x-k8s.io/revision-history" - // DesiredReplicasAnnotation is the desired replicas for a machine deployment recorded as an annotation // in its machine sets. Helps in separating scaling events from the rollout process and for // determining if the new machine set for a deployment is really saturated. @@ -295,15 +290,6 @@ type MachineDeploymentSpec struct { // +optional MachineNamingStrategy *MachineNamingStrategy `json:"machineNamingStrategy,omitempty"` - // revisionHistoryLimit is the number of old MachineSets to retain to allow rollback. - // This is a pointer to distinguish between explicit zero and not specified. - // Defaults to 1. - // - // Deprecated: This field is deprecated and is going to be removed in the next apiVersion. Please see https://github.com/kubernetes-sigs/cluster-api/issues/10479 for more details. - // - // +optional - RevisionHistoryLimit *int32 `json:"revisionHistoryLimit,omitempty"` - // paused indicates that the deployment is paused. // +optional Paused bool `json:"paused,omitempty"` diff --git a/api/core/v1beta2/zz_generated.deepcopy.go b/api/core/v1beta2/zz_generated.deepcopy.go index 24829834e61c..b473a9674505 100644 --- a/api/core/v1beta2/zz_generated.deepcopy.go +++ b/api/core/v1beta2/zz_generated.deepcopy.go @@ -1479,11 +1479,6 @@ func (in *MachineDeploymentSpec) DeepCopyInto(out *MachineDeploymentSpec) { *out = new(MachineNamingStrategy) **out = **in } - if in.RevisionHistoryLimit != nil { - in, out := &in.RevisionHistoryLimit, &out.RevisionHistoryLimit - *out = new(int32) - **out = **in - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineDeploymentSpec. diff --git a/api/core/v1beta2/zz_generated.openapi.go b/api/core/v1beta2/zz_generated.openapi.go index c83e5b6f4029..dfd00d483f52 100644 --- a/api/core/v1beta2/zz_generated.openapi.go +++ b/api/core/v1beta2/zz_generated.openapi.go @@ -2509,13 +2509,6 @@ func schema_cluster_api_api_core_v1beta2_MachineDeploymentSpec(ref common.Refere Ref: ref("sigs.k8s.io/cluster-api/api/core/v1beta2.MachineNamingStrategy"), }, }, - "revisionHistoryLimit": { - SchemaProps: spec.SchemaProps{ - Description: "revisionHistoryLimit is the number of old MachineSets to retain to allow rollback. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.\n\nDeprecated: This field is deprecated and is going to be removed in the next apiVersion. Please see https://github.com/kubernetes-sigs/cluster-api/issues/10479 for more details.", - Type: []string{"integer"}, - Format: "int32", - }, - }, "paused": { SchemaProps: spec.SchemaProps{ Description: "paused indicates that the deployment is paused.", diff --git a/cmd/clusterctl/client/alpha/machinedeployment.go b/cmd/clusterctl/client/alpha/machinedeployment.go index f5224a8d52de..f8ff0d7b6c06 100644 --- a/cmd/clusterctl/client/alpha/machinedeployment.go +++ b/cmd/clusterctl/client/alpha/machinedeployment.go @@ -19,21 +19,14 @@ package alpha import ( "context" "fmt" - "strconv" "time" "github.com/pkg/errors" - "k8s.io/apimachinery/pkg/api/meta" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - "k8s.io/klog/v2" "sigs.k8s.io/controller-runtime/pkg/client" clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2" "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster" - logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log" ) // getMachineDeployment retrieves the MachineDeployment object corresponding to the name and namespace specified. @@ -80,99 +73,3 @@ func patchMachineDeployment(ctx context.Context, proxy cluster.Proxy, name, name } return nil } - -// findMachineDeploymentRevision finds the specific revision in the machine sets. -func findMachineDeploymentRevision(toRevision int64, allMSs []*clusterv1.MachineSet) (*clusterv1.MachineSet, error) { - var ( - latestMachineSet *clusterv1.MachineSet - latestRevision = int64(-1) - previousMachineSet *clusterv1.MachineSet - previousRevision = int64(-1) - ) - for _, ms := range allMSs { - if v, err := revision(ms); err == nil { - switch toRevision { - case 0: - if latestRevision < v { - // newest one we've seen so far - previousRevision = latestRevision - previousMachineSet = latestMachineSet - latestRevision = v - latestMachineSet = ms - } else if previousRevision < v { - // second newest one we've seen so far - previousRevision = v - previousMachineSet = ms - } - case v: - return ms, nil - } - } - } - - if toRevision > 0 { - return nil, errors.Errorf("unable to find specified MachineDeployment revision: %v", toRevision) - } - - if previousMachineSet == nil { - return nil, errors.Errorf("no rollout history found for MachineDeployment") - } - return previousMachineSet, nil -} - -// getMachineSetsForDeployment returns a list of MachineSets associated with a MachineDeployment. -func getMachineSetsForDeployment(ctx context.Context, proxy cluster.Proxy, md *clusterv1.MachineDeployment) ([]*clusterv1.MachineSet, error) { - log := logf.Log - c, err := proxy.NewClient(ctx) - if err != nil { - return nil, err - } - // List all MachineSets to find those we own but that no longer match our selector. - machineSets := &clusterv1.MachineSetList{} - if err := c.List(ctx, machineSets, client.InNamespace(md.Namespace)); err != nil { - return nil, err - } - - filtered := make([]*clusterv1.MachineSet, 0, len(machineSets.Items)) - for idx := range machineSets.Items { - ms := &machineSets.Items[idx] - log := log.WithValues("MachineSet", klog.KObj(ms)) - - // Skip this MachineSet if its controller ref is not pointing to this MachineDeployment - if !metav1.IsControlledBy(ms, md) { - log.V(5).Info("Skipping MachineSet, controller ref does not match MachineDeployment") - continue - } - - selector, err := metav1.LabelSelectorAsSelector(&md.Spec.Selector) - if err != nil { - log.V(5).Info("Skipping MachineSet, failed to get label selector from spec selector") - continue - } - // If a MachineDeployment with a nil or empty selector creeps in, it should match nothing, not everything. - if selector.Empty() { - log.V(5).Info("Skipping MachineSet as the selector is empty") - continue - } - // Skip this MachineSet if selector does not match - if !selector.Matches(labels.Set(ms.Labels)) { - log.V(5).Info("Skipping MachineSet, label mismatch") - continue - } - filtered = append(filtered, ms) - } - - return filtered, nil -} - -func revision(obj runtime.Object) (int64, error) { - acc, err := meta.Accessor(obj) - if err != nil { - return 0, err - } - v, ok := acc.GetAnnotations()[clusterv1.RevisionAnnotation] - if !ok { - return 0, nil - } - return strconv.ParseInt(v, 10, 64) -} diff --git a/cmd/clusterctl/client/alpha/rollout.go b/cmd/clusterctl/client/alpha/rollout.go index 8736ae79df0d..c387734c583e 100644 --- a/cmd/clusterctl/client/alpha/rollout.go +++ b/cmd/clusterctl/client/alpha/rollout.go @@ -36,16 +36,11 @@ var validResourceTypes = []string{ KubeadmControlPlane, } -var validRollbackResourceTypes = []string{ - MachineDeployment, -} - // Rollout defines the behavior of a rollout implementation. type Rollout interface { ObjectRestarter(context.Context, cluster.Proxy, corev1.ObjectReference) error ObjectPauser(context.Context, cluster.Proxy, corev1.ObjectReference) error ObjectResumer(context.Context, cluster.Proxy, corev1.ObjectReference) error - ObjectRollbacker(context.Context, cluster.Proxy, corev1.ObjectReference, int64) error } var _ Rollout = &rollout{} diff --git a/cmd/clusterctl/client/alpha/rollout_rollbacker.go b/cmd/clusterctl/client/alpha/rollout_rollbacker.go deleted file mode 100644 index abd24dfdab8e..000000000000 --- a/cmd/clusterctl/client/alpha/rollout_rollbacker.go +++ /dev/null @@ -1,82 +0,0 @@ -/* -Copyright 2020 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package alpha - -import ( - "context" - - "github.com/pkg/errors" - corev1 "k8s.io/api/core/v1" - - clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2" - "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster" - logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log" - "sigs.k8s.io/cluster-api/util/patch" -) - -// ObjectRollbacker will issue a rollback on the specified cluster-api resource. -func (r *rollout) ObjectRollbacker(ctx context.Context, proxy cluster.Proxy, ref corev1.ObjectReference, toRevision int64) error { - switch ref.Kind { - case MachineDeployment: - deployment, err := getMachineDeployment(ctx, proxy, ref.Name, ref.Namespace) - if err != nil || deployment == nil { - return errors.Wrapf(err, "failed to get %v/%v", ref.Kind, ref.Name) - } - if deployment.Spec.Paused { - return errors.Errorf("can't rollback a paused MachineDeployment: please run 'clusterctl rollout resume %v/%v' first", ref.Kind, ref.Name) - } - if err := rollbackMachineDeployment(ctx, proxy, deployment, toRevision); err != nil { - return err - } - default: - return errors.Errorf("invalid resource type %q, valid values are %v", ref.Kind, validRollbackResourceTypes) - } - return nil -} - -// rollbackMachineDeployment will rollback to a previous MachineSet revision used by this MachineDeployment. -func rollbackMachineDeployment(ctx context.Context, proxy cluster.Proxy, md *clusterv1.MachineDeployment, toRevision int64) error { - log := logf.Log - c, err := proxy.NewClient(ctx) - if err != nil { - return err - } - - if toRevision < 0 { - return errors.Errorf("revision number cannot be negative: %v", toRevision) - } - msList, err := getMachineSetsForDeployment(ctx, proxy, md) - if err != nil { - return err - } - log.V(7).Info("Found MachineSets", "count", len(msList)) - msForRevision, err := findMachineDeploymentRevision(toRevision, msList) - if err != nil { - return err - } - log.V(7).Info("Found revision", "revision", msForRevision) - patchHelper, err := patch.NewHelper(md, c) - if err != nil { - return err - } - // Copy template into the machinedeployment (excluding the hash) - revMSTemplate := *msForRevision.Spec.Template.DeepCopy() - delete(revMSTemplate.Labels, clusterv1.MachineDeploymentUniqueLabel) - - md.Spec.Template = revMSTemplate - return patchHelper.Patch(ctx, md) -} diff --git a/cmd/clusterctl/client/alpha/rollout_rollbacker_test.go b/cmd/clusterctl/client/alpha/rollout_rollbacker_test.go deleted file mode 100644 index 45ce89b6e8ff..000000000000 --- a/cmd/clusterctl/client/alpha/rollout_rollbacker_test.go +++ /dev/null @@ -1,261 +0,0 @@ -/* -Copyright 2020 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package alpha - -import ( - "context" - "testing" - - . "github.com/onsi/gomega" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/ptr" - "sigs.k8s.io/controller-runtime/pkg/client" - - clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2" - "sigs.k8s.io/cluster-api/cmd/clusterctl/internal/test" -) - -func Test_ObjectRollbacker(t *testing.T) { - labels := map[string]string{ - clusterv1.ClusterNameLabel: "test", - clusterv1.MachineDeploymentNameLabel: "test-md-0", - } - currentVersion := "v1.19.3" - rollbackVersion := "v1.19.1" - deployment := &clusterv1.MachineDeployment{ - TypeMeta: metav1.TypeMeta{ - Kind: "MachineDeployment", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "test-md-0", - Namespace: "default", - Labels: map[string]string{ - clusterv1.ClusterNameLabel: "test", - }, - Annotations: map[string]string{ - clusterv1.RevisionAnnotation: "2", - }, - }, - Spec: clusterv1.MachineDeploymentSpec{ - ClusterName: "test", - Selector: metav1.LabelSelector{ - MatchLabels: map[string]string{ - clusterv1.ClusterNameLabel: "test", - }, - }, - Template: clusterv1.MachineTemplateSpec{ - ObjectMeta: clusterv1.ObjectMeta{ - Labels: labels, - }, - Spec: clusterv1.MachineSpec{ - ClusterName: "test", - Version: ¤tVersion, - InfrastructureRef: corev1.ObjectReference{ - APIVersion: clusterv1.GroupVersionInfrastructure.String(), - Kind: "InfrastructureMachineTemplate", - Name: "md-template", - }, - Bootstrap: clusterv1.Bootstrap{ - DataSecretName: ptr.To("data-secret-name"), - }, - }, - }, - }, - } - type fields struct { - objs []client.Object - ref corev1.ObjectReference - toRevision int64 - } - tests := []struct { - name string - fields fields - wantErr bool - wantVersion string - wantInfraTemplate string - wantBootsrapSecretName string - }{ - { - name: "machinedeployment should rollback to revision=1", - fields: fields{ - objs: []client.Object{ - deployment, - &clusterv1.MachineSet{ - TypeMeta: metav1.TypeMeta{ - Kind: "MachineSet", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "ms-rev-2", - Namespace: "default", - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(deployment, clusterv1.GroupVersion.WithKind("MachineDeployment")), - }, - Labels: map[string]string{ - clusterv1.ClusterNameLabel: "test", - }, - Annotations: map[string]string{ - clusterv1.RevisionAnnotation: "2", - }, - }, - }, - &clusterv1.MachineSet{ - TypeMeta: metav1.TypeMeta{ - Kind: "MachineSet", - }, - ObjectMeta: metav1.ObjectMeta{ - Namespace: "default", - Name: "ms-rev-1", - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(deployment, clusterv1.GroupVersion.WithKind("MachineDeployment")), - }, - Labels: map[string]string{ - clusterv1.ClusterNameLabel: "test", - }, - Annotations: map[string]string{ - clusterv1.RevisionAnnotation: "999", - }, - }, - Spec: clusterv1.MachineSetSpec{ - ClusterName: "test", - Selector: metav1.LabelSelector{ - MatchLabels: map[string]string{ - clusterv1.ClusterNameLabel: "test", - }, - }, - Template: clusterv1.MachineTemplateSpec{ - ObjectMeta: clusterv1.ObjectMeta{ - Labels: labels, - }, - Spec: clusterv1.MachineSpec{ - ClusterName: "test", - Version: &rollbackVersion, - InfrastructureRef: corev1.ObjectReference{ - APIVersion: clusterv1.GroupVersionInfrastructure.String(), - Kind: "InfrastructureMachineTemplate", - Name: "md-template-rollback", - }, - Bootstrap: clusterv1.Bootstrap{ - DataSecretName: ptr.To("data-secret-name-rollback"), - }, - }, - }, - }, - }, - }, - ref: corev1.ObjectReference{ - Kind: MachineDeployment, - Name: "test-md-0", - Namespace: "default", - }, - toRevision: int64(999), - }, - wantErr: false, - wantVersion: rollbackVersion, - wantInfraTemplate: "md-template-rollback", - wantBootsrapSecretName: "data-secret-name-rollback", - }, - { - name: "machinedeployment should not rollback because there is no previous revision", - fields: fields{ - objs: []client.Object{ - deployment, - &clusterv1.MachineSet{ - TypeMeta: metav1.TypeMeta{ - Kind: "MachineSet", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "ms-rev-2", - Namespace: "default", - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(deployment, clusterv1.GroupVersion.WithKind("MachineDeployment")), - }, - Labels: map[string]string{ - clusterv1.ClusterNameLabel: "test", - }, - Annotations: map[string]string{ - clusterv1.RevisionAnnotation: "2", - }, - }, - }, - }, - ref: corev1.ObjectReference{ - Kind: MachineDeployment, - Name: "test-md-0", - Namespace: "default", - }, - toRevision: int64(0), - }, - wantErr: true, - }, - { - name: "machinedeployment should not rollback because the specified version does not exist", - fields: fields{ - objs: []client.Object{ - deployment, - &clusterv1.MachineSet{ - TypeMeta: metav1.TypeMeta{ - Kind: "MachineSet", - }, - ObjectMeta: metav1.ObjectMeta{ - Name: "ms-rev-2", - Namespace: "default", - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(deployment, clusterv1.GroupVersion.WithKind("MachineDeployment")), - }, - Labels: map[string]string{ - clusterv1.ClusterNameLabel: "test", - }, - Annotations: map[string]string{ - clusterv1.RevisionAnnotation: "2", - }, - }, - }, - }, - ref: corev1.ObjectReference{ - Kind: MachineDeployment, - Name: "test-md-0", - Namespace: "default", - }, - toRevision: int64(999), - }, - wantErr: true, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - g := NewWithT(t) - r := newRolloutClient() - proxy := test.NewFakeProxy().WithObjs(tt.fields.objs...) - err := r.ObjectRollbacker(context.Background(), proxy, tt.fields.ref, tt.fields.toRevision) - if tt.wantErr { - g.Expect(err).To(HaveOccurred()) - return - } - g.Expect(err).ToNot(HaveOccurred()) - cl, err := proxy.NewClient(context.Background()) - g.Expect(err).ToNot(HaveOccurred()) - key := client.ObjectKeyFromObject(deployment) - md := &clusterv1.MachineDeployment{} - err = cl.Get(context.TODO(), key, md) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(*md.Spec.Template.Spec.Version).To(Equal(tt.wantVersion)) - g.Expect(md.Spec.Template.Spec.InfrastructureRef.Name).To(Equal(tt.wantInfraTemplate)) - g.Expect(*md.Spec.Template.Spec.Bootstrap.DataSecretName).To(Equal(tt.wantBootsrapSecretName)) - }) - } -} diff --git a/cmd/clusterctl/client/client.go b/cmd/clusterctl/client/client.go index 71095503911a..3c07bdc17a80 100644 --- a/cmd/clusterctl/client/client.go +++ b/cmd/clusterctl/client/client.go @@ -87,10 +87,6 @@ type AlphaClient interface { RolloutPause(ctx context.Context, options RolloutPauseOptions) error // RolloutResume provides rollout resume of paused cluster-api resources RolloutResume(ctx context.Context, options RolloutResumeOptions) error - // RolloutUndo provides rollout rollback of cluster-api resources - // - // Deprecated: RolloutUndo is deprecated and will be removed in one of the upcoming releases. - RolloutUndo(ctx context.Context, options RolloutUndoOptions) error // TopologyPlan dry runs the topology reconciler // // Deprecated: TopologyPlan is deprecated and will be removed in one of the upcoming releases. diff --git a/cmd/clusterctl/client/client_test.go b/cmd/clusterctl/client/client_test.go index 38abc334addb..b38d6fed395a 100644 --- a/cmd/clusterctl/client/client_test.go +++ b/cmd/clusterctl/client/client_test.go @@ -145,10 +145,6 @@ func (f fakeClient) RolloutResume(ctx context.Context, options RolloutResumeOpti return f.internalClient.RolloutResume(ctx, options) } -func (f fakeClient) RolloutUndo(ctx context.Context, options RolloutUndoOptions) error { - return f.internalClient.RolloutUndo(ctx, options) -} - func (f fakeClient) TopologyPlan(ctx context.Context, options TopologyPlanOptions) (*cluster.TopologyPlanOutput, error) { return f.internalClient.TopologyPlan(ctx, options) } diff --git a/cmd/clusterctl/client/rollout.go b/cmd/clusterctl/client/rollout.go index d30dc3665294..ce367fb0e7f8 100644 --- a/cmd/clusterctl/client/rollout.go +++ b/cmd/clusterctl/client/rollout.go @@ -69,23 +69,6 @@ type RolloutResumeOptions struct { Namespace string } -// RolloutUndoOptions carries the options supported by RolloutUndo. -type RolloutUndoOptions struct { - // Kubeconfig defines the kubeconfig to use for accessing the management cluster. If empty, - // default rules for kubeconfig discovery will be used. - Kubeconfig Kubeconfig - - // Resources for the rollout command - Resources []string - - // Namespace where the resource(s) live. If unspecified, the namespace name will be inferred - // from the current configuration. - Namespace string - - // Revision number to rollback to when issuing the undo command. - ToRevision int64 -} - func (c *clusterctlClient) RolloutRestart(ctx context.Context, options RolloutRestartOptions) error { clusterClient, err := c.clusterClientFactory(ClusterClientFactoryInput{Kubeconfig: options.Kubeconfig}) if err != nil { @@ -137,23 +120,6 @@ func (c *clusterctlClient) RolloutResume(ctx context.Context, options RolloutRes return nil } -func (c *clusterctlClient) RolloutUndo(ctx context.Context, options RolloutUndoOptions) error { - clusterClient, err := c.clusterClientFactory(ClusterClientFactoryInput{Kubeconfig: options.Kubeconfig}) - if err != nil { - return err - } - objRefs, err := getObjectRefs(clusterClient, options.Namespace, options.Resources) - if err != nil { - return err - } - for _, ref := range objRefs { - if err := c.alphaClient.Rollout().ObjectRollbacker(ctx, clusterClient.Proxy(), ref, options.ToRevision); err != nil { - return err - } - } - return nil -} - func getObjectRefs(clusterClient cluster.Client, namespace string, resources []string) ([]corev1.ObjectReference, error) { // If the option specifying the Namespace is empty, try to detect it. if namespace == "" { diff --git a/cmd/clusterctl/cmd/rollout.go b/cmd/clusterctl/cmd/rollout.go index de5c23bdb197..90593c1c3f8f 100644 --- a/cmd/clusterctl/cmd/rollout.go +++ b/cmd/clusterctl/cmd/rollout.go @@ -43,10 +43,7 @@ var ( # Resume an already paused machinedeployment or kubeadmcontrolplane clusterctl alpha rollout resume machinedeployment/my-md-0 - clusterctl alpha rollout resume kubeadmcontrolplane/my-kcp - - # Rollback a machinedeployment - clusterctl alpha rollout undo machinedeployment/my-md-0 --to-revision=3`) + clusterctl alpha rollout resume kubeadmcontrolplane/my-kcp`) rolloutCmd = &cobra.Command{ Use: "rollout SUBCOMMAND", @@ -61,5 +58,4 @@ func init() { rolloutCmd.AddCommand(rollout.NewCmdRolloutRestart(cfgFile)) rolloutCmd.AddCommand(rollout.NewCmdRolloutPause(cfgFile)) rolloutCmd.AddCommand(rollout.NewCmdRolloutResume(cfgFile)) - rolloutCmd.AddCommand(rollout.NewCmdRolloutUndo(cfgFile)) } diff --git a/cmd/clusterctl/cmd/rollout/undo.go b/cmd/clusterctl/cmd/rollout/undo.go deleted file mode 100644 index 71319d08ba7d..000000000000 --- a/cmd/clusterctl/cmd/rollout/undo.go +++ /dev/null @@ -1,91 +0,0 @@ -/* -Copyright 2020 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package rollout - -import ( - "context" - - "github.com/spf13/cobra" - - "sigs.k8s.io/cluster-api/cmd/clusterctl/client" - "sigs.k8s.io/cluster-api/cmd/clusterctl/cmd/internal/templates" -) - -// undoOptions is the start of the data required to perform the operation. -type undoOptions struct { - kubeconfig string - kubeconfigContext string - resources []string - namespace string - toRevision int64 -} - -var undoOpt = &undoOptions{} - -var ( - undoLong = templates.LongDesc(` - Rollback to a previous rollout.`) - - undoExample = templates.Examples(` - # Rollback to the previous deployment - clusterctl alpha rollout undo machinedeployment/my-md-0 - - # Rollback to previous machinedeployment --to-revision=3 - clusterctl alpha rollout undo machinedeployment/my-md-0 --to-revision=3`) -) - -// NewCmdRolloutUndo returns a Command instance for 'rollout undo' sub command. -func NewCmdRolloutUndo(cfgFile string) *cobra.Command { - cmd := &cobra.Command{ - Use: "undo RESOURCE", - DisableFlagsInUseLine: true, - Short: "Undo a cluster-api resource", - Long: undoLong, - Example: undoExample, - RunE: func(_ *cobra.Command, args []string) error { - return runUndo(cfgFile, args) - }, - } - cmd.Flags().StringVar(&undoOpt.kubeconfig, "kubeconfig", "", - "Path to the kubeconfig file to use for accessing the management cluster. If unspecified, default discovery rules apply.") - cmd.Flags().StringVar(&undoOpt.kubeconfigContext, "kubeconfig-context", "", - "Context to be used within the kubeconfig file. If empty, current context will be used.") - cmd.Flags().StringVarP(&undoOpt.namespace, "namespace", "n", "", "Namespace where the resource(s) reside. If unspecified, the defult namespace will be used.") - cmd.Flags().Int64Var(&undoOpt.toRevision, "to-revision", undoOpt.toRevision, "The revision to rollback to. Default to 0 (last revision).") - - cmd.Deprecated = "it will be removed in one of the upcoming releases.\n" - - return cmd -} - -func runUndo(cfgFile string, args []string) error { - undoOpt.resources = args - - ctx := context.Background() - - c, err := client.New(ctx, cfgFile) - if err != nil { - return err - } - - return c.RolloutUndo(ctx, client.RolloutUndoOptions{ - Kubeconfig: client.Kubeconfig{Path: undoOpt.kubeconfig, Context: undoOpt.kubeconfigContext}, - Namespace: undoOpt.namespace, - Resources: undoOpt.resources, - ToRevision: undoOpt.toRevision, - }) -} diff --git a/config/crd/bases/cluster.x-k8s.io_machinedeployments.yaml b/config/crd/bases/cluster.x-k8s.io_machinedeployments.yaml index 8e880c0ccadd..5dbdf0f6c38c 100644 --- a/config/crd/bases/cluster.x-k8s.io_machinedeployments.yaml +++ b/config/crd/bases/cluster.x-k8s.io_machinedeployments.yaml @@ -1933,15 +1933,6 @@ spec: should be later controlled by the autoscaler format: int32 type: integer - revisionHistoryLimit: - description: |- - revisionHistoryLimit is the number of old MachineSets to retain to allow rollback. - This is a pointer to distinguish between explicit zero and not specified. - Defaults to 1. - - Deprecated: This field is deprecated and is going to be removed in the next apiVersion. Please see https://github.com/kubernetes-sigs/cluster-api/issues/10479 for more details. - format: int32 - type: integer rolloutAfter: description: |- rolloutAfter is a field to indicate a rollout should be performed diff --git a/docs/book/src/developer/providers/migrations/v1.10-to-v1.11.md b/docs/book/src/developer/providers/migrations/v1.10-to-v1.11.md index 3fd2387a5877..5f978c877c0e 100644 --- a/docs/book/src/developer/providers/migrations/v1.10-to-v1.11.md +++ b/docs/book/src/developer/providers/migrations/v1.10-to-v1.11.md @@ -127,7 +127,8 @@ proposal because most of the changes described below are a consequence of the wo - Support for terminal errors has been dropped. - `status.failureReason` and `status.failureMessage` will continue to exist temporarily under `status.deprecated.v1beta1`. - The const values for `Failed` phase has been deprecated in the enum type for `status.phase` (controllers are not setting this value anymore) -- The `status.phases` field is now computed using the same logic used for `ScalingUp` and `ScalingDown` conditions. +- The `status.phases` field is now computed using the same logic used for `ScalingUp` and `ScalingDown` conditions. +- The `spec.revisionHistoryLimit` field has been removed. The MachineDeployment controller will now clean up all MachineSets without replicas. ### MachineSet @@ -311,6 +312,10 @@ TODO - `MachineDeploymentPhase`, used in `machineDeployment.status.phase` - `MachinePoolPhase`, used in `machinePool.status.phase` - `MachinePhase`, used in `machine.status.phase` + +## clusterctl changes + +* The `clusterctl alpha rollout undo` command has been removed as the corresponding revision history feature has been removed from MachineDeployment ## Removals scheduled for future releases diff --git a/internal/apis/core/v1alpha3/conversion_test.go b/internal/apis/core/v1alpha3/conversion_test.go index 2d53aa3f99ee..c3948a2c1615 100644 --- a/internal/apis/core/v1alpha3/conversion_test.go +++ b/internal/apis/core/v1alpha3/conversion_test.go @@ -161,6 +161,9 @@ func spokeMachineDeploymentSpec(in *MachineDeploymentSpec, c fuzz.Continue) { // Drop ProgressDeadlineSeconds as we intentionally don't preserve it. in.ProgressDeadlineSeconds = nil + + // Drop RevisionHistoryLimit as we intentionally don't preserve it. + in.RevisionHistoryLimit = nil } func spokeObjectMeta(in *ObjectMeta, c fuzz.Continue) { diff --git a/internal/apis/core/v1alpha3/zz_generated.conversion.go b/internal/apis/core/v1alpha3/zz_generated.conversion.go index 33e8606cb481..c0b653b1231d 100644 --- a/internal/apis/core/v1alpha3/zz_generated.conversion.go +++ b/internal/apis/core/v1alpha3/zz_generated.conversion.go @@ -813,7 +813,7 @@ func autoConvert_v1alpha3_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec out.Strategy = nil } // WARNING: in.MinReadySeconds requires manual conversion: does not exist in peer-type - out.RevisionHistoryLimit = (*int32)(unsafe.Pointer(in.RevisionHistoryLimit)) + // WARNING: in.RevisionHistoryLimit requires manual conversion: does not exist in peer-type out.Paused = in.Paused // WARNING: in.ProgressDeadlineSeconds requires manual conversion: does not exist in peer-type return nil @@ -837,7 +837,6 @@ func autoConvert_v1beta2_MachineDeploymentSpec_To_v1alpha3_MachineDeploymentSpec out.Strategy = nil } // WARNING: in.MachineNamingStrategy requires manual conversion: does not exist in peer-type - out.RevisionHistoryLimit = (*int32)(unsafe.Pointer(in.RevisionHistoryLimit)) out.Paused = in.Paused return nil } diff --git a/internal/apis/core/v1alpha4/conversion_test.go b/internal/apis/core/v1alpha4/conversion_test.go index 6b51d191349b..707bc07418d8 100644 --- a/internal/apis/core/v1alpha4/conversion_test.go +++ b/internal/apis/core/v1alpha4/conversion_test.go @@ -251,6 +251,9 @@ func spokeMachineDeploymentSpec(in *MachineDeploymentSpec, c fuzz.Continue) { // Drop ProgressDeadlineSeconds as we intentionally don't preserve it. in.ProgressDeadlineSeconds = nil + + // Drop RevisionHistoryLimit as we intentionally don't preserve it. + in.RevisionHistoryLimit = nil } func MachineHealthCheckFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} { diff --git a/internal/apis/core/v1alpha4/zz_generated.conversion.go b/internal/apis/core/v1alpha4/zz_generated.conversion.go index 4dd554472564..73d8aaffba66 100644 --- a/internal/apis/core/v1alpha4/zz_generated.conversion.go +++ b/internal/apis/core/v1alpha4/zz_generated.conversion.go @@ -1207,7 +1207,7 @@ func autoConvert_v1alpha4_MachineDeploymentSpec_To_v1beta2_MachineDeploymentSpec out.Strategy = nil } // WARNING: in.MinReadySeconds requires manual conversion: does not exist in peer-type - out.RevisionHistoryLimit = (*int32)(unsafe.Pointer(in.RevisionHistoryLimit)) + // WARNING: in.RevisionHistoryLimit requires manual conversion: does not exist in peer-type out.Paused = in.Paused // WARNING: in.ProgressDeadlineSeconds requires manual conversion: does not exist in peer-type return nil @@ -1231,7 +1231,6 @@ func autoConvert_v1beta2_MachineDeploymentSpec_To_v1alpha4_MachineDeploymentSpec out.Strategy = nil } // WARNING: in.MachineNamingStrategy requires manual conversion: does not exist in peer-type - out.RevisionHistoryLimit = (*int32)(unsafe.Pointer(in.RevisionHistoryLimit)) out.Paused = in.Paused return nil } diff --git a/internal/controllers/machinedeployment/machinedeployment_controller_test.go b/internal/controllers/machinedeployment/machinedeployment_controller_test.go index 78f014b35779..b1d9f2c67a9f 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller_test.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller_test.go @@ -106,9 +106,8 @@ func TestMachineDeploymentReconciler(t *testing.T) { }, }, Spec: clusterv1.MachineDeploymentSpec{ - ClusterName: testCluster.Name, - Replicas: ptr.To[int32](2), - RevisionHistoryLimit: ptr.To[int32](0), + ClusterName: testCluster.Name, + Replicas: ptr.To[int32](2), Selector: metav1.LabelSelector{ // We're using the same labels for spec.selector and spec.template.labels. // The labels are later changed and we will use the initial labels later to @@ -533,10 +532,9 @@ func TestMachineDeploymentReconciler_CleanUpManagedFieldsForSSAAdoption(t *testi }, }, Spec: clusterv1.MachineDeploymentSpec{ - Paused: true, // Set this to true as we do not want to test the other parts of the reconciler in this test. - ClusterName: testCluster.Name, - Replicas: ptr.To[int32](2), - RevisionHistoryLimit: ptr.To[int32](0), + Paused: true, // Set this to true as we do not want to test the other parts of the reconciler in this test. + ClusterName: testCluster.Name, + Replicas: ptr.To[int32](2), Selector: metav1.LabelSelector{ // We're using the same labels for spec.selector and spec.template.labels. MatchLabels: labels, diff --git a/internal/controllers/machinedeployment/machinedeployment_sync.go b/internal/controllers/machinedeployment/machinedeployment_sync.go index 4cc118e72506..30a096566238 100644 --- a/internal/controllers/machinedeployment/machinedeployment_sync.go +++ b/internal/controllers/machinedeployment/machinedeployment_sync.go @@ -578,16 +578,10 @@ func (r *Reconciler) scaleMachineSet(ctx context.Context, ms *clusterv1.MachineS return nil } -// cleanupDeployment is responsible for cleaning up a deployment i.e. retains all but the latest N old machine sets -// where N=d.Spec.RevisionHistoryLimit. Old machine sets are older versions of the machinetemplate of a deployment kept -// around by default 1) for historical reasons and 2) for the ability to rollback a deployment. +// cleanupDeployment is responsible for cleaning up a MachineDeployment. func (r *Reconciler) cleanupDeployment(ctx context.Context, oldMSs []*clusterv1.MachineSet, deployment *clusterv1.MachineDeployment) error { log := ctrl.LoggerFrom(ctx) - if deployment.Spec.RevisionHistoryLimit == nil { - return nil - } - // Avoid deleting machine set with deletion timestamp set aliveFilter := func(ms *clusterv1.MachineSet) bool { return ms != nil && ms.DeletionTimestamp.IsZero() @@ -595,15 +589,15 @@ func (r *Reconciler) cleanupDeployment(ctx context.Context, oldMSs []*clusterv1. cleanableMSes := mdutil.FilterMachineSets(oldMSs, aliveFilter) - diff := int32(len(cleanableMSes)) - *deployment.Spec.RevisionHistoryLimit - if diff <= 0 { + cleanableMSCount := int32(len(cleanableMSes)) + if cleanableMSCount == 0 { return nil } sort.Sort(mdutil.MachineSetsByCreationTimestamp(cleanableMSes)) log.V(4).Info("Looking to cleanup old machine sets for deployment") - for i := range diff { + for i := range cleanableMSCount { ms := cleanableMSes[i] if ms.Spec.Replicas == nil { return errors.Errorf("spec replicas for machine set %v is nil, this is unexpected", ms.Name) diff --git a/internal/controllers/machinedeployment/mdutil/util.go b/internal/controllers/machinedeployment/mdutil/util.go index be26c1ac4d67..00291a3b03d5 100644 --- a/internal/controllers/machinedeployment/mdutil/util.go +++ b/internal/controllers/machinedeployment/mdutil/util.go @@ -149,7 +149,7 @@ func Revision(obj runtime.Object) (int64, error) { var annotationsToSkip = map[string]bool{ corev1.LastAppliedConfigAnnotation: true, clusterv1.RevisionAnnotation: true, - clusterv1.RevisionHistoryAnnotation: true, + revisionHistoryAnnotation: true, clusterv1.DesiredReplicasAnnotation: true, clusterv1.MaxReplicasAnnotation: true, @@ -188,6 +188,11 @@ func getIntFromAnnotation(ms *clusterv1.MachineSet, annotationKey string, logger return int32(intValue), true } +// revisionHistoryAnnotation maintains the history of all old revisions that a machine set has served for a machine deployment. +// +// Deprecated: This annotation is deprecated and is going to be removed in the next release. +const revisionHistoryAnnotation = "machinedeployment.clusters.x-k8s.io/revision-history" + // ComputeMachineSetAnnotations computes the annotations that should be set on the MachineSet. // Note: The passed in newMS is nil if the new MachineSet doesn't exist in the apiserver yet. func ComputeMachineSetAnnotations(ctx context.Context, deployment *clusterv1.MachineDeployment, oldMSs []*clusterv1.MachineSet, newMS *clusterv1.MachineSet) (map[string]string, error) { @@ -221,18 +226,18 @@ func ComputeMachineSetAnnotations(ctx context.Context, deployment *clusterv1.Mac // Ensure we preserve the revision history annotation in any case if it already exists. // Note: With Server-Side-Apply not setting the annotation would drop it. - revisionHistory, revisionHistoryExists := newMS.Annotations[clusterv1.RevisionHistoryAnnotation] + revisionHistory, revisionHistoryExists := newMS.Annotations[revisionHistoryAnnotation] if revisionHistoryExists { - annotations[clusterv1.RevisionHistoryAnnotation] = revisionHistory + annotations[revisionHistoryAnnotation] = revisionHistory } // If the revision changes then add the old revision to the revision history annotation if currentRevisionExists && currentRevision != newRevision { oldRevisions := strings.Split(revisionHistory, ",") if oldRevisions[0] == "" { - annotations[clusterv1.RevisionHistoryAnnotation] = currentRevision + annotations[revisionHistoryAnnotation] = currentRevision } else { - annotations[clusterv1.RevisionHistoryAnnotation] = strings.Join(append(oldRevisions, currentRevision), ",") + annotations[revisionHistoryAnnotation] = strings.Join(append(oldRevisions, currentRevision), ",") } } } diff --git a/internal/controllers/machinedeployment/mdutil/util_test.go b/internal/controllers/machinedeployment/mdutil/util_test.go index f3c8554ad5b9..752106557fb9 100644 --- a/internal/controllers/machinedeployment/mdutil/util_test.go +++ b/internal/controllers/machinedeployment/mdutil/util_test.go @@ -1019,7 +1019,7 @@ func TestComputeMachineSetAnnotations(t *testing.T) { want: map[string]string{ "key1": "value1", clusterv1.RevisionAnnotation: "3", - clusterv1.RevisionHistoryAnnotation: "1", + revisionHistoryAnnotation: "1", clusterv1.DesiredReplicasAnnotation: "3", clusterv1.MaxReplicasAnnotation: "4", }, @@ -1052,7 +1052,7 @@ func TestComputeMachineSetAnnotations(t *testing.T) { want: map[string]string{ "key1": "value1", clusterv1.RevisionAnnotation: "5", - clusterv1.RevisionHistoryAnnotation: "1,2", + revisionHistoryAnnotation: "1,2", clusterv1.DesiredReplicasAnnotation: "3", clusterv1.MaxReplicasAnnotation: "4", }, @@ -1083,7 +1083,7 @@ func machineSetWithRevisionAndHistory(revision string, revisionHistory string) * }, } if revisionHistory != "" { - ms.Annotations[clusterv1.RevisionHistoryAnnotation] = revisionHistory + ms.Annotations[revisionHistoryAnnotation] = revisionHistory } return ms } diff --git a/internal/webhooks/machinedeployment.go b/internal/webhooks/machinedeployment.go index 3b5e5858340b..6222de9b7f42 100644 --- a/internal/webhooks/machinedeployment.go +++ b/internal/webhooks/machinedeployment.go @@ -100,10 +100,6 @@ func (webhook *MachineDeployment) Default(ctx context.Context, obj runtime.Objec } m.Spec.Replicas = ptr.To[int32](replicas) - if m.Spec.RevisionHistoryLimit == nil { - m.Spec.RevisionHistoryLimit = ptr.To[int32](1) - } - if m.Spec.Selector.MatchLabels == nil { m.Spec.Selector.MatchLabels = make(map[string]string) } diff --git a/internal/webhooks/machinedeployment_test.go b/internal/webhooks/machinedeployment_test.go index 8c1ec1660bcc..87c6593c5737 100644 --- a/internal/webhooks/machinedeployment_test.go +++ b/internal/webhooks/machinedeployment_test.go @@ -68,7 +68,6 @@ func TestMachineDeploymentDefault(t *testing.T) { g.Expect(md.Labels[clusterv1.ClusterNameLabel]).To(Equal(md.Spec.ClusterName)) g.Expect(md.Spec.Replicas).To(Equal(ptr.To[int32](1))) - g.Expect(md.Spec.RevisionHistoryLimit).To(Equal(ptr.To[int32](1))) g.Expect(md.Spec.Strategy).ToNot(BeNil()) g.Expect(md.Spec.Selector.MatchLabels).To(HaveKeyWithValue(clusterv1.MachineDeploymentNameLabel, "test-md"))