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

fix: krm exec function working dir #4654

Merged
merged 4 commits into from
Oct 26, 2022

Conversation

aabouzaid
Copy link
Contributor

@aabouzaid aabouzaid commented May 28, 2022

Based on @seh tip in #4347

This change makes a deep copy from the loader config instead of passing a reference to the config.

How to test: Follow the steps in #4347.

I've added 2 tests:

  • TestFnExecTransformer: This test will pass in all cases because before the fix the base path is used and there is only the base and no overlay.
  • TestFnExecTransformerWithOverlay:
    • Before the fix: The test failed with exact error as in 4347 because the working dir is set to the base path.
    • After the fix: The test passed where the working dir is updated with the overlay path.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented May 28, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: aabouzaid / name: Ahmed AbouZaid (15866d7)

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

Welcome @aabouzaid!

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 May 28, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @aabouzaid. 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/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 28, 2022
@aabouzaid
Copy link
Contributor Author

/check-cla

@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 May 28, 2022
@seh
Copy link
Contributor

seh commented Jun 14, 2022

@KnVerey, does the implementation match your expectations?

@aabouzaid, have you found an existing test that we can augment or duplicate to test this change?

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.

Please feel free to add a unit test, this approach seems fine to me. Thanks!

api/internal/target/kusttarget.go Outdated Show resolved Hide resolved
@natasha41575
Copy link
Contributor

/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 Jun 14, 2022
@natasha41575
Copy link
Contributor

natasha41575 commented Jun 15, 2022

have you found an existing test that we can augment or duplicate to test this change?

@seh @aabouzaid, https://github.com/kubernetes-sigs/kustomize/blob/master/api/krusty/fnplugin_test.go has some tests for KRM exec functions that you may be able to model after.

@k8s-ci-robot
Copy link
Contributor

@aabouzaid: 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.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 13, 2022
@aabouzaid
Copy link
Contributor Author

@natasha41575 I've created the DeepCopy, and also added 2 tests one with just the base and another with overly (I've updated the PR body with the test results before and after the fix).

@aabouzaid
Copy link
Contributor Author

@KnVerey @natasha41575 could you please take a look at this PR? It's ready.

@aabouzaid
Copy link
Contributor Author

@KnVerey @natasha41575 could we at least run the CI pipeline to make sure everything as expected 😅

Copy link
Contributor

@KnVerey KnVerey left a comment

Choose a reason for hiding this comment

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

Can you please also rebase when you address the comments?
Re: the tests, Github isn't even offering me the button to run them for some reason. I've never seen that before, and I'll look into it if it doesn't start working after you push again.

api/internal/plugins/loader/loader.go Outdated Show resolved Hide resolved
api/internal/plugins/loader/loader.go Outdated Show resolved Hide resolved
@natasha41575
Copy link
Contributor

natasha41575 commented Oct 6, 2022

@aabouzaid do you plan to continue this PR? It looks like we may need this functionality for #3980, which @annasong20 is working on. She'd like to pick this up unless you are still working on it.

@aabouzaid
Copy link
Contributor Author

@natasha41575 Yes, I will try to finish it over the weekend.

@aabouzaid aabouzaid requested review from annasong20 and KnVerey and removed request for KnVerey and annasong20 October 15, 2022 15:47
@annasong20
Copy link
Contributor

/ok-to-test

@annasong20
Copy link
Contributor

/retest

api/internal/plugins/loader/loader.go Show resolved Hide resolved
api/internal/plugins/loader/loader_test.go Show resolved Hide resolved
@@ -126,7 +132,7 @@ spec:
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
}

func TestFnExecGeneratorWithOverlay(t *testing.T) {
func TestFnExecGeneratorInOverlay(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change this back to TestFnExecGeneratorWithOverlay? In my last comment, I was only referring to the new test you added, TestFnExecTransformerInOverlay. In this generator test, the exec generator is actually in the base, not the overlay, so it should be "with".

Sorry, my bad for not clarifying!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I've renamed the functions to make it clear and avoid all of that confusion.

For example, for the transformer, we now have:

  • TestFnExecTransformerInBase: The transformer is in the base, and there is no overlay.
  • TestFnExecTransformerInBaseWithOverlay: The transformer is in the base, and there is an overlay, but it has no transformer.
  • TestFnExecTransformerInOverlay: The transformer is in the overlay and not in the base.

And the generator follows the same pattern.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fantastic!

api/krusty/fnplugin_test.go Outdated Show resolved Hide resolved
api/krusty/fnplugin_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@KnVerey KnVerey left a comment

Choose a reason for hiding this comment

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

/approve

@annasong20 go ahead and lgtm once you're satisfied your comments are addressed

Thank you to both of you for your work on this fix and its review!

api/internal/plugins/loader/loader_test.go Outdated Show resolved Hide resolved
api/internal/plugins/loader/loader.go Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aabouzaid, KnVerey

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 21, 2022
@aabouzaid
Copy link
Contributor Author

aabouzaid commented Oct 22, 2022

I've addressed all comments. So we are ready to go. ✔️
I will rebase and update the commit messages once no more changes are required.

I see that there is alredy an error in the CI pipeline but it has nothing to do with this PR.
It's in TestRemoteLoad_LocalProtocol (I see the same error in other commits pipeline runs)

@aabouzaid aabouzaid requested review from KnVerey and annasong20 and removed request for KnVerey October 24, 2022 09:41
`)

m := th.Run(prod, o)
assert.NoError(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -41,7 +41,19 @@ spec:
EOF
`

func TestFnExecGenerator(t *testing.T) {
const krmTransformerDotSh = `#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for making this change!

@annasong20
Copy link
Contributor

/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 26, 2022
@k8s-ci-robot k8s-ci-robot merged commit daf81df into kubernetes-sigs:master Oct 26, 2022
@aabouzaid
Copy link
Contributor Author

@annasong20 thanks for reviewing this PR 👌
The last step was to rebase and squash the last 2 commits to have a meaningful message 😅

@annasong20
Copy link
Contributor

@annasong20 thanks for reviewing this PR 👌 The last step was to rebase and squash the last 2 commits to have a meaningful message 😅

Totally on me. I didn't realize it would auto-merge... Thanks for bringing this up!

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/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.

6 participants