Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Jul 24, 2023
1 parent cfcbf01 commit 42635c3
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 17 deletions.
3 changes: 1 addition & 2 deletions exp/api/v1alpha4/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/conversion"

expv1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
v1beta1 "sigs.k8s.io/cluster-api/exp/api/v1beta1"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
)

func Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in *v1beta1.MachinePoolSpec, out *MachinePoolSpec, s apimachineryconversion.Scope) error {
func Convert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in *expv1.MachinePoolSpec, out *MachinePoolSpec, s apimachineryconversion.Scope) error {
return autoConvert_v1beta1_MachinePoolSpec_To_v1alpha4_MachinePoolSpec(in, out, s)
}

Expand Down
1 change: 0 additions & 1 deletion internal/controllers/topology/cluster/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func (r *Reconciler) reconcileTopologyReconciledCondition(s *scope.Scope, cluste
s.Blueprint.Topology.Version,
)
reason = clusterv1.TopologyReconciledMachinePoolsUpgradeDeferredReason

}

switch {
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/topology/cluster/current_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,13 @@ func getMDClassName(cluster *clusterv1.Cluster, mdTopologyName string) (bool, st
}

// getMPClassName retrieves the MPClass name by looking up the MPTopology in the Cluster.
func getMPClassName(cluster *clusterv1.Cluster, mdTopologyName string) (bool, string) {
func getMPClassName(cluster *clusterv1.Cluster, mpTopologyName string) (bool, string) {
if cluster.Spec.Topology.Workers == nil {
return false, ""
}

for _, mdTopology := range cluster.Spec.Topology.Workers.MachineDeployments {
if mdTopology.Name == mdTopologyName {
if mdTopology.Name == mpTopologyName {
return true, mdTopology.Class
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/topology/cluster/reconcile_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ func (r *Reconciler) reconcileMachinePools(ctx context.Context, s *scope.Scope)
for _, mpTopologyName := range diff.toUpdate {
currentMP := s.Current.MachinePools[mpTopologyName]
desiredMP := s.Desired.MachinePools[mpTopologyName]
if err := r.updateMachinePool(ctx, s.Current.Cluster, mpTopologyName, currentMP, desiredMP); err != nil {
if err := r.updateMachinePool(ctx, s.Current.Cluster, currentMP, desiredMP); err != nil {
return err
}
}
Expand Down Expand Up @@ -796,7 +796,7 @@ func (r *Reconciler) createMachinePool(ctx context.Context, cluster *clusterv1.C
}

// updateMachinePool updates a MachinePool. Also rotates the corresponding Templates if necessary.
func (r *Reconciler) updateMachinePool(ctx context.Context, cluster *clusterv1.Cluster, mpTopologyName string, currentMP, desiredMP *scope.MachinePoolState) error {
func (r *Reconciler) updateMachinePool(ctx context.Context, cluster *clusterv1.Cluster, currentMP, desiredMP *scope.MachinePoolState) error {
log := tlog.LoggerFrom(ctx).WithMachinePool(desiredMP.Object)

infraCtx, _ := log.WithObject(desiredMP.InfrastructureMachinePoolObject).Into(ctx)
Expand Down
3 changes: 3 additions & 0 deletions internal/controllers/topology/cluster/scope/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ func New(cluster *clusterv1.Cluster) *Scope {

// Determine the maximum upgrade concurrency from the annotation on the cluster.
maxMDUpgradeConcurrency := 1
maxMPUpgradeConcurrency := 1
if concurrency, ok := cluster.Annotations[clusterv1.ClusterTopologyUpgradeConcurrencyAnnotation]; ok {
// The error can be ignored because the webhook ensures that the value is a positive integer.
maxMDUpgradeConcurrency, _ = strconv.Atoi(concurrency)
maxMPUpgradeConcurrency, _ = strconv.Atoi(concurrency)
}
return &Scope{
Blueprint: &ClusterBlueprint{},
Expand All @@ -61,6 +63,7 @@ func New(cluster *clusterv1.Cluster) *Scope {
},
UpgradeTracker: NewUpgradeTracker(
MaxMDUpgradeConcurrency(maxMDUpgradeConcurrency),
MaxMDUpgradeConcurrency(maxMPUpgradeConcurrency),
),
HookResponseTracker: NewHookResponseTracker(),
}
Expand Down
15 changes: 14 additions & 1 deletion internal/controllers/topology/cluster/scope/upgradetracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ func (m MaxMDUpgradeConcurrency) ApplyToUpgradeTracker(options *UpgradeTrackerOp
options.maxMDUpgradeConcurrency = int(m)
}

// MaxMPUpgradeConcurrency sets the upper limit for the number of Machine Pools that can upgrade
// concurrently.
type MaxMPUpgradeConcurrency int

// ApplyToUpgradeTracker applies the given UpgradeTrackerOptions.
func (m MaxMPUpgradeConcurrency) ApplyToUpgradeTracker(options *UpgradeTrackerOptions) {
options.maxMPUpgradeConcurrency = int(m)
}

// NewUpgradeTracker returns an upgrade tracker with empty tracking information.
func NewUpgradeTracker(opts ...UpgradeTrackerOption) *UpgradeTracker {
options := &UpgradeTrackerOptions{}
Expand All @@ -130,6 +139,10 @@ func NewUpgradeTracker(opts ...UpgradeTrackerOption) *UpgradeTracker {
// The concurrency should be at least 1.
options.maxMDUpgradeConcurrency = 1
}
if options.maxMPUpgradeConcurrency < 1 {
// The concurrency should be at least 1.
options.maxMPUpgradeConcurrency = 1
}
return &UpgradeTracker{
MachineDeployments: MachineDeploymentUpgradeTracker{
pendingCreateTopologyNames: sets.Set[string]{},
Expand All @@ -143,7 +156,7 @@ func NewUpgradeTracker(opts ...UpgradeTrackerOption) *UpgradeTracker {
pendingRollingOutNames: sets.Set[string]{},
deferredNames: sets.Set[string]{},
rollingOutNames: sets.Set[string]{},
maxMachinePoolRollOutConcurrency: options.maxMDUpgradeConcurrency,
maxMachinePoolRollOutConcurrency: options.maxMPUpgradeConcurrency,
},
}
}
Expand Down
9 changes: 0 additions & 9 deletions internal/webhooks/patch_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ func validateSelectors(selector clusterv1.PatchSelector, class *clusterv1.Cluste

if selector.MatchResources.MachineDeploymentClass != nil && len(selector.MatchResources.MachineDeploymentClass.Names) > 0 {
for i, name := range selector.MatchResources.MachineDeploymentClass.Names {
// match := false
if strings.Contains(name, "*") {
// selector can at most have a single * rune
if strings.Count(name, "*") > 1 {
Expand Down Expand Up @@ -249,18 +248,10 @@ func validateSelectors(selector clusterv1.PatchSelector, class *clusterv1.Cluste
if matches {
if selectorMatchTemplate(selector, md.Template.Infrastructure.Ref) ||
selectorMatchTemplate(selector, md.Template.Bootstrap.Ref) {
// match = true
break
}
}
}
// if !match {
// allErrs = append(allErrs, field.Invalid(
// path.Child("matchResources", "machineDeploymentClass", "names").Index(i),
// name,
// "selector is enabled but matches neither the bootstrap ref nor the infrastructure ref of a MachineDeployment class",
// ))
// }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

Expand Down

0 comments on commit 42635c3

Please sign in to comment.