Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Feb 15, 2024
1 parent b2e33b7 commit cac7281
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
24 changes: 12 additions & 12 deletions internal/webhooks/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func (webhook *Cluster) validateTopologyVersion(ctx context.Context, fldPath *fi

allErrs := field.ErrorList{}
// minor version cannot be increased if control plane is upgrading or not yet on the current version
if err := validateTopologyControlPlaneVersion(ctx, fldPath, webhook.Client, oldCluster, oldVersion); err != nil {
if err := validateTopologyControlPlaneVersion(ctx, webhook.Client, oldCluster, oldVersion); err != nil {
allErrs = append(allErrs, field.Invalid(
fldPath,
fldValue,
Expand All @@ -438,7 +438,7 @@ func (webhook *Cluster) validateTopologyVersion(ctx context.Context, fldPath *fi
}

// minor version cannot be increased if MachineDeployments are upgrading or not yet on the current version
if err := validateTopologyMachineDeploymentVersions(ctx, fldPath, webhook.Client, oldCluster, oldVersion); err != nil {
if err := validateTopologyMachineDeploymentVersions(ctx, webhook.Client, oldCluster, oldVersion); err != nil {
allErrs = append(allErrs, field.Invalid(
fldPath,
fldValue,
Expand All @@ -447,7 +447,7 @@ func (webhook *Cluster) validateTopologyVersion(ctx context.Context, fldPath *fi
}

// minor version cannot be increased if MachinePools are upgrading or not yet on the current version
if err := validateTopologyMachinePoolVersions(ctx, fldPath, webhook.Client, webhook.Tracker, oldCluster, oldVersion); err != nil {
if err := validateTopologyMachinePoolVersions(ctx, webhook.Client, webhook.Tracker, oldCluster, oldVersion); err != nil {
allErrs = append(allErrs, field.Invalid(
fldPath,
fldValue,
Expand All @@ -462,10 +462,10 @@ func (webhook *Cluster) validateTopologyVersion(ctx context.Context, fldPath *fi
return nil
}

func validateTopologyControlPlaneVersion(ctx context.Context, fldPath *field.Path, ctrlClient client.Reader, oldCluster *clusterv1.Cluster, oldVersion semver.Version) error {
func validateTopologyControlPlaneVersion(ctx context.Context, ctrlClient client.Reader, oldCluster *clusterv1.Cluster, oldVersion semver.Version) error {
cp, err := external.Get(ctx, ctrlClient, oldCluster.Spec.ControlPlaneRef, oldCluster.Namespace)
if err != nil {
return errors.Wrap(err, "failed to to get ControlPlane object")
return errors.Wrap(err, "failed to get ControlPlane object")
}

cpVersionString, err := contract.ControlPlane().Version().Get(cp)
Expand Down Expand Up @@ -503,7 +503,7 @@ func validateTopologyControlPlaneVersion(ctx context.Context, fldPath *field.Pat
return nil
}

func validateTopologyMachineDeploymentVersions(ctx context.Context, fldPath *field.Path, ctrlClient client.Reader, oldCluster *clusterv1.Cluster, oldVersion semver.Version) error {
func validateTopologyMachineDeploymentVersions(ctx context.Context, ctrlClient client.Reader, oldCluster *clusterv1.Cluster, oldVersion semver.Version) error {
// List all the machine deployments in the current cluster and in a managed topology.
mds := &clusterv1.MachineDeploymentList{}
// FROM: desired_state.go getCurrentMachineDeploymentState
Expand All @@ -515,7 +515,7 @@ func validateTopologyMachineDeploymentVersions(ctx context.Context, fldPath *fie
client.InNamespace(oldCluster.Namespace),
)
if err != nil {
return field.InternalError(fldPath, errors.Wrap(err, "failed to read MachineDeployments for managed topology"))
return errors.Wrap(err, "failed to read MachineDeployments for managed topology")
}

if len(mds.Items) == 0 {
Expand All @@ -530,7 +530,7 @@ func validateTopologyMachineDeploymentVersions(ctx context.Context, fldPath *fie
mdVersion, err := semver.ParseTolerant(*md.Spec.Template.Spec.Version)
if err != nil {
// NOTE: this should never happen. Nevertheless, handling this for extra caution.
return field.InternalError(fldPath, errors.Wrapf(err, "failed to parse MachineDeployment's %q version %q", klog.KObj(md), *md.Spec.Template.Spec.Version))
return errors.Wrapf(err, "failed to parse MachineDeployment's %q version %q", klog.KObj(md), *md.Spec.Template.Spec.Version)
}

if mdVersion.NE(oldVersion) {
Expand All @@ -554,7 +554,7 @@ func validateTopologyMachineDeploymentVersions(ctx context.Context, fldPath *fie
return nil
}

func validateTopologyMachinePoolVersions(ctx context.Context, fldPath *field.Path, ctrlClient client.Reader, tracker ClusterCacheTrackerReader, oldCluster *clusterv1.Cluster, oldVersion semver.Version) error {
func validateTopologyMachinePoolVersions(ctx context.Context, ctrlClient client.Reader, tracker ClusterCacheTrackerReader, oldCluster *clusterv1.Cluster, oldVersion semver.Version) error {
// FROM: desired_state.go getCurrentMachinePoolState

// List all the machine pools in the current cluster and in a managed topology.
Expand All @@ -567,7 +567,7 @@ func validateTopologyMachinePoolVersions(ctx context.Context, fldPath *field.Pat
client.InNamespace(oldCluster.Namespace),
)
if err != nil {
return field.InternalError(fldPath, errors.Wrap(err, "failed to read MachinePools for managed topology"))
return errors.Wrap(err, "failed to read MachinePools for managed topology")
}

// Return early
Expand All @@ -577,7 +577,7 @@ func validateTopologyMachinePoolVersions(ctx context.Context, fldPath *field.Pat

wlClient, err := tracker.GetReader(ctx, client.ObjectKeyFromObject(oldCluster))
if err != nil {
return field.InternalError(fldPath, errors.Wrap(err, "unable to get client for workload cluster"))
return errors.Wrap(err, "unable to get client for workload cluster")
}

mpUpgradingNames := []string{}
Expand All @@ -588,7 +588,7 @@ func validateTopologyMachinePoolVersions(ctx context.Context, fldPath *field.Pat
mpVersion, err := semver.ParseTolerant(*mp.Spec.Template.Spec.Version)
if err != nil {
// NOTE: this should never happen. Nevertheless, handling this for extra caution.
return field.InternalError(fldPath, errors.Wrapf(err, "failed to parse MachinePool's %q version %q", klog.KObj(mp), *mp.Spec.Template.Spec.Version))
return errors.Wrapf(err, "failed to parse MachinePool's %q version %q", klog.KObj(mp), *mp.Spec.Template.Spec.Version)
}

if mpVersion.NE(oldVersion) {
Expand Down
10 changes: 3 additions & 7 deletions internal/webhooks/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
utilfeature "k8s.io/component-base/featuregate/testing"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -2539,7 +2538,6 @@ func Test_validateTopologyControlPlaneVersion(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

fldPath := field.NewPath("spec", "topology", "version")
fakeClient := fake.NewClientBuilder().
WithObjects(tt.additionalObjects...).
WithScheme(fakeScheme).
Expand All @@ -2548,7 +2546,7 @@ func Test_validateTopologyControlPlaneVersion(t *testing.T) {
oldVersion, err := semver.ParseTolerant(tt.old.Spec.Topology.Version)
g.Expect(err).ToNot(HaveOccurred())

err = validateTopologyControlPlaneVersion(ctx, fldPath, fakeClient, tt.old, oldVersion)
err = validateTopologyControlPlaneVersion(ctx, fakeClient, tt.old, oldVersion)
if tt.expectErr {
g.Expect(err).To(HaveOccurred())
return
Expand Down Expand Up @@ -2649,7 +2647,6 @@ func Test_validateTopologyMachineDeploymentVersions(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

fldPath := field.NewPath("spec", "topology", "version")
fakeClient := fake.NewClientBuilder().
WithObjects(tt.additionalObjects...).
WithScheme(fakeScheme).
Expand All @@ -2658,7 +2655,7 @@ func Test_validateTopologyMachineDeploymentVersions(t *testing.T) {
oldVersion, err := semver.ParseTolerant(tt.old.Spec.Topology.Version)
g.Expect(err).ToNot(HaveOccurred())

err = validateTopologyMachineDeploymentVersions(ctx, fldPath, fakeClient, tt.old, oldVersion)
err = validateTopologyMachineDeploymentVersions(ctx, fakeClient, tt.old, oldVersion)
if tt.expectErr {
g.Expect(err).To(HaveOccurred())
return
Expand Down Expand Up @@ -2786,7 +2783,6 @@ func Test_validateTopologyMachinePoolVersions(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

fldPath := field.NewPath("spec", "topology", "version")
fakeClient := fake.NewClientBuilder().
WithObjects(tt.additionalObjects...).
WithScheme(fakeScheme).
Expand All @@ -2801,7 +2797,7 @@ func Test_validateTopologyMachinePoolVersions(t *testing.T) {
Build(),
}

err = validateTopologyMachinePoolVersions(ctx, fldPath, fakeClient, fakeClusterCacheTracker, tt.old, oldVersion)
err = validateTopologyMachinePoolVersions(ctx, fakeClient, fakeClusterCacheTracker, tt.old, oldVersion)
if tt.expectErr {
g.Expect(err).To(HaveOccurred())
return
Expand Down

0 comments on commit cac7281

Please sign in to comment.