Skip to content

Commit 1716f41

Browse files
authored
Merge pull request #4651 from kersten/fix/kustomizev2-avoid-shadowing-config-resource-err
🌱 (chore): avoid shadowing of 'config', 'resource', and 'err' in kustomize/v2 scaffolds
2 parents 4e6fda8 + 74f474c commit 1716f41

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

pkg/plugins/common/kustomize/v2/scaffolds/api.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ type apiScaffolder struct {
4848
}
4949

5050
// NewAPIScaffolder returns a new Scaffolder for API/controller creation operations
51-
func NewAPIScaffolder(config config.Config, res resource.Resource, force bool) plugins.Scaffolder {
51+
func NewAPIScaffolder(cfg config.Config, res resource.Resource, force bool) plugins.Scaffolder {
5252
return &apiScaffolder{
53-
config: config,
53+
config: cfg,
5454
resource: res,
5555
force: force,
5656
}
@@ -95,8 +95,8 @@ func (s *apiScaffolder) Scaffold() error {
9595
kustomizeFilePath := "config/default/kustomization.yaml"
9696
err := pluginutil.UncommentCode(kustomizeFilePath, "#- ../crd", `#`)
9797
if err != nil {
98-
hasCRUncommented, err := pluginutil.HasFileContentWith(kustomizeFilePath, "- ../crd")
99-
if !hasCRUncommented || err != nil {
98+
hasCRUncommented, errCheck := pluginutil.HasFileContentWith(kustomizeFilePath, "- ../crd")
99+
if !hasCRUncommented || errCheck != nil {
100100
log.Errorf("Unable to find the target #- ../crd to uncomment in the file "+
101101
"%s.", kustomizeFilePath)
102102
}

pkg/plugins/common/kustomize/v2/scaffolds/init.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ type initScaffolder struct {
4343
}
4444

4545
// NewInitScaffolder returns a new Scaffolder for project initialization operations
46-
func NewInitScaffolder(config config.Config) plugins.Scaffolder {
46+
func NewInitScaffolder(cfg config.Config) plugins.Scaffolder {
4747
return &initScaffolder{
48-
config: config,
48+
config: cfg,
4949
}
5050
}
5151

pkg/plugins/common/kustomize/v2/scaffolds/webhook.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ type webhookScaffolder struct {
4747
}
4848

4949
// NewWebhookScaffolder returns a new Scaffolder for v2 webhook creation operations
50-
func NewWebhookScaffolder(config config.Config, resource resource.Resource, force bool) plugins.Scaffolder {
50+
func NewWebhookScaffolder(cfg config.Config, res resource.Resource, force bool) plugins.Scaffolder {
5151
return &webhookScaffolder{
52-
config: config,
53-
resource: resource,
52+
config: cfg,
53+
resource: res,
5454
force: force,
5555
}
5656
}
@@ -116,17 +116,17 @@ func (s *webhookScaffolder) Scaffold() error {
116116
kustomizeFilePath := "config/default/kustomization.yaml"
117117
err = pluginutil.UncommentCode(kustomizeFilePath, "#- ../webhook", `#`)
118118
if err != nil {
119-
hasWebHookUncommented, err := pluginutil.HasFileContentWith(kustomizeFilePath, "- ../webhook")
120-
if !hasWebHookUncommented || err != nil {
119+
hasWebHookUncommented, errCheck := pluginutil.HasFileContentWith(kustomizeFilePath, "- ../webhook")
120+
if !hasWebHookUncommented || errCheck != nil {
121121
log.Errorf("Unable to find the target #- ../webhook to uncomment in the file "+
122122
"%s.", kustomizeFilePath)
123123
}
124124
}
125125

126126
err = pluginutil.UncommentCode(kustomizeFilePath, "#patches:", `#`)
127127
if err != nil {
128-
hasWebHookUncommented, err := pluginutil.HasFileContentWith(kustomizeFilePath, "patches:")
129-
if !hasWebHookUncommented || err != nil {
128+
hasWebHookUncommented, errCheck := pluginutil.HasFileContentWith(kustomizeFilePath, "patches:")
129+
if !hasWebHookUncommented || errCheck != nil {
130130
log.Errorf("Unable to find the line '#patches:' to uncomment in the file "+
131131
"%s.", kustomizeFilePath)
132132
}
@@ -136,8 +136,9 @@ func (s *webhookScaffolder) Scaffold() error {
136136
# target:
137137
# kind: Deployment`, `#`)
138138
if err != nil {
139-
hasWebHookUncommented, err := pluginutil.HasFileContentWith(kustomizeFilePath, "- path: manager_webhook_patch.yaml")
140-
if !hasWebHookUncommented || err != nil {
139+
hasWebHookUncommented, errCheck := pluginutil.HasFileContentWith(kustomizeFilePath,
140+
"- path: manager_webhook_patch.yaml")
141+
if !hasWebHookUncommented || errCheck != nil {
141142
log.Errorf("Unable to find the target #- path: manager_webhook_patch.yaml to uncomment in the file "+
142143
"%s.", kustomizeFilePath)
143144
}

0 commit comments

Comments
 (0)