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

Run kustomize build with kustomize localize and add a no-verify flag. #5544

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sanaasy
Copy link

@sanaasy sanaasy commented Feb 18, 2024

Context

Closes issue: #5276

This PR adds functionality to auto-run kustomize build when the kustomize localize command is run. . This will run when --no-verify is not specified as false by the user or not specified at all when running the localize command. When the --no-verify flag is added, this check will be skipped.

🎩 Tophatted by doing:

  1. make kustomize
  2. ~/go/bin/kustomize localize . localized-results
  3. ~/go/bin/kustomize localize . localized-results --no-verify
  4. ~/go/bin/kustomize localize . localized-results --scope "/Desktop"

@k8s-ci-robot
Copy link
Contributor

This PR has multiple commits, and the default merge method is: merge.
You can request commits to be squashed using the label: tide/merge-method-squash

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.

Copy link

linux-foundation-easycla bot commented Feb 18, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Feb 18, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @sanaasy!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 18, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @sanaasy. 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 the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 18, 2024
@sanaasy sanaasy marked this pull request as draft February 18, 2024 20:14
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 18, 2024
@sanaasy
Copy link
Author

sanaasy commented Feb 18, 2024

I'm still working on tests for this issue so keeping this in draft!

Edit: this is done!

@sanaasy sanaasy force-pushed the sanaasy/add-no-verify-flag branch 4 times, most recently from b32e146 to a58784b Compare February 22, 2024 21:04
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 27, 2024
@sanaasy sanaasy marked this pull request as ready for review February 27, 2024 01:54
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 27, 2024
Copy link
Member

@stormqueen1990 stormqueen1990 left a comment

Choose a reason for hiding this comment

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

Hello there, @sanaasy! 👋

Thank you very much for your contribution.

With regards to using exec.Command, I am not sure if I understand the reasoning for choosing it over invoking the build command function directly, since localize and build are relatively co-located in the codebase. Would you mind elaborating on that decision?

kustomize/commands/localize/localize.go Outdated Show resolved Hide resolved
@sanaasy
Copy link
Author

sanaasy commented Feb 28, 2024

With regards to using exec.Command, I am not sure if I understand the reasoning for choosing it over invoking the build command function directly, since localize and build are relatively co-located in the codebase. Would you mind elaborating on that decision?

Sure! When I first wrote the code, I didn't see that the build command makeBuildCommand from the commands package was exported to be used anywhere in the code. I chose to exec this way to remove the dependency on building the command itself in the localize file and executing the Run command. If this is the preferred method though, I am happy to change it!

@stormqueen1990
Copy link
Member

Sure! When I first wrote the code, I didn't see that the build command makeBuildCommand from the commands package was exported to be used anywhere in the code. I chose to exec this way to remove the dependency on building the command itself in the localize file and executing the Run command. If this is the preferred method though, I am happy to change it!

Hi there, @sanaasy! Sorry for the delay in responding!

I have some concerns with the exec.Command() approach. Specifically, this approach requires the executable to be present in $PATH, and because it shells out to a separate command, it might be running build in a version that yields a result different from what the caller would yield.

The scenario I have in mind is something like this:

  • I have a system-wide installation of Kustomize that exists under /usr/bin/kustomize, which is at version v4.5.7.
  • I downloaded v5.3.0 to /home/myuser/bin/kustomize.
  • I run /home/myuser/bin/kustomize localize, expecting that build will also be run from this instance.
  • Instead, kustomize localize shells out to /usr/bin/kustomize (the $PATH installation), which could have a different API (and might yield a different result).

Please let me know if my understanding is incorrect, or if this scenario doesn't make sense!

@sanaasy sanaasy force-pushed the sanaasy/add-no-verify-flag branch from cf48606 to cc2aff7 Compare March 5, 2024 03:44
@sanaasy
Copy link
Author

sanaasy commented Mar 5, 2024

I have some concerns with the exec.Command() approach. Specifically, this approach requires the executable to be present in $PATH, and because it shells out to a separate command, it might be running build in a version that yields a result different from what the caller would yield.

That's a fair callout! I have updated the PR to use the local build commands instead and have verified that things work as expected. If you could take another look please!

Copy link
Member

@stormqueen1990 stormqueen1990 left a comment

Choose a reason for hiding this comment

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

Hi there, @sanaasy! 👋🏻

Thank you for your contribution! 🙏🏻

This PR is well on its way, I just have a couple of suggestions in terms of test coverage.

kustomize/commands/localize/localize_test.go Outdated Show resolved Hide resolved
kustomize/commands/localize/localize_test.go Outdated Show resolved Hide resolved
@stormqueen1990
Copy link
Member

/test all

@stormqueen1990
Copy link
Member

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label May 6, 2024
Copy link
Member

@stormqueen1990 stormqueen1990 left a comment

Choose a reason for hiding this comment

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

Found a few more bits!

kustomize/commands/localize/localize.go Outdated Show resolved Hide resolved
kustomize/commands/localize/localize.go Outdated Show resolved Hide resolved
kustomize/commands/localize/localize.go Outdated Show resolved Hide resolved
Copy link
Member

@stormqueen1990 stormqueen1990 left a comment

Choose a reason for hiding this comment

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

Thank you very much for your contribution! 🙏🏻

/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 13, 2024
@stormqueen1990
Copy link
Member

/label tide/merge-method-squash

kustomize/commands/localize/localize.go Outdated Show resolved Hide resolved
if localizedBuild == originalBuild {
log.Printf("VERIFICATION SUCCESS: `kustomize build` for %s and %s are the same after localization.\n", args.target, dst)
} else {
log.Println(copyutil.PrettyFileDiff(originalBuild, localizedBuild))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Println(copyutil.PrettyFileDiff(originalBuild, localizedBuild))
log.Println(copyutil.PrettyFileDiff(originalBuild, localizedBuild))

Curious: Is it intentional to add this log statement and explicitly mention the diff?

Copy link
Author

Choose a reason for hiding this comment

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

Yes! This is what the KEP outlined:

The command indicates success if the outputs match and throws an error with a diff summary otherwise. 

https://github.com/kubernetes-sigs/kustomize/blob/master/proposals/22-04-localize-command.md

@sanaasy sanaasy force-pushed the sanaasy/add-no-verify-flag branch from 63e5084 to b679598 Compare May 16, 2024 03:45
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 16, 2024
@sanaasy
Copy link
Author

sanaasy commented May 16, 2024

/lgtm

@k8s-ci-robot
Copy link
Contributor

@sanaasy: you cannot LGTM your own PR.

In response to this:

/lgtm

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-sigs/prow repository.

@k8s-ci-robot
Copy link
Contributor

@kushp: changing LGTM is restricted to collaborators

In response to this:

/lgtm

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-sigs/prow repository.

Copy link
Member

@stormqueen1990 stormqueen1990 left a comment

Choose a reason for hiding this comment

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

/lgtm
/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. lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 17, 2024
@stormqueen1990
Copy link
Member

/remove-label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot removed the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label May 17, 2024
Copy link
Member

@varshaprasad96 varshaprasad96 left a comment

Choose a reason for hiding this comment

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

The changes look good!

@sanaasy Thanks for the contribution!
@stormqueen1990 Thanks for reviewing and following this through! :))

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: christianh814, sanaasy, varshaprasad96

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 Jun 2, 2024
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 4, 2024
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@sanaasy
Copy link
Author

sanaasy commented Jun 4, 2024

@stormqueen1990 @varshaprasad96 👋 hello again! After Varsha had approved the PR, it ran into a lint error. I've fixed the line that was too long and split it up using string concatenation and have retested the lint, the build locally and the test files. Could you two have another look? Thank you again! Hopefully this should be the last step.

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants