Skip to content

Commit 9c36b61

Browse files
🌱 Enable the lint to check exported methods and fix issues (#4463)
Enable the lint to check exported methods and fix issues
1 parent ee22896 commit 9c36b61

File tree

43 files changed

+132
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+132
-99
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ linters-settings:
3333
- name: error-strings
3434
- name: error-naming
3535
- name: exported
36-
disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings.
3736
- name: if-return
3837
- name: increment-decrement
3938
- name: var-naming

hack/docs/generate_samples.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ package main
1818

1919
import (
2020
log "github.com/sirupsen/logrus"
21-
2221
cronjob "sigs.k8s.io/kubebuilder/v4/hack/docs/internal/cronjob-tutorial"
2322
gettingstarted "sigs.k8s.io/kubebuilder/v4/hack/docs/internal/getting-started"
2423
multiversion "sigs.k8s.io/kubebuilder/v4/hack/docs/internal/multiversion-tutorial"
2524
)
2625

27-
// Make sure executing `build_kb` to generate kb executable from the source code
26+
// KubebuilderBinName make sure executing `build_kb` to generate kb executable from the source code
2827
const KubebuilderBinName = "/tmp/kubebuilder/bin/kubebuilder"
2928

3029
type tutorialGenerator interface {
@@ -38,9 +37,9 @@ func main() {
3837
type generator func()
3938

4039
tutorials := map[string]generator{
41-
"cronjob": UpdateCronjobTutorial,
42-
"getting-started": UpdateGettingStarted,
43-
"multiversion": UpdateMultiversionTutorial,
40+
"cronjob": updateCronjobTutorial,
41+
"getting-started": updateGettingStarted,
42+
"multiversion": updateMultiversionTutorial,
4443
}
4544

4645
log.SetFormatter(&log.TextFormatter{DisableTimestamp: true})
@@ -59,19 +58,19 @@ func updateTutorial(generator tutorialGenerator) {
5958
generator.CodeGen()
6059
}
6160

62-
func UpdateCronjobTutorial() {
61+
func updateCronjobTutorial() {
6362
samplePath := "docs/book/src/cronjob-tutorial/testdata/project/"
6463
sp := cronjob.NewSample(KubebuilderBinName, samplePath)
6564
updateTutorial(&sp)
6665
}
6766

68-
func UpdateGettingStarted() {
67+
func updateGettingStarted() {
6968
samplePath := "docs/book/src/getting-started/testdata/project"
7069
sp := gettingstarted.NewSample(KubebuilderBinName, samplePath)
7170
updateTutorial(&sp)
7271
}
7372

74-
func UpdateMultiversionTutorial() {
73+
func updateMultiversionTutorial() {
7574
samplePath := "docs/book/src/multiversion-tutorial/testdata/project"
7675
sp := cronjob.NewSample(KubebuilderBinName, samplePath)
7776
updateTutorial(&sp)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
package cronjob
1818

19-
const CronjobSpecExplaination = `
19+
const cronjobSpecExplaination = `
2020
2121
// +kubebuilder:docs-gen:collapse=Imports
2222
@@ -49,7 +49,7 @@ const CronjobSpecExplaination = `
4949
*/
5050
`
5151

52-
const CronjobSpecStruct = `
52+
const cronjobSpecStruct = `
5353
// +kubebuilder:validation:MinLength=0
5454
5555
// The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
@@ -128,7 +128,7 @@ const (
128128
serialization, as mentioned above.
129129
*/`
130130

131-
const CronjobList = `
131+
const cronjobList = `
132132
133133
// A list of pointers to currently running jobs.
134134
// +optional

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ limitations under the License.
1616

1717
package cronjob
1818

19-
const ControllerIntro = `
19+
const controllerIntro = `
2020
// +kubebuilder:docs-gen:collapse=Apache License
2121
2222
/*
2323
We'll start out with some imports. You'll see below that we'll need a few more imports
2424
than those scaffolded for us. We'll talk about each one when we use it.
2525
*/`
2626

27-
const ControllerImport = `import (
27+
const controllerImport = `import (
2828
"context"
2929
"fmt"
3030
"sort"
@@ -48,7 +48,7 @@ Next, we'll need a Clock, which will allow us to fake timing in our tests.
4848
*/
4949
`
5050

51-
const ControllerMockClock = `
51+
const controllerMockClock = `
5252
/*
5353
We'll mock out the clock to make it easier to jump around in time while testing,
5454
the "real" clock just calls` + " `" + `time.Now` + "`" + `.
@@ -72,7 +72,7 @@ a couple more [markers](/reference/markers/rbac.md).
7272
*/
7373
`
7474

75-
const ControllerReconcile = `
75+
const controllerReconcile = `
7676
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;update;patch;delete
7777
// +kubebuilder:rbac:groups=batch,resources=jobs/status,verbs=get
7878
@@ -84,7 +84,7 @@ var (
8484
)
8585
`
8686

87-
const ControllerReconcileLogic = `log := log.FromContext(ctx)
87+
const controllerReconcileLogic = `log := log.FromContext(ctx)
8888
8989
/*
9090
### 1: Load the CronJob by name
@@ -533,7 +533,7 @@ var (
533533
apiGVStr = batchv1.GroupVersion.String()
534534
)
535535
`
536-
const ControllerSetupWithManager = `
536+
const controllerSetupWithManager = `
537537
// set up a real clock, since we're not in a test
538538
if r.Clock == nil {
539539
r.Clock = realClock{}

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

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ import (
2222

2323
log "github.com/sirupsen/logrus"
2424
"github.com/spf13/afero"
25-
2625
hackutils "sigs.k8s.io/kubebuilder/v4/hack/docs/utils"
2726
pluginutil "sigs.k8s.io/kubebuilder/v4/pkg/plugin/util"
2827
"sigs.k8s.io/kubebuilder/v4/test/e2e/utils"
2928
)
3029

30+
// Sample define the sample which will be scaffolded
3131
type Sample struct {
3232
ctx *utils.TestContext
3333
}
3434

35+
// NewSample create a new instance of the cronjob sample and configure the KB CLI that will be used
3536
func NewSample(binaryPath, samplePath string) Sample {
3637
log.Infof("Generating the sample context of Cronjob...")
3738
ctx := hackutils.NewSampleContext(binaryPath, samplePath, "GO111MODULE=on")
@@ -49,6 +50,7 @@ func (sp *Sample) Prepare() {
4950
hackutils.CheckError("creating directory for sample project", err)
5051
}
5152

53+
// GenerateSampleProject will generate the sample
5254
func (sp *Sample) GenerateSampleProject() {
5355
log.Infof("Initializing the cronjob project")
5456

@@ -79,6 +81,7 @@ func (sp *Sample) GenerateSampleProject() {
7981
hackutils.CheckError("Implementing admission webhook", err)
8082
}
8183

84+
// UpdateTutorial the cronjob tutorial with the scaffold changes
8285
func (sp *Sample) UpdateTutorial() {
8386
log.Println("Update tutorial with cronjob code")
8487
// 1. update specs
@@ -168,12 +171,12 @@ func (sp *Sample) updateSpec() {
168171

169172
err = pluginutil.InsertCode(
170173
filepath.Join(sp.ctx.Dir, "api/v1/cronjob_types.go"),
171-
`to be serialized.`, CronjobSpecExplaination)
174+
`to be serialized.`, cronjobSpecExplaination)
172175
hackutils.CheckError("fixing cronjob_types.go", err)
173176

174177
err = pluginutil.InsertCode(
175178
filepath.Join(sp.ctx.Dir, "api/v1/cronjob_types.go"),
176-
`type CronJobSpec struct {`, CronjobSpecStruct)
179+
`type CronJobSpec struct {`, cronjobSpecStruct)
177180
hackutils.CheckError("fixing cronjob_types.go", err)
178181

179182
err = pluginutil.ReplaceInFile(
@@ -187,7 +190,7 @@ func (sp *Sample) updateSpec() {
187190

188191
err = pluginutil.InsertCode(
189192
filepath.Join(sp.ctx.Dir, "api/v1/cronjob_types.go"),
190-
`// Important: Run "make" to regenerate code after modifying this file`, CronjobList)
193+
`// Important: Run "make" to regenerate code after modifying this file`, cronjobList)
191194
hackutils.CheckError("fixing cronjob_types.go", err)
192195

193196
err = pluginutil.InsertCode(
@@ -229,13 +232,13 @@ func (sp *Sample) updateAPIStuff() {
229232
err = pluginutil.InsertCode(
230233
filepath.Join(sp.ctx.Dir, "api/v1/groupversion_info.go"),
231234
`limitations under the License.
232-
*/`, GroupversionIntro)
235+
*/`, groupVersionIntro)
233236
hackutils.CheckError("fixing groupversion_info.go", err)
234237

235238
err = pluginutil.InsertCode(
236239
filepath.Join(sp.ctx.Dir, "api/v1/groupversion_info.go"),
237240
` "sigs.k8s.io/controller-runtime/pkg/scheme"
238-
)`, GroupversionSchema)
241+
)`, groupVersionSchema)
239242
hackutils.CheckError("fixing groupversion_info.go", err)
240243
}
241244

@@ -244,7 +247,7 @@ func (sp *Sample) updateController() {
244247
err = pluginutil.InsertCode(
245248
filepath.Join(sp.ctx.Dir, "internal/controller/cronjob_controller.go"),
246249
`limitations under the License.
247-
*/`, ControllerIntro)
250+
*/`, controllerIntro)
248251
hackutils.CheckError("fixing cronjob_controller.go", err)
249252

250253
err = pluginutil.ReplaceInFile(
@@ -258,7 +261,7 @@ func (sp *Sample) updateController() {
258261
"sigs.k8s.io/controller-runtime/pkg/log"
259262
260263
batchv1 "tutorial.kubebuilder.io/project/api/v1"
261-
)`, ControllerImport)
264+
)`, controllerImport)
262265
hackutils.CheckError("fixing cronjob_controller.go", err)
263266

264267
err = pluginutil.InsertCode(
@@ -270,12 +273,12 @@ func (sp *Sample) updateController() {
270273
err = pluginutil.InsertCode(
271274
filepath.Join(sp.ctx.Dir, "internal/controller/cronjob_controller.go"),
272275
` Clock
273-
}`, ControllerMockClock)
276+
}`, controllerMockClock)
274277
hackutils.CheckError("fixing cronjob_controller.go", err)
275278

276279
err = pluginutil.InsertCode(
277280
filepath.Join(sp.ctx.Dir, "internal/controller/cronjob_controller.go"),
278-
`// +kubebuilder:rbac:groups=batch.tutorial.kubebuilder.io,resources=cronjobs/finalizers,verbs=update`, ControllerReconcile)
281+
`// +kubebuilder:rbac:groups=batch.tutorial.kubebuilder.io,resources=cronjobs/finalizers,verbs=update`, controllerReconcile)
279282
hackutils.CheckError("fixing cronjob_controller.go", err)
280283

281284
err = pluginutil.ReplaceInFile(
@@ -285,12 +288,12 @@ func (sp *Sample) updateController() {
285288
// TODO(user): your logic here
286289
287290
return ctrl.Result{}, nil
288-
}`, ControllerReconcileLogic)
291+
}`, controllerReconcileLogic)
289292
hackutils.CheckError("fixing cronjob_controller.go", err)
290293

291294
err = pluginutil.InsertCode(
292295
filepath.Join(sp.ctx.Dir, "internal/controller/cronjob_controller.go"),
293-
`SetupWithManager(mgr ctrl.Manager) error {`, ControllerSetupWithManager)
296+
`SetupWithManager(mgr ctrl.Manager) error {`, controllerSetupWithManager)
294297
hackutils.CheckError("fixing cronjob_controller.go", err)
295298

296299
err = pluginutil.InsertCode(
@@ -313,7 +316,7 @@ func (sp *Sample) updateMain() {
313316
err = pluginutil.InsertCode(
314317
filepath.Join(sp.ctx.Dir, "cmd/main.go"),
315318
`// +kubebuilder:scaffold:imports
316-
)`, MainBatch)
319+
)`, mainBatch)
317320
hackutils.CheckError("fixing main.go", err)
318321

319322
err = pluginutil.InsertCode(
@@ -347,7 +350,7 @@ CronJob controller's`+" `"+`SetupWithManager`+"`"+` method.
347350
filepath.Join(sp.ctx.Dir, "cmd/main.go"),
348351
`setupLog.Error(err, "unable to create controller", "controller", "CronJob")
349352
os.Exit(1)
350-
}`, MainEnableWebhook)
353+
}`, mainEnableWebhook)
351354
hackutils.CheckError("fixing main.go", err)
352355

353356
err = pluginutil.InsertCode(
@@ -512,7 +515,7 @@ func (sp *Sample) updateSuiteTest() {
512515
err = pluginutil.InsertCode(
513516
filepath.Join(sp.ctx.Dir, "internal/controller/suite_test.go"),
514517
`limitations under the License.
515-
*/`, SuiteTestIntro)
518+
*/`, suiteTestIntro)
516519
hackutils.CheckError("updating suite_test.go to add license intro", err)
517520

518521
err = pluginutil.InsertCode(
@@ -534,13 +537,13 @@ var (
534537
cfg *rest.Config
535538
k8sClient client.Client
536539
)
537-
`, SuiteTestEnv)
540+
`, suiteTestEnv)
538541
hackutils.CheckError("updating suite_test.go to add more variables", err)
539542

540543
err = pluginutil.InsertCode(
541544
filepath.Join(sp.ctx.Dir, "internal/controller/suite_test.go"),
542545
`ctx, cancel = context.WithCancel(context.TODO())
543-
`, SuiteTestReadCRD)
546+
`, suiteTestReadCRD)
544547
hackutils.CheckError("updating suite_test.go to add text about CRD", err)
545548

546549
err = pluginutil.InsertCode(
@@ -559,7 +562,7 @@ var (
559562
Expect(err).NotTo(HaveOccurred())
560563
561564
// +kubebuilder:scaffold:scheme
562-
`, SuiteTestAddSchema)
565+
`, suiteTestAddSchema)
563566
hackutils.CheckError("updating suite_test.go to add schema", err)
564567

565568
err = pluginutil.InsertCode(
@@ -568,7 +571,7 @@ var (
568571
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
569572
Expect(err).NotTo(HaveOccurred())
570573
Expect(k8sClient).NotTo(BeNil())
571-
`, SuiteTestDescription)
574+
`, suiteTestDescription)
572575
hackutils.CheckError("updating suite_test.go for test description", err)
573576

574577
err = pluginutil.ReplaceInFile(
@@ -580,7 +583,7 @@ var _ = AfterSuite(func() {
580583
err := testEnv.Stop()
581584
Expect(err).NotTo(HaveOccurred())
582585
})
583-
`, SuiteTestCleanup)
586+
`, suiteTestCleanup)
584587
hackutils.CheckError("updating suite_test.go to cleanup tests", err)
585588
}
586589

@@ -623,7 +626,7 @@ func (sp *Sample) updateExample() {
623626
// samples/batch_v1_cronjob
624627
err = pluginutil.InsertCode(
625628
filepath.Join(sp.ctx.Dir, "config/samples/batch_v1_cronjob.yaml"),
626-
`spec:`, CronjobSample)
629+
`spec:`, cronjobSample)
627630
hackutils.CheckError("fixing samples/batch_v1_cronjob.yaml", err)
628631

629632
err = pluginutil.ReplaceInFile(
@@ -634,6 +637,6 @@ func (sp *Sample) updateExample() {
634637

635638
func (sp *Sample) addControllerTest() {
636639
var fs = afero.NewOsFs()
637-
err := afero.WriteFile(fs, filepath.Join(sp.ctx.Dir, "internal/controller/cronjob_controller_test.go"), []byte(ControllerTest), 0600)
640+
err := afero.WriteFile(fs, filepath.Join(sp.ctx.Dir, "internal/controller/cronjob_controller_test.go"), []byte(controllerTest), 0600)
638641
hackutils.CheckError("adding cronjob_controller_test", err)
639642
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
package cronjob
1818

19-
const MainBatch = `
19+
const mainBatch = `
2020
// +kubebuilder:docs-gen:collapse=Imports
2121
2222
/*
@@ -28,7 +28,7 @@ If we would be using any other CRD we would have to add their scheme the same wa
2828
Builtin types such as Job have their scheme added by` + " `" + `clientgoscheme` + "`" + `.
2929
*/`
3030

31-
const MainEnableWebhook = `
31+
const mainEnableWebhook = `
3232
3333
/*
3434
We'll also set up webhooks for our type, which we'll talk about next.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
package cronjob
1818

19-
const GroupversionIntro = `
19+
const groupVersionIntro = `
2020
// +kubebuilder:docs-gen:collapse=Apache License
2121
2222
/*
@@ -28,7 +28,7 @@ metadata for the CRDs it creates from this package.
2828
*/
2929
`
3030

31-
const GroupversionSchema = `
31+
const groupVersionSchema = `
3232
/*
3333
Then, we have the commonly useful variables that help us set up our Scheme.
3434
Since we need to use all the types in this package in our controller, it's

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
package cronjob
1818

19-
const CronjobSample = `
19+
const cronjobSample = `
2020
schedule: "*/1 * * * *"
2121
startingDeadlineSeconds: 60
2222
concurrencyPolicy: Allow # explicitly specify, but Allow is also default.

0 commit comments

Comments
 (0)