Skip to content

Commit

Permalink
🌱 Enable var-naming lint and fix issues for Kubebuilder CLI (kubernet…
Browse files Browse the repository at this point in the history
…es-sigs#4460)

Enable var-naming lint and fix issues for Kubebuilder CLI
  • Loading branch information
camilamacedo86 authored Jan 1, 2025
1 parent 1d12979 commit bab2741
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 27 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ linters-settings:
disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings.
- name: increment-decrement
- name: var-naming
disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings.
- name: var-declaration
- name: package-comments
disabled: true # TODO: Investigate if it should be enabled. Disabled for now due to many findings.
Expand Down
4 changes: 2 additions & 2 deletions hack/docs/generate_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// Make sure executing `build_kb` to generate kb executable from the source code
const KubebuilderBinName = "/tmp/kubebuilder/bin/kubebuilder"

type tutorial_generator interface {
type tutorialGenerator interface {
Prepare()
GenerateSampleProject()
UpdateTutorial()
Expand All @@ -52,7 +52,7 @@ func main() {
}
}

func updateTutorial(generator tutorial_generator) {
func updateTutorial(generator tutorialGenerator) {
generator.Prepare()
generator.GenerateSampleProject()
generator.UpdateTutorial()
Expand Down
16 changes: 8 additions & 8 deletions hack/docs/internal/getting-started/generate_getting_started.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewSample(binaryPath, samplePath string) Sample {
}

func (sp *Sample) UpdateTutorial() {
sp.updateApi()
sp.updateAPI()
sp.updateSample()
sp.updateController()
sp.updateControllerTest()
Expand Down Expand Up @@ -100,7 +100,7 @@ func (sp *Sample) updateControllerTest() {
hackutils.CheckError("add spec apis", err)
}

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

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

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

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

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

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

const newStatusApi = `// Represents the observations of a Memcached's current state.
const newStatusAPI = `// Represents the observations of a Memcached's current state.
// Memcached.status.conditions.type are: "Available", "Progressing", and "Degraded"
// Memcached.status.conditions.status are one of True, False, Unknown.
// Memcached.status.conditions.reason the value should be a CamelCase string and producers of specific
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (sp *Sample) UpdateTutorial() {

// Update files according to the multiversion
sp.updateCronjobV1DueForce()
sp.updateApiV1()
sp.updateApiV2()
sp.updateAPIV1()
sp.updateAPIV2()
sp.updateWebhookV2()
sp.updateConversionFiles()
sp.updateSampleV2()
Expand Down Expand Up @@ -379,7 +379,7 @@ Most of the conversion is straightforward copying, except for converting our cha
hackutils.CheckError("replace covert info at hub v2", err)
}

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

}

func (sp *Sample) updateApiV2() {
func (sp *Sample) updateAPIV2() {
path := "api/v2/cronjob_types.go"
err := pluginutil.InsertCode(
filepath.Join(sp.ctx.Dir, path),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package network_policy
package networkpolicy

import (
"path/filepath"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package network_policy
package networkpolicy

import (
"path/filepath"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package network_policy
package networkpolicy

import (
"path/filepath"
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugins/optional/helm/v1alpha/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang/deploy-image/v1alpha1"
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm"
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates"
chart_templates "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates"
charttemplates "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates"
templatescertmanager "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/cert-manager"
"sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/manager"
templatesmetrics "sigs.k8s.io/kubebuilder/v4/pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/metrics"
Expand Down Expand Up @@ -93,7 +93,7 @@ func (s *initScaffolder) Scaffold() error {
Force: s.force,
},
&templates.HelmIgnore{},
&chart_templates.HelmHelpers{},
&charttemplates.HelmHelpers{},
&manager.ManagerDeployment{
Force: s.force,
DeployImages: len(imagesEnvVars) > 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package chart_templates
package charttemplates

import (
"path/filepath"
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/v4/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func GenerateV4(kbc *utils.TestContext) {
certManagerTarget, "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "prometheus", "kustomization.yaml"),
monitorTlsPatch, "#")).To(Succeed())
monitorTLSPatch, "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"),
metricsCertPatch, "#")).To(Succeed())
Expand Down Expand Up @@ -186,7 +186,7 @@ func GenerateV4WithNetworkPolicies(kbc *utils.TestContext) {
metricsCertReplaces, "#")).To(Succeed())
ExpectWithOffset(1, pluginutil.UncommentCode(
filepath.Join(kbc.Dir, "config", "prometheus", "kustomization.yaml"),
monitorTlsPatch, "#")).To(Succeed())
monitorTLSPatch, "#")).To(Succeed())

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

const monitorTlsPatch = `#patches:
const monitorTLSPatch = `#patches:
# - path: monitor_tls_patch.yaml
# target:
# kind: ServiceMonitor`
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/v4/plugin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,10 @@ func serviceAccountToken(kbc *utils.TestContext) (out string, err error) {
if err != nil {
return out, err
}
var rawJson string
var rawJSON string
getToken := func(g Gomega) {
// Output of this is already a valid JWT token. No need to covert this from base64 to string format
rawJson, err = kbc.Kubectl.Command(
rawJSON, err = kbc.Kubectl.Command(
"create",
"--raw", fmt.Sprintf(
"/api/v1/namespaces/%s/serviceaccounts/%s/token",
Expand All @@ -634,7 +634,7 @@ func serviceAccountToken(kbc *utils.TestContext) (out string, err error) {

g.Expect(err).NotTo(HaveOccurred())
var token tokenRequest
err = json.Unmarshal([]byte(rawJson), &token)
err = json.Unmarshal([]byte(rawJSON), &token)
g.Expect(err).NotTo(HaveOccurred())

out = token.Status.Token
Expand Down

0 comments on commit bab2741

Please sign in to comment.