Skip to content

Commit

Permalink
Merge pull request #3391 from yyy1000/fix-license
Browse files Browse the repository at this point in the history
馃悰: (go/v4) Scaffold no header when lincense is type none
  • Loading branch information
k8s-ci-robot committed May 8, 2023
2 parents 4a04609 + 8b81fd1 commit 1fa2170
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
41 changes: 24 additions & 17 deletions pkg/plugins/golang/v4/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,33 @@ func (s *initScaffolder) Scaffold() error {
machinery.WithConfig(s.config),
)

bpFile := &hack.Boilerplate{
License: s.license,
Owner: s.owner,
}
bpFile.Path = s.boilerplatePath
if err := scaffold.Execute(bpFile); err != nil {
return err
}
if s.license != "none" {
bpFile := &hack.Boilerplate{
License: s.license,
Owner: s.owner,
}
bpFile.Path = s.boilerplatePath
if err := scaffold.Execute(bpFile); err != nil {
return err
}

boilerplate, err := afero.ReadFile(s.fs.FS, s.boilerplatePath)
if err != nil {
return err
boilerplate, err := afero.ReadFile(s.fs.FS, s.boilerplatePath)
if err != nil {
return err
}
// Initialize the machinery.Scaffold that will write the files to disk
scaffold = machinery.NewScaffold(s.fs,
machinery.WithConfig(s.config),
machinery.WithBoilerplate(string(boilerplate)),
)
} else {
s.boilerplatePath = ""
// Initialize the machinery.Scaffold without boilerplate
scaffold = machinery.NewScaffold(s.fs,
machinery.WithConfig(s.config),
)
}

// Initialize the machinery.Scaffold that will write the files to disk
scaffold = machinery.NewScaffold(s.fs,
machinery.WithConfig(s.config),
machinery.WithBoilerplate(string(boilerplate)),
)

// If the KustomizeV2 was used to do the scaffold then
// we need to ensure that we use its supported Kustomize Version
// in order to support it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ Copyright {{ .Year }}.
{{ index .Licenses .License }}*/`

var knownLicenses = map[string]string{
"apache2": apache2,
"none": "",
"apache2": apache2,
"copyright": "",
}

const apache2 = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
{{ if .BoilerplatePath -}}
$(CONTROLLER_GEN) object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
{{- else -}}
$(CONTROLLER_GEN) object paths="./..."
{{- end }}
.PHONY: fmt
fmt: ## Run go fmt against code.
Expand Down

0 comments on commit 1fa2170

Please sign in to comment.