Skip to content

Commit 6faee1e

Browse files
coillteoirDavid Lynch
andauthored
chore(lints): ran golangci-lint run --fix on codebase (#1725)
Co-authored-by: David Lynch <david.lynch@workday.com>
1 parent c8a1230 commit 6faee1e

21 files changed

Lines changed: 83 additions & 82 deletions

controllers/tc009990_mtls_generate_creds_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func Test_009990_mtls_generate_creds_test(t *testing.T) {
142142
g.Expect(caValid).To(BeTrue())
143143

144144
By("verifying that the runner cert secret has the appropriate labels")
145-
labels := runnerSecret.ObjectMeta.GetLabels()
145+
labels := runnerSecret.GetLabels()
146146
g.Expect(labels).To(HaveKey(infrav1.RunnerLabel))
147147

148148
By("verifying that the runner cert is valid for a range of hostnames in a given namespace")

controllers/tf_controller.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (r *TerraformReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
131131
<-r.CertRotator.Ready
132132

133133
traceLog.Info("Validate TLS Cert")
134-
if isCAValid, _ := r.CertRotator.IsCAValid(); isCAValid == false && r.CertRotator.TriggerCARotation != nil {
134+
if isCAValid, _ := r.CertRotator.IsCAValid(); !isCAValid && r.CertRotator.TriggerCARotation != nil {
135135
traceLog.Info("TLS Cert invalid")
136136
readyCh := make(chan *mtls.TriggerResult)
137137
traceLog.Info("Trigger Cert Rotation")
@@ -169,7 +169,7 @@ func (r *TerraformReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
169169
}
170170

171171
// Record the duration of the reconciliation.
172-
r.Metrics.RecordDuration(ctx, terraform, startTime)
172+
r.RecordDuration(ctx, terraform, startTime)
173173
}()
174174

175175
// Make sure the Finalizer exists
@@ -472,7 +472,7 @@ func (r *TerraformReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
472472

473473
// Examine if the object is under deletion
474474
traceLog.Info("Check for deletion timestamp to finalize")
475-
if !terraform.ObjectMeta.DeletionTimestamp.IsZero() {
475+
if !terraform.DeletionTimestamp.IsZero() {
476476
traceLog.Info("Calling finalize function")
477477
if terraform, result, err := r.finalize(ctx, patchHelper, terraform, runnerClient, sourceObj, reconciliationLoopID); err != nil {
478478
traceLog.Info("Patch the status of the Terraform resource")
@@ -641,7 +641,7 @@ func (r *TerraformReconciler) shouldReconcile(terraform *infrav1.Terraform, sour
641641
}
642642

643643
func isBeingDeleted(terraform *infrav1.Terraform) bool {
644-
return !terraform.ObjectMeta.DeletionTimestamp.IsZero()
644+
return !terraform.DeletionTimestamp.IsZero()
645645
}
646646

647647
// SetupWithManager sets up the controller with the Manager.
@@ -733,7 +733,7 @@ func (r *TerraformReconciler) checkDependencies(ctx context.Context, terraform *
733733

734734
// Check whether the dependent Terraform isn't being deleted, and then add a
735735
// a finalizer if it is missing
736-
if tDep.ObjectMeta.DeletionTimestamp.IsZero() && !controllerutil.ContainsFinalizer(tDep, finalizerKey) {
736+
if tDep.DeletionTimestamp.IsZero() && !controllerutil.ContainsFinalizer(tDep, finalizerKey) {
737737
patch := client.MergeFrom(tDep.DeepCopy())
738738
controllerutil.AddFinalizer(tDep, finalizerKey)
739739
if err := r.Patch(context.Background(), tDep, patch, client.FieldOwner(r.FieldManager)); err != nil {
@@ -811,8 +811,8 @@ func (r *TerraformReconciler) requestsForRevisionChangeOf(indexKey string) handl
811811
}
812812
reqs := make([]reconcile.Request, len(sorted))
813813
for i, t := range sorted {
814-
reqs[i].NamespacedName.Name = t.Name
815-
reqs[i].NamespacedName.Namespace = t.Namespace
814+
reqs[i].Name = t.Name
815+
reqs[i].Namespace = t.Namespace
816816
}
817817
return reqs
818818
}
@@ -841,7 +841,7 @@ func (r *TerraformReconciler) getSource(ctx context.Context, terraform *infrav1.
841841
switch terraform.Spec.SourceRef.Kind {
842842
case sourcev1.GitRepositoryKind:
843843
var repository sourcev1.GitRepository
844-
err := r.Client.Get(ctx, sourceReference, &repository)
844+
err := r.Get(ctx, sourceReference, &repository)
845845
if err != nil {
846846
if apierrors.IsNotFound(err) {
847847
return sourceObj, err
@@ -851,7 +851,7 @@ func (r *TerraformReconciler) getSource(ctx context.Context, terraform *infrav1.
851851
sourceObj = &repository
852852
case sourcev1.BucketKind:
853853
var bucket sourcev1.Bucket
854-
err := r.Client.Get(ctx, sourceReference, &bucket)
854+
err := r.Get(ctx, sourceReference, &bucket)
855855
if err != nil {
856856
if apierrors.IsNotFound(err) {
857857
return sourceObj, err
@@ -861,7 +861,7 @@ func (r *TerraformReconciler) getSource(ctx context.Context, terraform *infrav1.
861861
sourceObj = &bucket
862862
case sourcev1.OCIRepositoryKind:
863863
var repository sourcev1.OCIRepository
864-
err := r.Client.Get(ctx, sourceReference, &repository)
864+
err := r.Get(ctx, sourceReference, &repository)
865865
if err != nil {
866866
if apierrors.IsNotFound(err) {
867867
return sourceObj, err

controllers/tf_controller_apply.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (r *TerraformReconciler) apply(ctx context.Context, patchHelper *patch.Seri
100100

101101
// this a special case, when backend is completely disabled.
102102
// we need to use "destroy" command instead of apply
103-
if r.backendCompletelyDisable(terraform) && terraform.Spec.Destroy == true {
103+
if r.backendCompletelyDisable(terraform) && terraform.Spec.Destroy {
104104
destroyReply, err := runnerClient.Destroy(ctx, &runner.DestroyRequest{
105105
TfInstance: tfInstance,
106106
Targets: terraform.Spec.Targets,
@@ -120,7 +120,7 @@ func (r *TerraformReconciler) apply(ctx context.Context, patchHelper *patch.Seri
120120
}
121121
}
122122

123-
if eventSent == false {
123+
if !eventSent {
124124
msg := fmt.Sprintf("Destroy error: %s", err.Error())
125125
r.Eventf(terraform, corev1.EventTypeWarning, infrav1.TFExecDestroyFailedReason, msg)
126126
}
@@ -149,7 +149,7 @@ func (r *TerraformReconciler) apply(ctx context.Context, patchHelper *patch.Seri
149149
}
150150
}
151151

152-
if eventSent == false {
152+
if !eventSent {
153153
msg := fmt.Sprintf("Apply error: %s", err.Error())
154154
r.Eventf(terraform, corev1.EventTypeWarning, infrav1.TFExecApplyFailedReason, msg)
155155
}
@@ -167,7 +167,7 @@ func (r *TerraformReconciler) apply(ctx context.Context, patchHelper *patch.Seri
167167
isDestroyApplied = terraform.Status.Plan.IsDestroyPlan
168168

169169
// if apply was successful, we need to update the inventory, but not if we are destroying
170-
if terraform.Spec.EnableInventory && isDestroyApplied == false {
170+
if terraform.Spec.EnableInventory && !isDestroyApplied {
171171
getInventoryRequest := &runner.GetInventoryRequest{TfInstance: tfInstance}
172172
getInventoryReply, err := runnerClient.GetInventory(ctx, getInventoryRequest)
173173
if err != nil {
@@ -189,18 +189,18 @@ func (r *TerraformReconciler) apply(ctx context.Context, patchHelper *patch.Seri
189189
})
190190
}
191191
log.Info(fmt.Sprintf("got inventory - entries count: %d", len(inventoryEntries)))
192-
} else if terraform.Spec.EnableInventory == false {
192+
} else if !terraform.Spec.EnableInventory {
193193
log.Info("inventory is disabled")
194194
terraform.Status.Inventory = nil
195195
}
196196
}
197197

198198
var msg string
199199
if isDestroyApplied {
200-
msg = fmt.Sprintf("Destroy applied successfully")
200+
msg = "Destroy applied successfully"
201201
r.Eventf(terraform, corev1.EventTypeNormal, infrav1.TFExecDestroySucceedReason, msg)
202202
} else {
203-
msg = fmt.Sprintf("Applied successfully")
203+
msg = "Applied successfully"
204204
r.Eventf(terraform, corev1.EventTypeNormal, infrav1.TFExecApplySucceedReason, msg)
205205
}
206206

controllers/tf_controller_backend.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (r *TerraformReconciler) backendCompletelyDisable(terraform *infrav1.Terraf
2222
return true
2323
}
2424

25-
return terraform.Spec.BackendConfig != nil && terraform.Spec.BackendConfig.Disable == true
25+
return terraform.Spec.BackendConfig != nil && terraform.Spec.BackendConfig.Disable
2626
}
2727

2828
func (r *TerraformReconciler) setupTerraform(ctx context.Context, patchHelper *patch.SerialPatcher, runnerClient runner.RunnerClient, terraform *infrav1.Terraform, sourceObj sourcev1.Source, revision string, reconciliationLoopID string) (*infrav1.Terraform, string, string, error) {
@@ -233,14 +233,14 @@ terraform {
233233

234234
if env.ValueFrom.SecretKeyRef != nil {
235235
secret := corev1.Secret{}
236-
err = r.Client.Get(ctx, types.NamespacedName{
236+
err = r.Get(ctx, types.NamespacedName{
237237
Namespace: terraform.GetObjectMeta().GetNamespace(),
238238
Name: env.ValueFrom.SecretKeyRef.Name,
239239
}, &secret)
240240
envs[env.Name] = string(secret.Data[env.ValueFrom.SecretKeyRef.Key])
241241
} else if env.ValueFrom.ConfigMapKeyRef != nil {
242242
cm := corev1.ConfigMap{}
243-
err = r.Client.Get(ctx, types.NamespacedName{
243+
err = r.Get(ctx, types.NamespacedName{
244244
Namespace: terraform.GetObjectMeta().GetNamespace(),
245245
Name: env.ValueFrom.ConfigMapKeyRef.Name,
246246
}, &cm)

controllers/tf_controller_drift_detect.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ func (r *TerraformReconciler) shouldDetectDrift(terraform *infrav1.Terraform, re
1616
// Please do not optimize this logic, as we'd like others to easily understand the logics behind this behaviour.
1717

1818
// return false when drift detection is disabled
19-
if terraform.Spec.DisableDriftDetection == true {
19+
if terraform.Spec.DisableDriftDetection {
2020
return false
2121
}
2222

2323
// not support when Destroy == true
24-
if terraform.Spec.Destroy == true {
24+
if terraform.Spec.Destroy {
2525
return false
2626
}
2727

@@ -99,7 +99,7 @@ func (r *TerraformReconciler) detectDrift(ctx context.Context, terraform *infrav
9999
}
100100
}
101101

102-
if eventSent == false {
102+
if !eventSent {
103103
msg := fmt.Sprintf("Drift detection error: %s", err.Error())
104104
r.Eventf(terraform, corev1.EventTypeWarning, infrav1.DriftDetectionFailedReason, msg)
105105
}

controllers/tf_controller_finalizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (r *TerraformReconciler) finalize(ctx context.Context, patchHelper *patch.S
8383
return terraform, controllerruntime.Result{Requeue: true}, err
8484
}
8585

86-
if thereIsNothingToDestroy(terraform) == false {
86+
if !thereIsNothingToDestroy(terraform) {
8787
traceLog.Info("Apply the destroy plan")
8888
terraform, err = r.apply(ctx, patchHelper, terraform, tfInstance, runnerClient, revision)
8989
traceLog.Info("Check for error")

controllers/tf_controller_health_checks.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ func (r *TerraformReconciler) shouldDoHealthChecks(terraform *infrav1.Terraform)
3131
var applyCondition metav1.Condition
3232
var hcCondition metav1.Condition
3333
for _, c := range terraform.Status.Conditions {
34-
if c.Type == infrav1.ConditionTypeApply {
34+
switch c.Type {
35+
case infrav1.ConditionTypeApply:
3536
applyCondition = c
36-
} else if c.Type == infrav1.ConditionTypeHealthCheck {
37+
case infrav1.ConditionTypeHealthCheck:
3738
hcCondition = c
3839
}
3940
}

controllers/tf_controller_outputs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ func (r *TerraformReconciler) outputsMayBeDrifted(ctx context.Context, terraform
3535
if terraform.Spec.WriteOutputsToSecret != nil {
3636
outputsSecretKey := types.NamespacedName{Namespace: terraform.Namespace, Name: terraform.Spec.WriteOutputsToSecret.Name}
3737
var outputsSecret corev1.Secret
38-
err := r.Client.Get(ctx, outputsSecretKey, &outputsSecret)
38+
err := r.Get(ctx, outputsSecretKey, &outputsSecret)
3939
if err != nil && apierrors.IsNotFound(err) {
4040
return true, nil
4141
}
4242

4343
keysInSecret := []string{}
44-
for k, _ := range outputsSecret.Data {
44+
for k := range outputsSecret.Data {
4545
keysInSecret = append(keysInSecret, k)
4646
}
4747
sort.Strings(keysInSecret)
@@ -168,7 +168,7 @@ func (r *TerraformReconciler) writeOutput(ctx context.Context, terraform *infrav
168168
}
169169
}
170170

171-
if len(data) == 0 || terraform.Spec.Destroy == true {
171+
if len(data) == 0 || terraform.Spec.Destroy {
172172
return infrav1.TerraformOutputsWritten(terraform, revision, "No Outputs written"), nil
173173
}
174174

@@ -193,7 +193,7 @@ func (r *TerraformReconciler) writeOutput(ctx context.Context, terraform *infrav
193193

194194
if writeOutputsReply.Changed {
195195
keysWritten := []string{}
196-
for k, _ := range data {
196+
for k := range data {
197197
keysWritten = append(keysWritten, k)
198198
}
199199
msg := fmt.Sprintf("Outputs written.\n%d output(s): %s", len(keysWritten), strings.Join(keysWritten, ", "))

controllers/tf_controller_plan.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (r *TerraformReconciler) plan(ctx context.Context, patchHelper *patch.Seria
5757

5858
// check if destroy is set to true or
5959
// the object is being deleted and DestroyResourcesOnDeletion is set to true
60-
if terraform.Spec.Destroy || (!terraform.ObjectMeta.DeletionTimestamp.IsZero() && terraform.Spec.DestroyResourcesOnDeletion) {
60+
if terraform.Spec.Destroy || (!terraform.DeletionTimestamp.IsZero() && terraform.Spec.DestroyResourcesOnDeletion) {
6161
log.Info("plan to destroy")
6262
planRequest.Destroy = true
6363
}
@@ -84,7 +84,7 @@ func (r *TerraformReconciler) plan(ctx context.Context, patchHelper *patch.Seria
8484
}
8585
}
8686

87-
if eventSent == false {
87+
if !eventSent {
8888
msg := fmt.Sprintf("Plan error: %s", err.Error())
8989
r.Eventf(terraform, corev1.EventTypeWarning, infrav1.TFExecPlanFailedReason, msg)
9090
}
@@ -101,7 +101,7 @@ func (r *TerraformReconciler) plan(ctx context.Context, patchHelper *patch.Seria
101101
log.Info(fmt.Sprintf("plan: %s, found drift: %v", planReply.Message, drifted))
102102

103103
// currently the PlanCreated flag is only used here to determine if the destroy plan is empty
104-
if planRequest.Destroy && planReply.PlanCreated == false {
104+
if planRequest.Destroy && !planReply.PlanCreated {
105105
// A corner case
106106
// If the destroy plan is empty, we should not call apply
107107
terraform = infrav1.TerraformPlannedNoChanges(terraform, revision, "No objects need to be destroyed")
@@ -145,7 +145,7 @@ func (r *TerraformReconciler) plan(ctx context.Context, patchHelper *patch.Seria
145145
forceOrAutoApply := r.forceOrAutoApply(terraform)
146146

147147
// this is the manual mode, we fire the event to show how to apply the plan
148-
if forceOrAutoApply == false {
148+
if !forceOrAutoApply {
149149
planId := planid.GetPlanID(revision)
150150
approveMessage := planid.GetApproveMessage(planId, "Plan generated")
151151
msg := fmt.Sprintf("Planned.\n%s", approveMessage)

controllers/tf_controller_reconcile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (r *TerraformReconciler) reconcile(ctx context.Context, patchHelper *patch.
141141
// immediately return if no drift - reconciliation will retry normally
142142
if driftDetectionErr == nil {
143143
// reconcile outputs only when outputs are missing
144-
if outputsDrifted, err := r.outputsMayBeDrifted(ctx, terraform); outputsDrifted == true && err == nil {
144+
if outputsDrifted, err := r.outputsMayBeDrifted(ctx, terraform); outputsDrifted && err == nil {
145145
terraform, err = r.processOutputs(ctx, patchHelper, runnerClient, terraform, tfInstance, revision)
146146
if err != nil {
147147
log.Error(err, "error processing outputs")
@@ -287,7 +287,7 @@ func (r *TerraformReconciler) reconcile(ctx context.Context, patchHelper *patch.
287287
Entries: inventoryEntries,
288288
}
289289
}
290-
} else if terraform.Spec.EnableInventory == false {
290+
} else if !terraform.Spec.EnableInventory {
291291
log.Info("inventory is disabled")
292292
terraform.Status.Inventory = nil
293293
}

0 commit comments

Comments
 (0)