-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛: (go/v4) Scaffold no header when lincense is type none #3391
Conversation
Hi @yyy1000. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
hack/docs/generate_samples.go
Outdated
@@ -51,7 +50,7 @@ func UpdateComponentConfigTutorial() { | |||
} | |||
|
|||
func UpdateCronjobTutorial() { | |||
binaryPath := util.KubebuilderBinName | |||
binaryPath := "/tmp/kubebuilder/bin/kubebuilder" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we revert this one and still use the const?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think use the const 'util.KubebuilderBinName' couldn't work. This will not use the kubebuilder binary complied by the command. 🤔 See #3390
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been working so why it would stop to work within the changes of this PR?
Can you please revert this one and squash for we get it merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, I think it has been working for only two days. The last commit changing it is : d0a1806
So I think at least not so many people run it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is called when we run make generate
.
The make generate
is called when we do the CI checks and would NOT get merged if does not work.
See this code successfully executed to verify your PR: https://github.com/kubernetes-sigs/kubebuilder/actions/runs/4902477788/jobs/8754346010
I can ensure that works either and you can properly very that by just running without these changes make generate
locally within the master branch.
Could you please revert these changes that have no relation to the scope of the PR?
hack/docs/generate_samples.go
Outdated
@@ -36,7 +35,7 @@ func main() { | |||
} | |||
|
|||
func UpdateComponentConfigTutorial() { | |||
binaryPath := util.KubebuilderBinName | |||
binaryPath := "/tmp/kubebuilder/bin/kubebuilder" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just please rebase with the master, for we have only your specific change and squash the commits. The change shows great. So we can get this one merged.
/ok-to-test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @yyy1000,
Thank you for your contribution. 🥇 Just a few nits and then it seems great to fly:
- Remove changes in generate_samples.go, which are out of the scope of this PR and unnecessary and should not be made. We should not replace the const values that centralize the Kubebuilder binary with strings within the path.
- Squash the commits
Fixed it already. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approved cancel
Hi @yyy1000,
Sorry but after re-check this one it still not quite right. See:
- If none then it is right. The hack/header-file should not be scaffolded and we change the makefile target
- However, it is missing:
I am a user. I would like to have the current behaviour done when I select none for a new optional flag with a name that make s it clearer (copyright)
Sorry for that. I used to think that only applied to 'license' flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @yyy1000,
Try to create a new project and use --license=none. You will see that it will create the header within the copyright.
So, the idea is:
- a) none should be NONE. That means no license at all
- b) we can add a new optional value for the flag license to allow a user inform
--license=copyright
to have the current behaviour.
Following the places where the change needs to be made. See:
kubebuilder/pkg/plugins/golang/v4/scaffolds/internal/templates/hack/boilerplate.go
Lines 100 to 111 in 7aa151a
const boilerplateTemplate = `/* {{ if .Owner -}} Copyright {{ .Year }} {{ .Owner }}. {{- else -}} Copyright {{ .Year }}. {{- end }} {{ index .Licenses .License }}*/` var knownLicenses = map[string]string{ "apache2": apache2, "none": "", } kubebuilder/pkg/plugins/golang/v4/init.go
Lines 87 to 89 in 7aa151a
fs.StringVar(&p.license, "license", "apache2", "license to use to boilerplate, may be one of 'apache2', 'none'") fs.StringVar(&p.owner, "owner", "", "owner to add to the copyright")
Please, let me know if that make sense and feel free to reach out if you have questions.
feat: change the binaryPath when update tutorial fix: revert const name fix: current behavior
Sorry for missing that :) Thanks for your help, I have fixed it. |
@@ -106,8 +106,8 @@ Copyright {{ .Year }}. | |||
{{ index .Licenses .License }}*/` | |||
|
|||
var knownLicenses = map[string]string{ | |||
"apache2": apache2, | |||
"none": "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If we remove none as an option, then it will fail when used. See:
kubebuilder/pkg/plugins/golang/v4/scaffolds/internal/templates/hack/boilerplate.go
Lines 51 to 63 in 7aa151a
func (f Boilerplate) Validate() error { if f.License == "" { // A default license will be set later } else if _, found := knownLicenses[f.License]; found { // One of the know licenses } else if _, found := f.Licenses[f.License]; found { // A map containing the requested license was also provided } else { return fmt.Errorf("unknown specified license %s", f.License) } return nil } - If we keep none and copyright within the value "" instead of a const, we need to ensure the behaviour and that when we use one or another, the expected output will occur.
- If we do not inform the tag license, then apache2 should be outputted by default.
Did you test it out locally? Following the steps:
-
If the license is not informed, we should keep the same current behaviour output apache2 as default.
-
- Create a new project: $ kubebuilder init
-
- Create a new API: $ kubebuilder create api --group ship --version v1beta1 --kind Frigate
-
- Check the header of any go file. $ cat internal/controller/suite_test.go
It should have outputted apache2
-
If we use --license=apache2, we should the apache2 as above
-
- Create a new project: $ kubebuilder init --license=apache2
-
- Create a new API: $ kubebuilder create api --group ship --version v1beta1 --kind Frigate
-
- Check the header of any go file. $ cat internal/controller/suite_test.go
-
If we use --license=none, we should not scaffold hack/bolerplate.txt, and we should not scaffold the path in the Makefile file target
-
- Create a new project: $ kubebuilder init --license=none
-
- Create a new API: $ kubebuilder create api --group ship --version v1beta1 --kind Frigate
-
- Check the header of any go file. $ cat internal/controller/suite_test.go
- If we use --license=copyright, then we should scaffold hack/bolerplate.txt and have only the header with the copyright . See:
kubebuilder/pkg/plugins/golang/v4/scaffolds/internal/templates/hack/boilerplate.go
Lines 100 to 106 in 7aa151a
const boilerplateTemplate = `/* {{ if .Owner -}} Copyright {{ .Year }} {{ .Owner }}. {{- else -}} Copyright {{ .Year }}. {{- end }} {{ index .Licenses .License }}*/`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I think it's OK to delete the option 'none'. If we use the option 'none', it will not execute scaffold.Execute(bpFile)
. So knownLicenses
will not be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, how none can be valid and not exist in knownLicenses[f.License]?
"apache2": apache2, | ||
"none": "", | ||
"apache2": apache2, | ||
"copyright": "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's right. We can define the const value 'copyright' a empty string. Just like const copyright = ""
?
"apache2": apache2, | ||
"none": "", | ||
"apache2": apache2, | ||
"copyright": "", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot have any copyright withing the value of none.
I think we might need to check if is possible to pass here a const copyright wich will be == boilerplateTemplate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think the 'const copyright' == “”(an empty string) is enough. the {{ index .Licenses .License }}*/
` will just be an empty string.
As I tested it, it works OK now. Can we continue to merge it or should I add some tests in the PR first? |
Owner: s.owner, | ||
} | ||
bpFile.Path = s.boilerplatePath | ||
if err := scaffold.Execute(bpFile); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, that's a good question. 'none' is valid even if not exist in knownLicenses[f.License].
Let me explain it for you.
If we pass '--license=none', then it will skip this(line 90).
In scaffold.Execute(bpFile)
, it will call SetTemplateDefaults(
) and Validate()
. So if we set 'none', it will never use knownLicenses[f.License]
. Does it make sense? @camilamacedo86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems OK. Thank you for your contribution 🥇
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, yyy1000 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm |
Description
Fix #3377
Now it would not scaffold any header if we use 'none' in license option.