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 10 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
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: christianh814, sanaasy
Once this PR has been reviewed and has the lgtm label, please assign stormqueen1990 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

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!

@sanaasy sanaasy force-pushed the sanaasy/add-no-verify-flag branch from cc2aff7 to facafce Compare March 5, 2024 16:34
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! 👋🏻

Apologies for my delayed response! I took a look at the KEP for the localize command and found a few points that need changes.

Let me know if these make sense!

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
kustomize/commands/localize/localize_test.go Outdated Show resolved Hide resolved
kustomize/commands/localize/localize.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 15, 2024
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 3, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 3, 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.

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.

Comment on lines +45 to +46
- name: helmTest
repo: testRepo
Copy link
Member

Choose a reason for hiding this comment

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

If you'd like to have something that pulls real content from somewhere, we have quite a few usages of

- name: external-dns
  repo: oci://registry-1.docker.io/bitnamicharts/

in tests.

@@ -66,6 +82,58 @@ func TestScopeFlag(t *testing.T) {
loctest.CheckFs(t, testDir.String(), expected, actual)
}

func TestNoVerifyFlag(t *testing.T) {
kustomization := map[string]string{
"kustomization.yaml": `namePrefix: test-
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be interesting to have an extra test case here with some localizable content. Perhaps a resource such as https://raw.githubusercontent.com/kubernetes-sigs/kustomize/v1.0.6/examples/helloWorld/deployment.yaml could be a good candidate (since it is part of this repo)?

@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!

}

if localizedBuild == originalBuild {
log.Printf("VERIFICATION SUCCESS: `kustomize build` for %s and %s are the same after localization.", args.target, dst)
Copy link
Member

Choose a reason for hiding this comment

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

minor: I think this log could benefit of having a line break at the end, since Printf() won't add it by default.

log.Printf("VERIFICATION SUCCESS: `kustomize build` for %s and %s are the same after localization.", args.target, dst)
} else {
log.Println(copyutil.PrettyFileDiff(originalBuild, localizedBuild))
log.Fatalf("VERFICATION FAILED: `kustomize build` for %s and %s are different after localization.", args.target, dst)
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to have a line break at the end of this message as well.

@@ -62,6 +68,26 @@ kustomize localize https://github.com/kubernetes-sigs/kustomize//api/krusty/test
if err != nil {
return errors.Wrap(err)
}

if !f.noVerify && f.scope == "" {
Copy link
Member

Choose a reason for hiding this comment

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

localize with verification should still work even if --scope is specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants