Skip to content

Commit a8555bb

Browse files
authored
Merge pull request #1986 from sonasingh46/ifshort_linter
chore(golangci-lint): add ifshort linter
2 parents bc44584 + 53ede26 commit a8555bb

File tree

10 files changed

+14
-24
lines changed

10 files changed

+14
-24
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ linters:
2525
- gosec
2626
- gosimple
2727
- govet
28+
- ifshort
2829
- importas
2930
- ineffassign
3031
- misspell

api/v1beta1/azuremachine_default.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ import (
2828

2929
// SetDefaultSSHPublicKey sets the default SSHPublicKey for an AzureMachine.
3030
func (s *AzureMachineSpec) SetDefaultSSHPublicKey() error {
31-
sshKeyData := s.SSHPublicKey
32-
if sshKeyData == "" {
31+
if sshKeyData := s.SSHPublicKey; sshKeyData == "" {
3332
_, publicRsaKey, err := utilSSH.GenerateSSHKey()
3433
if err != nil {
3534
return err
3635
}
3736

3837
s.SSHPublicKey = base64.StdEncoding.EncodeToString(ssh.MarshalAuthorizedKey(publicRsaKey))
3938
}
40-
4139
return nil
4240
}
4341

@@ -86,8 +84,7 @@ func (s *AzureMachineSpec) SetIdentityDefaults() {
8684

8785
// SetDefaults sets to the defaults for the AzureMachineSpec.
8886
func (s *AzureMachineSpec) SetDefaults() {
89-
err := s.SetDefaultSSHPublicKey()
90-
if err != nil {
87+
if err := s.SetDefaultSSHPublicKey(); err != nil {
9188
ctrl.Log.WithName("SetDefault").Error(err, "SetDefaultSshPublicKey failed")
9289
}
9390
s.SetDefaultCachingType()

azure/scope/identity.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ func (p *AzureCredentialsProvider) GetClientSecret(ctx context.Context) (string,
200200
Name: secretRef.Name,
201201
}
202202
secret := &corev1.Secret{}
203-
err := p.Client.Get(ctx, key, secret)
204-
if err != nil {
203+
204+
if err := p.Client.Get(ctx, key, secret); err != nil {
205205
return "", errors.Wrap(err, "Unable to fetch ClientSecret")
206206
}
207207
return string(secret.Data[azureSecretKey]), nil

azure/services/agentpools/agentpools.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ func (s *Service) Reconcile(ctx context.Context) error {
9494
// cluster, normalized to reflect the input we originally provided.
9595
// AKS will populate defaults and read-only values, which we want
9696
// to strip/clean to match what we expect.
97-
isCreate := azure.ResourceNotFound(err)
98-
if isCreate {
97+
98+
if isCreate := azure.ResourceNotFound(err); isCreate {
9999
err = s.Client.CreateOrUpdate(ctx, agentPoolSpec.ResourceGroup, agentPoolSpec.Cluster, agentPoolSpec.Name, profile)
100100
if err != nil && azure.ResourceNotFound(err) {
101101
return azure.WithTransientError(errors.Wrap(err, "agent pool dependent resource does not exist yet"), 20*time.Second)

azure/services/availabilitysets/availabilitysets.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ func (s *Service) Reconcile(ctx context.Context) error {
6565
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureServiceReconcileTimeout)
6666
defer cancel()
6767

68-
setSpec := s.Scope.AvailabilitySetSpec()
6968
var err error
70-
if setSpec != nil {
69+
if setSpec := s.Scope.AvailabilitySetSpec(); setSpec != nil {
7170
_, err = s.CreateResource(ctx, setSpec, serviceName)
7271
} else {
7372
log.V(2).Info("skip creation when no availability set spec is found")
@@ -85,9 +84,8 @@ func (s *Service) Delete(ctx context.Context) error {
8584
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultAzureServiceReconcileTimeout)
8685
defer cancel()
8786

88-
setSpec := s.Scope.AvailabilitySetSpec()
8987
var resultingErr error
90-
if setSpec == nil {
88+
if setSpec := s.Scope.AvailabilitySetSpec(); setSpec == nil {
9189
log.V(2).Info("skip deletion when no availability set spec is found")
9290
} else {
9391
existingSet, err := s.Client.Get(ctx, setSpec)

exp/api/v1beta1/azuremachinepool_default.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ import (
2828

2929
// SetDefaultSSHPublicKey sets the default SSHPublicKey for an AzureMachinePool.
3030
func (amp *AzureMachinePool) SetDefaultSSHPublicKey() error {
31-
sshKeyData := amp.Spec.Template.SSHPublicKey
32-
if sshKeyData == "" {
31+
if sshKeyData := amp.Spec.Template.SSHPublicKey; sshKeyData == "" {
3332
_, publicRsaKey, err := utilSSH.GenerateSSHKey()
3433
if err != nil {
3534
return err
3635
}
3736

3837
amp.Spec.Template.SSHPublicKey = base64.StdEncoding.EncodeToString(ssh.MarshalAuthorizedKey(publicRsaKey))
3938
}
40-
4139
return nil
4240
}
4341

exp/api/v1beta1/azuremachinepool_webhook.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ var _ webhook.Defaulter = &AzureMachinePool{}
4343

4444
// Default implements webhook.Defaulter so a webhook will be registered for the type.
4545
func (amp *AzureMachinePool) Default() {
46-
err := amp.SetDefaultSSHPublicKey()
47-
if err != nil {
46+
if err := amp.SetDefaultSSHPublicKey(); err != nil {
4847
ctrl.Log.WithName("AzureMachinePoolLogger").Error(err, "SetDefaultSshPublicKey failed")
4948
}
5049
amp.SetIdentityDefaults()

exp/api/v1beta1/azuremanagedcontrolplane_default.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ const (
3434

3535
// setDefaultSSHPublicKey sets the default SSHPublicKey for an AzureManagedControlPlane.
3636
func (r *AzureManagedControlPlane) setDefaultSSHPublicKey() error {
37-
sshKeyData := r.Spec.SSHPublicKey
38-
if sshKeyData == "" {
37+
if sshKeyData := r.Spec.SSHPublicKey; sshKeyData == "" {
3938
_, publicRsaKey, err := utilSSH.GenerateSSHKey()
4039
if err != nil {
4140
return err

exp/api/v1beta1/azuremanagedcontrolplane_webhook.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ func (r *AzureManagedControlPlane) Default() {
6565
r.Spec.Version = normalizedVersion
6666
}
6767

68-
err := r.setDefaultSSHPublicKey()
69-
if err != nil {
68+
if err := r.setDefaultSSHPublicKey(); err != nil {
7069
ctrl.Log.WithName("AzureManagedControlPlaneWebHookLogger").Error(err, "SetDefaultSshPublicKey failed")
7170
}
7271

util/tele/corr_id.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ type CorrID string
5050
// fmt.Println("new corr ID: ", newCorrID)
5151
// doSomething(ctx)
5252
func ctxWithCorrID(ctx context.Context) (context.Context, CorrID) {
53-
currentCorrIDIface := ctx.Value(CorrIDKeyVal)
54-
if currentCorrIDIface != nil {
53+
if currentCorrIDIface := ctx.Value(CorrIDKeyVal); currentCorrIDIface != nil {
5554
currentCorrID, ok := currentCorrIDIface.(CorrID)
5655
if ok {
5756
return ctx, currentCorrID

0 commit comments

Comments
 (0)