Skip to content
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

Merged
merged 1 commit into from
May 8, 2023

Conversation

yyy1000
Copy link
Member

@yyy1000 yyy1000 commented May 6, 2023

Description
Fix #3377
Now it would not scaffold any header if we use 'none' in license option.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 6, 2023
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 6, 2023
@@ -51,7 +50,7 @@ func UpdateComponentConfigTutorial() {
}

func UpdateCronjobTutorial() {
binaryPath := util.KubebuilderBinName
binaryPath := "/tmp/kubebuilder/bin/kubebuilder"
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

@camilamacedo86 camilamacedo86 May 6, 2023

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?

Copy link
Member Author

@yyy1000 yyy1000 May 6, 2023

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.

Copy link
Member

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?

@@ -36,7 +35,7 @@ func main() {
}

func UpdateComponentConfigTutorial() {
binaryPath := util.KubebuilderBinName
binaryPath := "/tmp/kubebuilder/bin/kubebuilder"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here?

Copy link
Member

@camilamacedo86 camilamacedo86 left a 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

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 6, 2023
Copy link
Member

@camilamacedo86 camilamacedo86 left a 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

@yyy1000
Copy link
Member Author

yyy1000 commented May 7, 2023

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!

camilamacedo86
camilamacedo86 previously approved these changes May 7, 2023
Copy link
Member

@camilamacedo86 camilamacedo86 left a 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)

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 7, 2023
@camilamacedo86 camilamacedo86 added this to the v3.11.0 milestone May 7, 2023
@camilamacedo86 camilamacedo86 dismissed their stale review May 7, 2023 07:07

missing criteria

@camilamacedo86 camilamacedo86 removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 7, 2023
@k8s-ci-robot k8s-ci-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 7, 2023
@yyy1000
Copy link
Member Author

yyy1000 commented May 7, 2023

/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.
Do you mean we can add a new optional flag called 'copyright' and make the new optional flag has the same behavior like 'license'?

Copy link
Member

@camilamacedo86 camilamacedo86 left a 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:

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
@yyy1000
Copy link
Member Author

yyy1000 commented May 8, 2023

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:

Please, let me know if that make sense and feel free to reach out if you have questions.

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": "",
Copy link
Member

@camilamacedo86 camilamacedo86 May 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yyy1000,

  • If we remove none as an option, then it will fail when used. See:
    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.

    1. Create a new project: $ kubebuilder init
    1. Create a new API: $ kubebuilder create api --group ship --version v1beta1 --kind Frigate
    1. 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

    1. Create a new project: $ kubebuilder init --license=apache2
    1. Create a new API: $ kubebuilder create api --group ship --version v1beta1 --kind Frigate
    1. 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

    1. Create a new project: $ kubebuilder init --license=none
    1. Create a new API: $ kubebuilder create api --group ship --version v1beta1 --kind Frigate
    1. Check the header of any go file. $ cat internal/controller/suite_test.go

Copy link
Member Author

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.

Copy link
Member

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": "",
Copy link
Member Author

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": "",
Copy link
Member

@camilamacedo86 camilamacedo86 May 8, 2023

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

Copy link
Member Author

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.

@yyy1000
Copy link
Member Author

yyy1000 commented May 8, 2023

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 {
Copy link
Member Author

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

Copy link
Member

@camilamacedo86 camilamacedo86 left a 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

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 8, 2023
@camilamacedo86
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 8, 2023
@k8s-ci-robot k8s-ci-robot merged commit 1fa2170 into kubernetes-sigs:master May 8, 2023
@yyy1000 yyy1000 deleted the fix-license branch May 8, 2023 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lincense type none is scaffolding a header
3 participants