Skip to content

Commit

Permalink
Move mdutil into an internal package
Browse files Browse the repository at this point in the history
Creates controllers/internal/machinedeployment
Deprecate all exported funcs and consts in controllers/mdutil

Fixes #5244
  • Loading branch information
enxebre committed Sep 23, 2021
1 parent b1f90d5 commit 89f1680
Show file tree
Hide file tree
Showing 13 changed files with 1,621 additions and 12 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha4/machinedeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ const (
// is machinedeployment.spec.replicas + maxSurge. Used by the underlying machine sets to estimate their
// proportions in case the deployment has surge replicas.
MaxReplicasAnnotation = "machinedeployment.clusters.x-k8s.io/max-replicas"

// MachineDeploymentUniqueLabel is the label applied to Machines
// in a MachineDeployment containing the hash of the template.
MachineDeploymentUniqueLabel = "machine-template-hash"
)

// ANCHOR: MachineDeploymentSpec
Expand Down
19 changes: 17 additions & 2 deletions cmd/clusterctl/client/alpha/machinedeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ limitations under the License.
package alpha

import (
"strconv"

"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"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
"sigs.k8s.io/cluster-api/controllers/mdutil"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -75,7 +78,7 @@ func findMachineDeploymentRevision(toRevision int64, allMSs []*clusterv1.Machine
previousRevision = int64(-1)
)
for _, ms := range allMSs {
if v, err := mdutil.Revision(ms); err == nil {
if v, err := revision(ms); err == nil {
if toRevision == 0 {
if latestRevision < v {
// newest one we've seen so far
Expand Down Expand Up @@ -147,3 +150,15 @@ func getMachineSetsForDeployment(proxy cluster.Proxy, d *clusterv1.MachineDeploy

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)
}
3 changes: 1 addition & 2 deletions cmd/clusterctl/client/alpha/rollout_rollbacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
"sigs.k8s.io/cluster-api/controllers/mdutil"
"sigs.k8s.io/cluster-api/util/patch"
)

Expand Down Expand Up @@ -73,7 +72,7 @@ func rollbackMachineDeployment(proxy cluster.Proxy, d *clusterv1.MachineDeployme
}
// Copy template into the machinedeployment (excluding the hash)
revMSTemplate := *msForRevision.Spec.Template.DeepCopy()
delete(revMSTemplate.Labels, mdutil.DefaultMachineDeploymentUniqueLabelKey)
delete(revMSTemplate.Labels, clusterv1.MachineDeploymentUniqueLabel)

d.Spec.Template = revMSTemplate
return patchHelper.Patch(ctx, d)
Expand Down
19 changes: 19 additions & 0 deletions controllers/internal/mdutil/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright 2021 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 machinedeployment implements MachineDeployment utilities
// meant to be consumed internally by the controller.
package mdutil
Loading

0 comments on commit 89f1680

Please sign in to comment.