Skip to content
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

chore: Bump golangci-lint to v1.53.2 #4326

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ linters:
- bidichk
- contextcheck
- cyclop
- depguard
- dupl
- durationcheck
- errname
Expand Down Expand Up @@ -87,8 +88,6 @@ linters-settings:
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: apierrors
- pkg: k8s.io/apimachinery/pkg/util/errors
alias: kerrors
- pkg: sigs.k8s.io/controller-runtime/pkg/conversion
Expand Down
2 changes: 1 addition & 1 deletion api/v1beta2/awscluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func TestAWSClusterValidateCreate(t *testing.T) {
g.Eventually(func() bool {
err := testEnv.Get(ctx, key, c)
return err == nil
}, 10*time.Second).Should(Equal(true))
}, 10*time.Second).Should(BeTrue())

if tt.expect != nil {
tt.expect(g, c.Spec.ControlPlaneLoadBalancer)
Expand Down
4 changes: 3 additions & 1 deletion api/v1beta2/bastion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"regexp"

"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/utils/pointer"
)

var (
Expand Down Expand Up @@ -51,12 +52,13 @@ func (b *Bastion) Validate() []*field.Error {

func validateSSHKeyName(sshKeyName *string) field.ErrorList {
var allErrs field.ErrorList
sshKey := pointer.StringDeref(sshKeyName, "")
switch {
case sshKeyName == nil:
// nil is accepted
case sshKeyName != nil && *sshKeyName == "":
// empty string is accepted
case sshKeyName != nil && !sshKeyValidNameRegex.Match([]byte(*sshKeyName)):
case sshKeyName != nil && !sshKeyValidNameRegex.MatchString(sshKey):
allErrs = append(allErrs, field.Invalid(field.NewPath("sshKeyName"), sshKeyName, "Name is invalid. Must be specified in ASCII and must not start or end in whitespace"))
}
return allErrs
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/eks/controllers/eksconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (r *EKSConfigReconciler) joinWorker(ctx context.Context, cluster *clusterv1
if !conditions.IsTrue(cluster, clusterv1.ControlPlaneInitializedCondition) {
log.Info("Control Plane has not yet been initialized")
conditions.MarkFalse(config, eksbootstrapv1.DataSecretAvailableCondition, eksbootstrapv1.WaitingForControlPlaneInitializationReason, clusterv1.ConditionSeverityInfo, "")
return ctrl.Result{}, nil
return ctrl.Result{Requeue: true}, nil
}

controlPlane := &ekscontrolplanev1.AWSManagedControlPlane{}
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/eks/controllers/eksconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestEKSConfigReconcilerReturnEarlyIfClusterControlPlaneNotInitialized(t *te

g.Eventually(func(gomega Gomega) {
result, err := reconciler.joinWorker(context.Background(), cluster, config, configOwner("Machine"))
gomega.Expect(result).To(Equal(reconcile.Result{}))
gomega.Expect(result).To(Equal(reconcile.Result{RequeueAfter: 0, Requeue: true}))
gomega.Expect(err).NotTo(HaveOccurred())
}).Should(Succeed())
}
Expand Down
18 changes: 9 additions & 9 deletions controllers/awscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ func (r *AWSClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// Handle deleted clusters
if !awsCluster.DeletionTimestamp.IsZero() {
return r.reconcileDelete(ctx, clusterScope)
return reconcile.Result{}, r.reconcileDelete(ctx, clusterScope)
}

// Handle non-deleted clusters
return r.reconcileNormal(clusterScope)
}

func (r *AWSClusterReconciler) reconcileDelete(ctx context.Context, clusterScope *scope.ClusterScope) (reconcile.Result, error) {
func (r *AWSClusterReconciler) reconcileDelete(ctx context.Context, clusterScope *scope.ClusterScope) error {
clusterScope.Info("Reconciling AWSCluster delete")

ec2svc := r.getEC2Service(clusterScope)
Expand All @@ -217,39 +217,39 @@ func (r *AWSClusterReconciler) reconcileDelete(ctx context.Context, clusterScope

if err := elbsvc.DeleteLoadbalancers(); err != nil {
clusterScope.Error(err, "error deleting load balancer")
return reconcile.Result{}, err
return err
}

if err := ec2svc.DeleteBastion(); err != nil {
clusterScope.Error(err, "error deleting bastion")
return reconcile.Result{}, err
return err
}

if err := sgService.DeleteSecurityGroups(); err != nil {
clusterScope.Error(err, "error deleting security groups")
return reconcile.Result{}, err
return err
}

if r.ExternalResourceGC {
gcSvc := gc.NewService(clusterScope, gc.WithGCStrategy(r.AlternativeGCStrategy))
if gcErr := gcSvc.ReconcileDelete(ctx); gcErr != nil {
return reconcile.Result{}, fmt.Errorf("failed delete reconcile for gc service: %w", gcErr)
return fmt.Errorf("failed delete reconcile for gc service: %w", gcErr)
}
}

if err := networkSvc.DeleteNetwork(); err != nil {
clusterScope.Error(err, "error deleting network")
return reconcile.Result{}, err
return err
}

if err := s3Service.DeleteBucket(); err != nil {
return reconcile.Result{}, errors.Wrapf(err, "error deleting S3 Bucket")
return errors.Wrapf(err, "error deleting S3 Bucket")
}

// Cluster is deleted so remove the finalizer.
controllerutil.RemoveFinalizer(clusterScope.AWSCluster, infrav1.ClusterFinalizer)

return reconcile.Result{}, nil
return nil
}

func (r *AWSClusterReconciler) reconcileNormal(clusterScope *scope.ClusterScope) (reconcile.Result, error) {
Expand Down
12 changes: 6 additions & 6 deletions controllers/awscluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
}
err := testEnv.Get(ctx, key, cluster)
return err == nil
}, 10*time.Second).Should(Equal(true))
}, 10*time.Second).Should(BeTrue())

defer teardown()
defer t.Cleanup(func() {
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
}
err := testEnv.Get(ctx, key, cluster)
return err == nil
}, 10*time.Second).Should(Equal(true))
}, 10*time.Second).Should(BeTrue())

defer teardown()
defer t.Cleanup(func() {
Expand Down Expand Up @@ -303,7 +303,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
}
err := testEnv.Get(ctx, key, cluster)
return err == nil
}, 10*time.Second).Should(Equal(true))
}, 10*time.Second).Should(BeTrue())
defer t.Cleanup(func() {
g.Expect(testEnv.Cleanup(ctx, &awsCluster, controllerIdentity, ns)).To(Succeed())
})
Expand Down Expand Up @@ -333,7 +333,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
_, err = reconciler.reconcileNormal(cs)
g.Expect(err.Error()).To(ContainSubstring("The maximum number of VPCs has been reached"))

_, err = reconciler.reconcileDelete(ctx, cs)
err = reconciler.reconcileDelete(ctx, cs)
g.Expect(err).To(BeNil())
})
t.Run("Should successfully delete AWSCluster with managed VPC", func(t *testing.T) {
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
}
err := testEnv.Get(ctx, key, cluster)
return err == nil
}, 10*time.Second).Should(Equal(true))
}, 10*time.Second).Should(BeTrue())

defer t.Cleanup(func() {
g.Expect(testEnv.Cleanup(ctx, &awsCluster, controllerIdentity, ns)).To(Succeed())
Expand Down Expand Up @@ -410,7 +410,7 @@ func TestAWSClusterReconcilerIntegrationTests(t *testing.T) {
return sgSvc
}

_, err = reconciler.reconcileDelete(ctx, cs)
err = reconciler.reconcileDelete(ctx, cs)
g.Expect(err).To(BeNil())
expectAWSClusterConditions(g, cs.AWSCluster, []conditionAssertion{{infrav1.LoadBalancerReadyCondition, corev1.ConditionFalse, clusterv1.ConditionSeverityInfo, clusterv1.DeletedReason},
{infrav1.BastionHostReadyCondition, corev1.ConditionFalse, clusterv1.ConditionSeverityInfo, clusterv1.DeletedReason},
Expand Down
12 changes: 6 additions & 6 deletions controllers/awscluster_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
},
)
g.Expect(err).To(BeNil())
_, err = reconciler.reconcileDelete(ctx, cs)
err = reconciler.reconcileDelete(ctx, cs)
g.Expect(err).To(BeNil())
g.Expect(awsCluster.GetFinalizers()).ToNot(ContainElement(infrav1.ClusterFinalizer))
})
Expand All @@ -438,7 +438,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
},
)
g.Expect(err).To(BeNil())
_, err = reconciler.reconcileDelete(ctx, cs)
err = reconciler.reconcileDelete(ctx, cs)
g.Expect(err).ToNot(BeNil())
g.Expect(awsCluster.GetFinalizers()).To(ContainElement(infrav1.ClusterFinalizer))
})
Expand All @@ -461,7 +461,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
},
)
g.Expect(err).To(BeNil())
_, err = reconciler.reconcileDelete(ctx, cs)
err = reconciler.reconcileDelete(ctx, cs)
g.Expect(err).ToNot(BeNil())
g.Expect(awsCluster.GetFinalizers()).To(ContainElement(infrav1.ClusterFinalizer))
})
Expand All @@ -485,7 +485,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
},
)
g.Expect(err).To(BeNil())
_, err = reconciler.reconcileDelete(ctx, cs)
err = reconciler.reconcileDelete(ctx, cs)
g.Expect(err).ToNot(BeNil())
g.Expect(awsCluster.GetFinalizers()).To(ContainElement(infrav1.ClusterFinalizer))
})
Expand All @@ -510,7 +510,7 @@ func TestAWSClusterReconcileOperations(t *testing.T) {
},
)
g.Expect(err).To(BeNil())
_, err = reconciler.reconcileDelete(ctx, cs)
err = reconciler.reconcileDelete(ctx, cs)
g.Expect(err).ToNot(BeNil())
g.Expect(awsCluster.GetFinalizers()).To(ContainElement(infrav1.ClusterFinalizer))
})
Expand Down Expand Up @@ -621,7 +621,7 @@ func createCluster(g *WithT, awsCluster *infrav1.AWSCluster, namespace string) {
}
err := testEnv.Get(ctx, key, cluster)
return err == nil
}, 10*time.Second).Should(Equal(true))
}, 10*time.Second).Should(BeTrue())
}
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/awsmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func createAWSMachine(g *WithT, awsMachine *infrav1.AWSMachine) {
Namespace: awsMachine.Namespace,
}
return testEnv.Get(ctx, key, machine) == nil
}, 10*time.Second).Should(Equal(true))
}, 10*time.Second).Should(BeTrue())
}

func getAWSMachine() *infrav1.AWSMachine {
Expand Down
6 changes: 1 addition & 5 deletions controllers/awsmachine_controller_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/test/mocks"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/noderefutil"
capierrors "sigs.k8s.io/cluster-api/errors"
"sigs.k8s.io/cluster-api/util"
)
Expand Down Expand Up @@ -287,9 +286,6 @@ func TestAWSMachineReconciler(t *testing.T) {
id := providerID
providerID := func(t *testing.T, g *WithT) {
t.Helper()
_, err := noderefutil.NewProviderID(id)
g.Expect(err).To(BeNil())

ms.AWSMachine.Spec.ProviderID = &id
}

Expand Down Expand Up @@ -2342,7 +2338,7 @@ func TestAWSMachineReconcilerReconcile(t *testing.T) {
}
err = testEnv.Get(ctx, key, machine)
return err == nil
}, 10*time.Second).Should(Equal(true))
}, 10*time.Second).Should(BeTrue())

result, err := reconciler.Reconcile(ctx, ctrl.Request{
NamespacedName: client.ObjectKey{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ func TestAWSControllerIdentityController(t *testing.T) {
return true
}
return false
}, 10*time.Second).Should(Equal(true))
}, 10*time.Second).Should(BeTrue())
})
}
23 changes: 12 additions & 11 deletions exp/controllers/awsmachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -164,13 +165,13 @@ func (r *AWSMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Reque
switch infraScope := infraCluster.(type) {
case *scope.ManagedControlPlaneScope:
if !awsMachinePool.ObjectMeta.DeletionTimestamp.IsZero() {
return r.reconcileDelete(machinePoolScope, infraScope, infraScope)
return ctrl.Result{}, r.reconcileDelete(machinePoolScope, infraScope, infraScope)
}

return r.reconcileNormal(ctx, machinePoolScope, infraScope, infraScope)
case *scope.ClusterScope:
if !awsMachinePool.ObjectMeta.DeletionTimestamp.IsZero() {
return r.reconcileDelete(machinePoolScope, infraScope, infraScope)
return ctrl.Result{}, r.reconcileDelete(machinePoolScope, infraScope, infraScope)
}

return r.reconcileNormal(ctx, machinePoolScope, infraScope, infraScope)
Expand Down Expand Up @@ -214,14 +215,14 @@ func (r *AWSMachinePoolReconciler) reconcileNormal(ctx context.Context, machineP
if !machinePoolScope.Cluster.Status.InfrastructureReady {
machinePoolScope.Info("Cluster infrastructure is not ready yet")
conditions.MarkFalse(machinePoolScope.AWSMachinePool, expinfrav1.ASGReadyCondition, infrav1.WaitingForClusterInfrastructureReason, clusterv1.ConditionSeverityInfo, "")
return ctrl.Result{}, nil
return ctrl.Result{Requeue: true}, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this returning true now? that would active the rate limiter, wouldn't this be just requeue when a change in the status triggers and event?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done it based on discussion here: #4321 (comment)

}

// Make sure bootstrap data is available and populated
if machinePoolScope.MachinePool.Spec.Template.Spec.Bootstrap.DataSecretName == nil {
machinePoolScope.Info("Bootstrap data secret reference is not yet available")
conditions.MarkFalse(machinePoolScope.AWSMachinePool, expinfrav1.ASGReadyCondition, infrav1.WaitingForBootstrapDataReason, clusterv1.ConditionSeverityInfo, "")
return ctrl.Result{}, nil
return ctrl.Result{RequeueAfter: time.Minute}, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

ec2Svc := r.getEC2Service(ec2Scope)
Expand Down Expand Up @@ -334,15 +335,15 @@ func (r *AWSMachinePoolReconciler) reconcileNormal(ctx context.Context, machineP
return ctrl.Result{}, nil
}

func (r *AWSMachinePoolReconciler) reconcileDelete(machinePoolScope *scope.MachinePoolScope, clusterScope cloud.ClusterScoper, ec2Scope scope.EC2Scope) (ctrl.Result, error) {
func (r *AWSMachinePoolReconciler) reconcileDelete(machinePoolScope *scope.MachinePoolScope, clusterScope cloud.ClusterScoper, ec2Scope scope.EC2Scope) error {
clusterScope.Info("Handling deleted AWSMachinePool")

ec2Svc := r.getEC2Service(ec2Scope)
asgSvc := r.getASGService(clusterScope)

asg, err := r.findASG(machinePoolScope, asgSvc)
if err != nil {
return ctrl.Result{}, err
return err
}

if asg == nil {
Expand All @@ -361,36 +362,36 @@ func (r *AWSMachinePoolReconciler) reconcileDelete(machinePoolScope *scope.Machi
machinePoolScope.Info("Deleting ASG", "id", asg.Name, "status", asg.Status)
if err := asgSvc.DeleteASGAndWait(asg.Name); err != nil {
r.Recorder.Eventf(machinePoolScope.AWSMachinePool, corev1.EventTypeWarning, "FailedDelete", "Failed to delete ASG %q: %v", asg.Name, err)
return ctrl.Result{}, errors.Wrap(err, "failed to delete ASG")
return errors.Wrap(err, "failed to delete ASG")
}
}
}

launchTemplateID := machinePoolScope.AWSMachinePool.Status.LaunchTemplateID
launchTemplate, _, err := ec2Svc.GetLaunchTemplate(machinePoolScope.LaunchTemplateName())
if err != nil {
return ctrl.Result{}, err
return err
}

if launchTemplate == nil {
machinePoolScope.Debug("Unable to locate launch template")
r.Recorder.Eventf(machinePoolScope.AWSMachinePool, corev1.EventTypeNormal, "NoASGFound", "Unable to find matching ASG")
controllerutil.RemoveFinalizer(machinePoolScope.AWSMachinePool, expinfrav1.MachinePoolFinalizer)
return ctrl.Result{}, nil
return nil
}

machinePoolScope.Info("deleting launch template", "name", launchTemplate.Name)
if err := ec2Svc.DeleteLaunchTemplate(launchTemplateID); err != nil {
r.Recorder.Eventf(machinePoolScope.AWSMachinePool, corev1.EventTypeWarning, "FailedDelete", "Failed to delete launch template %q: %v", launchTemplate.Name, err)
return ctrl.Result{}, errors.Wrap(err, "failed to delete ASG")
return errors.Wrap(err, "failed to delete ASG")
}

machinePoolScope.Info("successfully deleted AutoScalingGroup and Launch Template")

// remove finalizer
controllerutil.RemoveFinalizer(machinePoolScope.AWSMachinePool, expinfrav1.MachinePoolFinalizer)

return ctrl.Result{}, nil
return nil
}

func (r *AWSMachinePoolReconciler) updatePool(machinePoolScope *scope.MachinePoolScope, clusterScope cloud.ClusterScoper, existingASG *expinfrav1.AutoScalingGroup) error {
Expand Down
Loading