Skip to content

Commit cd48b2b

Browse files
authored
Merge pull request #4779 from camilamacedo86/fix-static-checks
🐛 (Follow up of : #4752 - Upgrade GolangCI) - fix: address staticcheck linter issues (ST1005, QF1008) in scaffolds and tutorials
2 parents 4022007 + 742ec79 commit cd48b2b

File tree

30 files changed

+49
-91
lines changed

30 files changed

+49
-91
lines changed

docs/book/src/cronjob-tutorial/testdata/project/.golangci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ linters:
3939
- linters:
4040
- staticcheck
4141
text: "ST1019"
42-
- linters:
43-
- staticcheck
44-
text: "ST1005"
45-
- linters:
46-
- staticcheck
47-
text: "QF1008"
4842
paths:
4943
- third_party$
5044
- builtin$

docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
354354
if cronJob.Status.LastScheduleTime != nil {
355355
earliestTime = cronJob.Status.LastScheduleTime.Time
356356
} else {
357-
earliestTime = cronJob.ObjectMeta.CreationTimestamp.Time
357+
earliestTime = cronJob.CreationTimestamp.Time
358358
}
359359
if cronJob.Spec.StartingDeadlineSeconds != nil {
360360
// controller is not going to schedule anything below this point

docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ the validation schema.
265265
*/
266266

267267
func validateCronJobName(cronjob *batchv1.CronJob) *field.Error {
268-
if len(cronjob.ObjectMeta.Name) > validationutils.DNS1035LabelMaxLength-11 {
268+
if len(cronjob.Name) > validationutils.DNS1035LabelMaxLength-11 {
269269
// The job name length is 63 characters like all Kubernetes objects
270270
// (which must fit in a DNS subdomain). The cronjob controller appends
271271
// a 11-character suffix to the cronjob (`-$TIMESTAMP`) when creating
272272
// a job. The job name length limit is 63 characters. Therefore cronjob
273273
// names must have length <= 63-11=52. If we don't validate this here,
274274
// then job creation will fail later.
275-
return field.Invalid(field.NewPath("metadata").Child("name"), cronjob.ObjectMeta.Name, "must be no more than 52 characters")
275+
return field.Invalid(field.NewPath("metadata").Child("name"), cronjob.Name, "must be no more than 52 characters")
276276
}
277277
return nil
278278
}

docs/book/src/cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ var _ = Describe("CronJob Webhook", func() {
115115

116116
Context("When creating or updating CronJob under Validating Webhook", func() {
117117
It("Should deny creation if the name is too long", func() {
118-
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
118+
obj.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
119119
Expect(validator.ValidateCreate(ctx, obj)).Error().To(
120120
MatchError(ContainSubstring("must be no more than 52 characters")),
121121
"Expected name validation to fail for a too-long name")
122122
})
123123

124124
It("Should admit creation if the name is valid", func() {
125-
obj.ObjectMeta.Name = validCronJobName
125+
obj.Name = validCronJobName
126126
Expect(validator.ValidateCreate(ctx, obj)).To(BeNil(),
127127
"Expected name validation to pass for a valid name")
128128
})
@@ -141,11 +141,11 @@ var _ = Describe("CronJob Webhook", func() {
141141
})
142142

143143
It("Should deny update if both name and spec are invalid", func() {
144-
oldObj.ObjectMeta.Name = validCronJobName
144+
oldObj.Name = validCronJobName
145145
oldObj.Spec.Schedule = schedule
146146

147147
By("simulating an update")
148-
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
148+
obj.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
149149
obj.Spec.Schedule = "invalid-cron-schedule"
150150

151151
By("validating an update")
@@ -154,11 +154,11 @@ var _ = Describe("CronJob Webhook", func() {
154154
})
155155

156156
It("Should admit update if both name and spec are valid", func() {
157-
oldObj.ObjectMeta.Name = validCronJobName
157+
oldObj.Name = validCronJobName
158158
oldObj.Spec.Schedule = schedule
159159

160160
By("simulating an update")
161-
obj.ObjectMeta.Name = "valid-cronjob-name-updated"
161+
obj.Name = "valid-cronjob-name-updated"
162162
obj.Spec.Schedule = "0 0 * * *"
163163

164164
By("validating an update")

docs/book/src/cronjob-tutorial/testdata/project/test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"os/exec"
2525
"strings"
2626

27-
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck
27+
. "github.com/onsi/ginkgo/v2" // nolint:revive,staticcheck
2828
)
2929

3030
const (

docs/book/src/getting-started/testdata/project/.golangci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ linters:
3939
- linters:
4040
- staticcheck
4141
text: "ST1019"
42-
- linters:
43-
- staticcheck
44-
text: "ST1005"
45-
- linters:
46-
- staticcheck
47-
text: "QF1008"
4842
paths:
4943
- third_party$
5044
- builtin$

docs/book/src/getting-started/testdata/project/test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"os/exec"
2525
"strings"
2626

27-
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck
27+
. "github.com/onsi/ginkgo/v2" // nolint:revive,staticcheck
2828
)
2929

3030
const (

docs/book/src/multiversion-tutorial/testdata/project/.golangci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ linters:
3939
- linters:
4040
- staticcheck
4141
text: "ST1019"
42-
- linters:
43-
- staticcheck
44-
text: "ST1005"
45-
- linters:
46-
- staticcheck
47-
text: "QF1008"
4842
paths:
4943
- third_party$
5044
- builtin$

docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
354354
if cronJob.Status.LastScheduleTime != nil {
355355
earliestTime = cronJob.Status.LastScheduleTime.Time
356356
} else {
357-
earliestTime = cronJob.ObjectMeta.CreationTimestamp.Time
357+
earliestTime = cronJob.CreationTimestamp.Time
358358
}
359359
if cronJob.Spec.StartingDeadlineSeconds != nil {
360360
// controller is not going to schedule anything below this point

docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ the validation schema.
270270
*/
271271

272272
func validateCronJobName(cronjob *batchv1.CronJob) *field.Error {
273-
if len(cronjob.ObjectMeta.Name) > validationutils.DNS1035LabelMaxLength-11 {
273+
if len(cronjob.Name) > validationutils.DNS1035LabelMaxLength-11 {
274274
// The job name length is 63 characters like all Kubernetes objects
275275
// (which must fit in a DNS subdomain). The cronjob controller appends
276276
// a 11-character suffix to the cronjob (`-$TIMESTAMP`) when creating
277277
// a job. The job name length limit is 63 characters. Therefore cronjob
278278
// names must have length <= 63-11=52. If we don't validate this here,
279279
// then job creation will fail later.
280-
return field.Invalid(field.NewPath("metadata").Child("name"), cronjob.ObjectMeta.Name, "must be no more than 52 characters")
280+
return field.Invalid(field.NewPath("metadata").Child("name"), cronjob.Name, "must be no more than 52 characters")
281281
}
282282
return nil
283283
}

docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ var _ = Describe("CronJob Webhook", func() {
114114

115115
Context("When creating or updating CronJob under Validating Webhook", func() {
116116
It("Should deny creation if the name is too long", func() {
117-
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
117+
obj.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
118118
Expect(validator.ValidateCreate(ctx, obj)).Error().To(
119119
MatchError(ContainSubstring("must be no more than 52 characters")),
120120
"Expected name validation to fail for a too-long name")
121121
})
122122

123123
It("Should admit creation if the name is valid", func() {
124-
obj.ObjectMeta.Name = validCronJobName
124+
obj.Name = validCronJobName
125125
Expect(validator.ValidateCreate(ctx, obj)).To(BeNil(),
126126
"Expected name validation to pass for a valid name")
127127
})
@@ -140,11 +140,11 @@ var _ = Describe("CronJob Webhook", func() {
140140
})
141141

142142
It("Should deny update if both name and spec are invalid", func() {
143-
oldObj.ObjectMeta.Name = validCronJobName
143+
oldObj.Name = validCronJobName
144144
oldObj.Spec.Schedule = schedule
145145

146146
By("simulating an update")
147-
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
147+
obj.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
148148
obj.Spec.Schedule = "invalid-cron-schedule"
149149

150150
By("validating an update")
@@ -153,11 +153,11 @@ var _ = Describe("CronJob Webhook", func() {
153153
})
154154

155155
It("Should admit update if both name and spec are valid", func() {
156-
oldObj.ObjectMeta.Name = validCronJobName
156+
oldObj.Name = validCronJobName
157157
oldObj.Spec.Schedule = schedule
158158

159159
By("simulating an update")
160-
obj.ObjectMeta.Name = "valid-cronjob-name-updated"
160+
obj.Name = "valid-cronjob-name-updated"
161161
obj.Spec.Schedule = "0 0 * * *"
162162

163163
By("validating an update")

docs/book/src/multiversion-tutorial/testdata/project/internal/webhook/v2/cronjob_webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ func validateCronJob(cronjob *batchv2.CronJob) error {
173173
}
174174

175175
func validateCronJobName(cronjob *batchv2.CronJob) *field.Error {
176-
if len(cronjob.ObjectMeta.Name) > validationutils.DNS1035LabelMaxLength-11 {
177-
return field.Invalid(field.NewPath("metadata").Child("name"), cronjob.ObjectMeta.Name, "must be no more than 52 characters")
176+
if len(cronjob.Name) > validationutils.DNS1035LabelMaxLength-11 {
177+
return field.Invalid(field.NewPath("metadata").Child("name"), cronjob.Name, "must be no more than 52 characters")
178178
}
179179
return nil
180180
}

docs/book/src/multiversion-tutorial/testdata/project/test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"os/exec"
2525
"strings"
2626

27-
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck
27+
. "github.com/onsi/ginkgo/v2" // nolint:revive,staticcheck
2828
)
2929

3030
const (

hack/docs/internal/cronjob-tutorial/controller_implementation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ const controllerReconcileLogic = `log := logf.FromContext(ctx)
343343
if cronJob.Status.LastScheduleTime != nil {
344344
earliestTime = cronJob.Status.LastScheduleTime.Time
345345
} else {
346-
earliestTime = cronJob.ObjectMeta.CreationTimestamp.Time
346+
earliestTime = cronJob.CreationTimestamp.Time
347347
}
348348
if cronJob.Spec.StartingDeadlineSeconds != nil {
349349
// controller is not going to schedule anything below this point

hack/docs/internal/cronjob-tutorial/webhook_implementation.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ the validation schema.
164164
*/
165165
166166
func validateCronJobName(cronjob *batchv1.CronJob) *field.Error {
167-
if len(cronjob.ObjectMeta.Name) > validationutils.DNS1035LabelMaxLength-11 {
167+
if len(cronjob.Name) > validationutils.DNS1035LabelMaxLength-11 {
168168
// The job name length is 63 characters like all Kubernetes objects
169169
// (which must fit in a DNS subdomain). The cronjob controller appends
170170
// a 11-character suffix to the cronjob (` + "`" + `-$TIMESTAMP` + "`" + `) when creating
171171
// a job. The job name length limit is 63 characters. Therefore cronjob
172172
// names must have length <= 63-11=52. If we don't validate this here,
173173
// then job creation will fail later.
174-
return field.Invalid(field.NewPath("metadata").Child("name"), cronjob.ObjectMeta.Name, "must be no more than 52 characters")
174+
return field.Invalid(field.NewPath("metadata").Child("name"), cronjob.Name, "must be no more than 52 characters")
175175
}
176176
return nil
177177
}
@@ -256,14 +256,14 @@ const webhookTestingValidatingTodoFragment = `// TODO (user): Add logic for vali
256256
// })`
257257

258258
const webhookTestingValidatingExampleFragment = `It("Should deny creation if the name is too long", func() {
259-
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
259+
obj.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
260260
Expect(validator.ValidateCreate(ctx, obj)).Error().To(
261261
MatchError(ContainSubstring("must be no more than 52 characters")),
262262
"Expected name validation to fail for a too-long name")
263263
})
264264
265265
It("Should admit creation if the name is valid", func() {
266-
obj.ObjectMeta.Name = validCronJobName
266+
obj.Name = validCronJobName
267267
Expect(validator.ValidateCreate(ctx, obj)).To(BeNil(),
268268
"Expected name validation to pass for a valid name")
269269
})
@@ -282,11 +282,11 @@ const webhookTestingValidatingExampleFragment = `It("Should deny creation if the
282282
})
283283
284284
It("Should deny update if both name and spec are invalid", func() {
285-
oldObj.ObjectMeta.Name = validCronJobName
285+
oldObj.Name = validCronJobName
286286
oldObj.Spec.Schedule = schedule
287287
288288
By("simulating an update")
289-
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
289+
obj.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
290290
obj.Spec.Schedule = "invalid-cron-schedule"
291291
292292
By("validating an update")
@@ -295,11 +295,11 @@ const webhookTestingValidatingExampleFragment = `It("Should deny creation if the
295295
})
296296
297297
It("Should admit update if both name and spec are valid", func() {
298-
oldObj.ObjectMeta.Name = validCronJobName
298+
oldObj.Name = validCronJobName
299299
oldObj.Spec.Schedule = schedule
300300
301301
By("simulating an update")
302-
obj.ObjectMeta.Name = "valid-cronjob-name-updated"
302+
obj.Name = "valid-cronjob-name-updated"
303303
obj.Spec.Schedule = "0 0 * * *"
304304
305305
By("validating an update")

hack/docs/internal/multiversion-tutorial/generate_multiversion.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ interfaces, a conversion webhook will be registered.
225225
226226
Context("When creating or updating CronJob under Validating Webhook", func() {
227227
It("Should deny creation if the name is too long", func() {
228-
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
228+
obj.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
229229
Expect(validator.ValidateCreate(ctx, obj)).Error().To(
230230
MatchError(ContainSubstring("must be no more than 52 characters")),
231231
"Expected name validation to fail for a too-long name")
232232
})
233233
234234
It("Should admit creation if the name is valid", func() {
235-
obj.ObjectMeta.Name = validCronJobName
235+
obj.Name = validCronJobName
236236
Expect(validator.ValidateCreate(ctx, obj)).To(BeNil(),
237237
"Expected name validation to pass for a valid name")
238238
})
@@ -251,11 +251,11 @@ interfaces, a conversion webhook will be registered.
251251
})
252252
253253
It("Should deny update if both name and spec are invalid", func() {
254-
oldObj.ObjectMeta.Name = validCronJobName
254+
oldObj.Name = validCronJobName
255255
oldObj.Spec.Schedule = schedule
256256
257257
By("simulating an update")
258-
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
258+
obj.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
259259
obj.Spec.Schedule = "invalid-cron-schedule"
260260
261261
By("validating an update")
@@ -264,11 +264,11 @@ interfaces, a conversion webhook will be registered.
264264
})
265265
266266
It("Should admit update if both name and spec are valid", func() {
267-
oldObj.ObjectMeta.Name = validCronJobName
267+
oldObj.Name = validCronJobName
268268
oldObj.Spec.Schedule = schedule
269269
270270
By("simulating an update")
271-
obj.ObjectMeta.Name = "valid-cronjob-name-updated"
271+
obj.Name = "valid-cronjob-name-updated"
272272
obj.Spec.Schedule = "0 0 * * *"
273273
274274
By("validating an update")

hack/docs/internal/multiversion-tutorial/webhook_v2_implementaton.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func validateCronJob(cronjob *batchv2.CronJob) error {
6666
}
6767
6868
func validateCronJobName(cronjob *batchv2.CronJob) *field.Error {
69-
if len(cronjob.ObjectMeta.Name) > validationutils.DNS1035LabelMaxLength-11 {
70-
return field.Invalid(field.NewPath("metadata").Child("name"), cronjob.ObjectMeta.Name, "must be no more than 52 characters")
69+
if len(cronjob.Name) > validationutils.DNS1035LabelMaxLength-11 {
70+
return field.Invalid(field.NewPath("metadata").Child("name"), cronjob.Name, "must be no more than 52 characters")
7171
}
7272
return nil
7373
}

pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ func imageFor{{ .Resource.Kind }}() (string, error) {
459459
var imageEnvVar = "{{ upper .Resource.Kind }}_IMAGE"
460460
image, found := os.LookupEnv(imageEnvVar)
461461
if !found {
462-
return "", fmt.Errorf("Unable to find %s environment variable with the image", imageEnvVar)
462+
return "", fmt.Errorf("unable to find %s environment variable with the image", imageEnvVar)
463463
}
464464
return image, nil
465465
}

pkg/plugins/golang/v4/scaffolds/internal/templates/golangci.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ linters:
8282
- linters:
8383
- staticcheck
8484
text: "ST1019"
85-
- linters:
86-
- staticcheck
87-
text: "ST1005"
88-
- linters:
89-
- staticcheck
90-
text: "QF1008"
9185
paths:
9286
- third_party$
9387
- builtin$

pkg/plugins/golang/v4/scaffolds/internal/templates/test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import (
5252
"os/exec"
5353
"strings"
5454
55-
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck
55+
. "github.com/onsi/ginkgo/v2" // nolint:revive,staticcheck
5656
)
5757
5858
const (

testdata/project-v4-multigroup/.golangci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ linters:
3939
- linters:
4040
- staticcheck
4141
text: "ST1019"
42-
- linters:
43-
- staticcheck
44-
text: "ST1005"
45-
- linters:
46-
- staticcheck
47-
text: "QF1008"
4842
paths:
4943
- third_party$
5044
- builtin$

testdata/project-v4-multigroup/internal/controller/example.com/busybox_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func imageForBusybox() (string, error) {
419419
var imageEnvVar = "BUSYBOX_IMAGE"
420420
image, found := os.LookupEnv(imageEnvVar)
421421
if !found {
422-
return "", fmt.Errorf("Unable to find %s environment variable with the image", imageEnvVar)
422+
return "", fmt.Errorf("unable to find %s environment variable with the image", imageEnvVar)
423423
}
424424
return image, nil
425425
}

0 commit comments

Comments
 (0)