Skip to content

⚠️ Drop revisionHistory in MachineDeployment #12274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions api/core/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 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.

14 changes: 0 additions & 14 deletions api/core/v1beta2/machinedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"`
Expand Down
5 changes: 0 additions & 5 deletions api/core/v1beta2/zz_generated.deepcopy.go

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

7 changes: 0 additions & 7 deletions api/core/v1beta2/zz_generated.openapi.go

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

103 changes: 0 additions & 103 deletions cmd/clusterctl/client/alpha/machinedeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
5 changes: 0 additions & 5 deletions cmd/clusterctl/client/alpha/rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
82 changes: 0 additions & 82 deletions cmd/clusterctl/client/alpha/rollout_rollbacker.go

This file was deleted.

Loading
Loading