Skip to content

Commit bab2741

Browse files
🌱 Enable var-naming lint and fix issues for Kubebuilder CLI (#4460)
Enable var-naming lint and fix issues for Kubebuilder CLI
1 parent 1d12979 commit bab2741

File tree

11 files changed

+26
-27
lines changed

11 files changed

+26
-27
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ linters-settings:
3838
disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings.
3939
- name: increment-decrement
4040
- name: var-naming
41-
disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings.
4241
- name: var-declaration
4342
- name: package-comments
4443
disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings.

hack/docs/generate_samples.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
// Make sure executing `build_kb` to generate kb executable from the source code
2828
const KubebuilderBinName = "/tmp/kubebuilder/bin/kubebuilder"
2929

30-
type tutorial_generator interface {
30+
type tutorialGenerator interface {
3131
Prepare()
3232
GenerateSampleProject()
3333
UpdateTutorial()
@@ -52,7 +52,7 @@ func main() {
5252
}
5353
}
5454

55-
func updateTutorial(generator tutorial_generator) {
55+
func updateTutorial(generator tutorialGenerator) {
5656
generator.Prepare()
5757
generator.GenerateSampleProject()
5858
generator.UpdateTutorial()

hack/docs/internal/getting-started/generate_getting_started.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func NewSample(binaryPath, samplePath string) Sample {
3939
}
4040

4141
func (sp *Sample) UpdateTutorial() {
42-
sp.updateApi()
42+
sp.updateAPI()
4343
sp.updateSample()
4444
sp.updateController()
4545
sp.updateControllerTest()
@@ -100,7 +100,7 @@ func (sp *Sample) updateControllerTest() {
100100
hackutils.CheckError("add spec apis", err)
101101
}
102102

103-
func (sp *Sample) updateApi() {
103+
func (sp *Sample) updateAPI() {
104104
var err error
105105
path := "api/v1alpha1/memcached_types.go"
106106
err = pluginutil.InsertCode(
@@ -122,10 +122,10 @@ func (sp *Sample) updateApi() {
122122
`)
123123
hackutils.CheckError("collapse imports in memcached api", err)
124124

125-
err = pluginutil.ReplaceInFile(filepath.Join(sp.ctx.Dir, path), oldSpecApi, newSpecApi)
125+
err = pluginutil.ReplaceInFile(filepath.Join(sp.ctx.Dir, path), oldSpecAPI, newSpecAPI)
126126
hackutils.CheckError("replace spec api", err)
127127

128-
err = pluginutil.ReplaceInFile(filepath.Join(sp.ctx.Dir, path), oldStatusApi, newStatusApi)
128+
err = pluginutil.ReplaceInFile(filepath.Join(sp.ctx.Dir, path), oldStatusAPI, newStatusAPI)
129129
hackutils.CheckError("replace status api", err)
130130
}
131131

@@ -242,19 +242,19 @@ func (sp *Sample) CodeGen() {
242242
hackutils.CheckError("Failed to run make build-installer for getting started tutorial", err)
243243
}
244244

245-
const oldSpecApi = "// Foo is an example field of Memcached. Edit memcached_types.go to remove/update\n\tFoo string `json:\"foo,omitempty\"`"
246-
const newSpecApi = `// Size defines the number of Memcached instances
245+
const oldSpecAPI = "// Foo is an example field of Memcached. Edit memcached_types.go to remove/update\n\tFoo string `json:\"foo,omitempty\"`"
246+
const newSpecAPI = `// Size defines the number of Memcached instances
247247
// The following markers will use OpenAPI v3 schema to validate the value
248248
// More info: https://book.kubebuilder.io/reference/markers/crd-validation.html
249249
// +kubebuilder:validation:Minimum=1
250250
// +kubebuilder:validation:Maximum=3
251251
// +kubebuilder:validation:ExclusiveMaximum=false
252252
Size int32 ` + "`json:\"size,omitempty\"`"
253253

254-
const oldStatusApi = `// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
254+
const oldStatusAPI = `// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
255255
// Important: Run "make" to regenerate code after modifying this file`
256256

257-
const newStatusApi = `// Represents the observations of a Memcached's current state.
257+
const newStatusAPI = `// Represents the observations of a Memcached's current state.
258258
// Memcached.status.conditions.type are: "Available", "Progressing", and "Degraded"
259259
// Memcached.status.conditions.status are one of True, False, Unknown.
260260
// Memcached.status.conditions.reason the value should be a CamelCase string and producers of specific

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ func (sp *Sample) UpdateTutorial() {
9393

9494
// Update files according to the multiversion
9595
sp.updateCronjobV1DueForce()
96-
sp.updateApiV1()
97-
sp.updateApiV2()
96+
sp.updateAPIV1()
97+
sp.updateAPIV2()
9898
sp.updateWebhookV2()
9999
sp.updateConversionFiles()
100100
sp.updateSampleV2()
@@ -379,7 +379,7 @@ Most of the conversion is straightforward copying, except for converting our cha
379379
hackutils.CheckError("replace covert info at hub v2", err)
380380
}
381381

382-
func (sp *Sample) updateApiV1() {
382+
func (sp *Sample) updateAPIV1() {
383383
path := "api/v1/cronjob_types.go"
384384
err := pluginutil.InsertCode(
385385
filepath.Join(sp.ctx.Dir, path),
@@ -655,7 +655,7 @@ CronJob controller's `+"`SetupWithManager`"+` method.
655655

656656
}
657657

658-
func (sp *Sample) updateApiV2() {
658+
func (sp *Sample) updateAPIV2() {
659659
path := "api/v2/cronjob_types.go"
660660
err := pluginutil.InsertCode(
661661
filepath.Join(sp.ctx.Dir, path),

pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/network-policy/allow-metrics-traffic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package network_policy
17+
package networkpolicy
1818

1919
import (
2020
"path/filepath"

pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/network-policy/allow-webhook-traffic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package network_policy
17+
package networkpolicy
1818

1919
import (
2020
"path/filepath"

pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/network-policy/kustomization.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package network_policy
17+
package networkpolicy
1818

1919
import (
2020
"path/filepath"

pkg/plugins/optional/helm/v1alpha/scaffolds/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang/deploy-image/v1alpha1"
3535
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm"
3636
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates"
37-
chart_templates "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates"
37+
charttemplates "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates"
3838
templatescertmanager "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/cert-manager"
3939
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/manager"
4040
templatesmetrics "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/metrics"
@@ -93,7 +93,7 @@ func (s *initScaffolder) Scaffold() error {
9393
Force: s.force,
9494
},
9595
&templates.HelmIgnore{},
96-
&chart_templates.HelmHelpers{},
96+
&charttemplates.HelmHelpers{},
9797
&manager.ManagerDeployment{
9898
Force: s.force,
9999
DeployImages: len(imagesEnvVars) > 0,

pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/helpers_tpl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package chart_templates
17+
package charttemplates
1818

1919
import (
2020
"path/filepath"

test/e2e/v4/generate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func GenerateV4(kbc *utils.TestContext) {
7070
certManagerTarget, "#")).To(Succeed())
7171
ExpectWithOffset(1, pluginutil.UncommentCode(
7272
filepath.Join(kbc.Dir, "config", "prometheus", "kustomization.yaml"),
73-
monitorTlsPatch, "#")).To(Succeed())
73+
monitorTLSPatch, "#")).To(Succeed())
7474
ExpectWithOffset(1, pluginutil.UncommentCode(
7575
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
7676
metricsCertPatch, "#")).To(Succeed())
@@ -186,7 +186,7 @@ func GenerateV4WithNetworkPolicies(kbc *utils.TestContext) {
186186
metricsCertReplaces, "#")).To(Succeed())
187187
ExpectWithOffset(1, pluginutil.UncommentCode(
188188
filepath.Join(kbc.Dir, "config", "prometheus", "kustomization.yaml"),
189-
monitorTlsPatch, "#")).To(Succeed())
189+
monitorTLSPatch, "#")).To(Succeed())
190190

191191
By("uncomment kustomization.yaml to enable network policy")
192192
ExpectWithOffset(1, pluginutil.UncommentCode(
@@ -454,7 +454,7 @@ func uncommentKustomizeCoversion(kbc *utils.TestContext) {
454454
fmt.Sprintf(certName, kbc.Group, kbc.Domain), "#")).To(Succeed())
455455
}
456456

457-
const monitorTlsPatch = `#patches:
457+
const monitorTLSPatch = `#patches:
458458
# - path: monitor_tls_patch.yaml
459459
# target:
460460
# kind: ServiceMonitor`

0 commit comments

Comments
 (0)