Skip to content

Commit 338af81

Browse files
authored
Merge pull request #4548 from wazery/lint-doc-samples
🌱 : Improve samples linting & fix samples lint issues
2 parents f9bef1c + 0c4ce6d commit 338af81

File tree

16 files changed

+94
-47
lines changed

16 files changed

+94
-47
lines changed

.github/workflows/lint-sample.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ jobs:
1616
folder: [
1717
"testdata/project-v4",
1818
"testdata/project-v4-with-plugins",
19-
"testdata/project-v4-multigroup"
19+
"testdata/project-v4-multigroup",
20+
"docs/book/src/cronjob-tutorial/testdata/project",
21+
"docs/book/src/getting-started/testdata/project",
22+
"docs/book/src/multiversion-tutorial/testdata/project"
2023
]
2124
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
2225
steps:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ var (
9696
//
9797
// For more details, check Reconcile and its Result here:
9898
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.1/pkg/reconcile
99+
// nolint:gocyclo
99100
func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
100101
log := log.FromContext(ctx)
101102

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ var _ = Describe("CronJob controller", func() {
129129
By("By checking the CronJob has zero active Jobs")
130130
Consistently(func(g Gomega) {
131131
g.Expect(k8sClient.Get(ctx, cronjobLookupKey, createdCronjob)).To(Succeed())
132-
g.Expect(createdCronjob.Status.Active).To(HaveLen(0))
132+
g.Expect(createdCronjob.Status.Active).To(BeEmpty())
133133
}, duration, interval).Should(Succeed())
134134
/*
135135
Next, we actually create a stubbed Job that will belong to our CronJob, as well as its downstream template specs.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package v1
2020
import (
2121
"context"
2222
"fmt"
23+
2324
"github.com/robfig/cron"
2425
apierrors "k8s.io/apimachinery/pkg/api/errors"
2526
"k8s.io/apimachinery/pkg/runtime/schema"

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ var _ = Describe("CronJob Webhook", func() {
3232
defaulter CronJobCustomDefaulter
3333
)
3434

35+
const validCronJobName = "valid-cronjob-name"
36+
const schedule = "*/5 * * * *"
37+
3538
BeforeEach(func() {
3639
obj = &batchv1.CronJob{
3740
Spec: batchv1.CronJobSpec{
38-
Schedule: "*/5 * * * *",
41+
Schedule: schedule,
3942
ConcurrencyPolicy: batchv1.AllowConcurrent,
4043
SuccessfulJobsHistoryLimit: new(int32),
4144
FailedJobsHistoryLimit: new(int32),
@@ -46,7 +49,7 @@ var _ = Describe("CronJob Webhook", func() {
4649

4750
oldObj = &batchv1.CronJob{
4851
Spec: batchv1.CronJobSpec{
49-
Schedule: "*/5 * * * *",
52+
Schedule: schedule,
5053
ConcurrencyPolicy: batchv1.AllowConcurrent,
5154
SuccessfulJobsHistoryLimit: new(int32),
5255
FailedJobsHistoryLimit: new(int32),
@@ -80,7 +83,7 @@ var _ = Describe("CronJob Webhook", func() {
8083
obj.Spec.FailedJobsHistoryLimit = nil // This should default to 1
8184

8285
By("calling the Default method to apply defaults")
83-
defaulter.Default(ctx, obj)
86+
_ = defaulter.Default(ctx, obj)
8487

8588
By("checking that the default values are set")
8689
Expect(obj.Spec.ConcurrencyPolicy).To(Equal(batchv1.AllowConcurrent), "Expected ConcurrencyPolicy to default to AllowConcurrent")
@@ -100,7 +103,7 @@ var _ = Describe("CronJob Webhook", func() {
100103
*obj.Spec.FailedJobsHistoryLimit = 2
101104

102105
By("calling the Default method to apply defaults")
103-
defaulter.Default(ctx, obj)
106+
_ = defaulter.Default(ctx, obj)
104107

105108
By("checking that the fields were not overwritten")
106109
Expect(obj.Spec.ConcurrencyPolicy).To(Equal(batchv1.ForbidConcurrent), "Expected ConcurrencyPolicy to retain its set value")
@@ -119,7 +122,7 @@ var _ = Describe("CronJob Webhook", func() {
119122
})
120123

121124
It("Should admit creation if the name is valid", func() {
122-
obj.ObjectMeta.Name = "valid-cronjob-name"
125+
obj.ObjectMeta.Name = validCronJobName
123126
Expect(validator.ValidateCreate(ctx, obj)).To(BeNil(),
124127
"Expected name validation to pass for a valid name")
125128
})
@@ -132,14 +135,14 @@ var _ = Describe("CronJob Webhook", func() {
132135
})
133136

134137
It("Should admit creation if the schedule is valid", func() {
135-
obj.Spec.Schedule = "*/5 * * * *"
138+
obj.Spec.Schedule = schedule
136139
Expect(validator.ValidateCreate(ctx, obj)).To(BeNil(),
137140
"Expected spec validation to pass for a valid schedule")
138141
})
139142

140143
It("Should deny update if both name and spec are invalid", func() {
141-
oldObj.ObjectMeta.Name = "valid-cronjob-name"
142-
oldObj.Spec.Schedule = "*/5 * * * *"
144+
oldObj.ObjectMeta.Name = validCronJobName
145+
oldObj.Spec.Schedule = schedule
143146

144147
By("simulating an update")
145148
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
@@ -151,8 +154,8 @@ var _ = Describe("CronJob Webhook", func() {
151154
})
152155

153156
It("Should admit update if both name and spec are valid", func() {
154-
oldObj.ObjectMeta.Name = "valid-cronjob-name"
155-
oldObj.Spec.Schedule = "*/5 * * * *"
157+
oldObj.ObjectMeta.Name = validCronJobName
158+
oldObj.Spec.Schedule = schedule
156159

157160
By("simulating an update")
158161
obj.ObjectMeta.Name = "valid-cronjob-name-updated"

docs/book/src/getting-started/testdata/project/internal/controller/memcached_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ package controller
1919
import (
2020
"context"
2121
"fmt"
22+
23+
"time"
24+
2225
appsv1 "k8s.io/api/apps/v1"
2326
corev1 "k8s.io/api/core/v1"
2427
apierrors "k8s.io/apimachinery/pkg/api/errors"
2528
"k8s.io/apimachinery/pkg/api/meta"
2629
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2730
"k8s.io/apimachinery/pkg/types"
2831
"k8s.io/utils/ptr"
29-
"time"
3032

3133
"k8s.io/apimachinery/pkg/runtime"
3234
ctrl "sigs.k8s.io/controller-runtime"
@@ -89,7 +91,7 @@ func (r *MemcachedReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
8991
}
9092

9193
// Let's just set the status as Unknown when no status is available
92-
if memcached.Status.Conditions == nil || len(memcached.Status.Conditions) == 0 {
94+
if len(memcached.Status.Conditions) == 0 {
9395
meta.SetStatusCondition(&memcached.Status.Conditions, metav1.Condition{Type: typeAvailableMemcached, Status: metav1.ConditionUnknown, Reason: "Reconciling", Message: "Starting reconciliation"})
9496
if err = r.Status().Update(ctx, memcached); err != nil {
9597
log.Error(err, "Failed to update Memcached status")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ var (
9696
//
9797
// For more details, check Reconcile and its Result here:
9898
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.1/pkg/reconcile
99+
// nolint:gocyclo
99100
func (r *CronJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
100101
log := log.FromContext(ctx)
101102

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ var _ = Describe("CronJob controller", func() {
129129
By("By checking the CronJob has zero active Jobs")
130130
Consistently(func(g Gomega) {
131131
g.Expect(k8sClient.Get(ctx, cronjobLookupKey, createdCronjob)).To(Succeed())
132-
g.Expect(createdCronjob.Status.Active).To(HaveLen(0))
132+
g.Expect(createdCronjob.Status.Active).To(BeEmpty())
133133
}, duration, interval).Should(Succeed())
134134
/*
135135
Next, we actually create a stubbed Job that will belong to our CronJob, as well as its downstream template specs.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package v1
2020
import (
2121
"context"
2222
"fmt"
23+
2324
"github.com/robfig/cron"
2425
apierrors "k8s.io/apimachinery/pkg/api/errors"
2526
"k8s.io/apimachinery/pkg/runtime/schema"

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ var _ = Describe("CronJob Webhook", func() {
3131
validator CronJobCustomValidator
3232
defaulter CronJobCustomDefaulter
3333
)
34+
const validCronJobName = "valid-cronjob-name"
35+
const schedule = "*/5 * * * *"
3436

3537
BeforeEach(func() {
3638
obj = &batchv1.CronJob{
3739
Spec: batchv1.CronJobSpec{
38-
Schedule: "*/5 * * * *",
40+
Schedule: schedule,
3941
ConcurrencyPolicy: batchv1.AllowConcurrent,
4042
SuccessfulJobsHistoryLimit: new(int32),
4143
FailedJobsHistoryLimit: new(int32),
@@ -46,7 +48,7 @@ var _ = Describe("CronJob Webhook", func() {
4648

4749
oldObj = &batchv1.CronJob{
4850
Spec: batchv1.CronJobSpec{
49-
Schedule: "*/5 * * * *",
51+
Schedule: schedule,
5052
ConcurrencyPolicy: batchv1.AllowConcurrent,
5153
SuccessfulJobsHistoryLimit: new(int32),
5254
FailedJobsHistoryLimit: new(int32),
@@ -80,7 +82,7 @@ var _ = Describe("CronJob Webhook", func() {
8082
obj.Spec.FailedJobsHistoryLimit = nil // This should default to 1
8183

8284
By("calling the Default method to apply defaults")
83-
defaulter.Default(ctx, obj)
85+
_ = defaulter.Default(ctx, obj)
8486

8587
By("checking that the default values are set")
8688
Expect(obj.Spec.ConcurrencyPolicy).To(Equal(batchv1.AllowConcurrent), "Expected ConcurrencyPolicy to default to AllowConcurrent")
@@ -100,7 +102,7 @@ var _ = Describe("CronJob Webhook", func() {
100102
*obj.Spec.FailedJobsHistoryLimit = 2
101103

102104
By("calling the Default method to apply defaults")
103-
defaulter.Default(ctx, obj)
105+
_ = defaulter.Default(ctx, obj)
104106

105107
By("checking that the fields were not overwritten")
106108
Expect(obj.Spec.ConcurrencyPolicy).To(Equal(batchv1.ForbidConcurrent), "Expected ConcurrencyPolicy to retain its set value")
@@ -119,7 +121,7 @@ var _ = Describe("CronJob Webhook", func() {
119121
})
120122

121123
It("Should admit creation if the name is valid", func() {
122-
obj.ObjectMeta.Name = "valid-cronjob-name"
124+
obj.ObjectMeta.Name = validCronJobName
123125
Expect(validator.ValidateCreate(ctx, obj)).To(BeNil(),
124126
"Expected name validation to pass for a valid name")
125127
})
@@ -132,14 +134,14 @@ var _ = Describe("CronJob Webhook", func() {
132134
})
133135

134136
It("Should admit creation if the schedule is valid", func() {
135-
obj.Spec.Schedule = "*/5 * * * *"
137+
obj.Spec.Schedule = schedule
136138
Expect(validator.ValidateCreate(ctx, obj)).To(BeNil(),
137139
"Expected spec validation to pass for a valid schedule")
138140
})
139141

140142
It("Should deny update if both name and spec are invalid", func() {
141-
oldObj.ObjectMeta.Name = "valid-cronjob-name"
142-
oldObj.Spec.Schedule = "*/5 * * * *"
143+
oldObj.ObjectMeta.Name = validCronJobName
144+
oldObj.Spec.Schedule = schedule
143145

144146
By("simulating an update")
145147
obj.ObjectMeta.Name = "this-name-is-way-too-long-and-should-fail-validation-because-it-is-way-too-long"
@@ -151,8 +153,8 @@ var _ = Describe("CronJob Webhook", func() {
151153
})
152154

153155
It("Should admit update if both name and spec are valid", func() {
154-
oldObj.ObjectMeta.Name = "valid-cronjob-name"
155-
oldObj.Spec.Schedule = "*/5 * * * *"
156+
oldObj.ObjectMeta.Name = validCronJobName
157+
oldObj.Spec.Schedule = schedule
156158

157159
By("simulating an update")
158160
obj.ObjectMeta.Name = "valid-cronjob-name-updated"

0 commit comments

Comments
 (0)