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

Add --no-verify flag to edit add resource command #5333

Conversation

hailkomputer
Copy link
Member

This PR addresses the issue #3276

Users want to be able to run kustomize edit add resource <remote-resource> in cases the remote is not reachable and can not be validated.

--skip-validation flag will be passed to the underlying GlobPatternsWithLoader function which is refactored here.
Refactored behavior of GlobPatternsWithLoader function is as follows:

It accepts a slice of glob strings and returns the set of matching file paths. If validation is skipped, then it will return the patterns as provided. Otherwise, It will try to load the files from the filesystem. If files are not found in the filesystem, it will try to load from remote. It returns an error if validation is not skipped and there are no matching files or it can't load from remote.

Other instances of the function reference is also changed with the newly introduces input parameter.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 18, 2023
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 18, 2023
@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.

@natasha41575
Copy link
Contributor

/cc @mehabhalodiya

@natasha41575 natasha41575 added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Sep 21, 2023
kustomize/commands/internal/util/util.go Outdated Show resolved Hide resolved
kustomize/commands/internal/util/util.go Show resolved Hide resolved
kustomize/commands/internal/util/util.go Outdated Show resolved Hide resolved
kustomize/commands/internal/util/util_test.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 Sep 27, 2023
@hailkomputer
Copy link
Member Author

@stormqueen1990 Thank you for the suggestions, I have addressed them in the latest commit.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 29, 2023
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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 1, 2023
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Oct 2, 2023
Copy link
Member

@charles-chenzz charles-chenzz left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 2, 2023
Copy link
Contributor

@natasha41575 natasha41575 left a comment

Choose a reason for hiding this comment

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

LGTM - except for just one comment on the name of the flag.

@@ -35,6 +36,9 @@ func newCmdAddResource(fSys filesys.FileSystem) *cobra.Command {
return o.RunAddResource(fSys)
},
}
cmd.Flags().BoolVar(&o.skipValidation, "skip-validation", false,
Copy link
Contributor

@natasha41575 natasha41575 Oct 2, 2023

Choose a reason for hiding this comment

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

For parity with the flag we are adding to kustomize localize (#5276), can we likewise name this flag --no-verify?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be better. I've renamed the flag.

resources, err = GlobPatternsWithLoader(fSys, ldr, []string{invalidURL}, true)
require.NoError(t, err, "unexpected load error")
require.Equal(t, 1, len(resources), "incorrect resources")
require.Equal(t, invalidURL, resources[0], "incorrect resources")
Copy link
Contributor

@natasha41575 natasha41575 Oct 2, 2023

Choose a reason for hiding this comment

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

Thanks for fixing up these tests and adding one for this feature.

I think it might be nice to rewrite these tests using test structs and subtests, here is an example of this for the remove tests, so that it is easier to read and distinguish each test. You don't need to do this as part of this PR, but it would be a welcome change if you'd like to submit a follow-up PR to do so.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I was also thinking about that when I refactored the tests. Let me tackle that in a separate PR.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 3, 2023
@hailkomputer hailkomputer changed the title Add skip-validation flag to edit add resource command Add --no-verify flag to edit add resource command Oct 3, 2023
@natasha41575
Copy link
Contributor

/lgtm
/approve

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 6, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hailkomputer, natasha41575

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 Oct 6, 2023
@natasha41575 natasha41575 merged commit ace2d53 into kubernetes-sigs:master Oct 6, 2023
5 checks passed
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. 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.
Development

Successfully merging this pull request may close these issues.

5 participants