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

Added list of env variables for fn-plugins #2999

Merged
merged 2 commits into from
Sep 26, 2020

Conversation

aodinokov
Copy link
Contributor

@aodinokov aodinokov commented Sep 17, 2020

KRM-functions should be able to get env variables.
After changes of runfn object fn based plugins don't
get them anymore.
Reflecting in build cmd args added in [1]
for fn run cmd.

[1]
#2988

KRM-functions should be able get env variables.
Reflecting in `build` cmd args added in [1]
for `fn run` cmd.

[1]
kubernetes-sigs#2988
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 17, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @aodinokov. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Sep 17, 2020
@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Sep 17, 2020
@aodinokov
Copy link
Contributor Author

cc: @Shell32-Natsu

@Shell32-Natsu
Copy link
Contributor

/ok-to-test
/lgtm

@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 Sep 17, 2020
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 17, 2020
@Shell32-Natsu
Copy link
Contributor

Can you add some tests in api/krusty/fnplugin_test.go? env should also be able to used in declarative files.

@aodinokov
Copy link
Contributor Author

aodinokov commented Sep 17, 2020

Can you add some tests in api/krusty/fnplugin_test.go? env should also be able to used in declarative files.

api/krusty/fnplugin_test.go runs tests with kpt-functions inside containers. that's a good idea to make something that passes env and expect the result based on the env variable value. the only concern, that I don't know any kpt-functions that need env variables. except 2 that I've written by myself :) That's why I'm not sure right now if it's possible to write a good test for that.

with std kpt-functions I may use envs values, but not sure how to check... will need to look inside to find a good one

@Shell32-Natsu
Copy link
Contributor

Shell32-Natsu commented Sep 17, 2020

OK, let's consider that later.

@monopole
Copy link
Contributor

Thanks for the SOPs function in GoogleContainerTools/kpt-functions-catalog#101

by all means please contribute a simple test function in go that use env vars (e.g. accepts them and emits their values somewhere in the output).

https://github.com/GoogleContainerTools/kpt-functions-catalog/tree/master/functions/go

@aodinokov
Copy link
Contributor Author

aodinokov commented Sep 20, 2020

by all means please contribute a simple test function in go that use env vars (e.g. accepts them and emits their values somewhere in the output).

Was thinking about reusing already existing functions. helm_template looked promising, but it appeared that env functions is blocked (See warnings in the description).
I decided that it should be something meaningful and generic like envsubst, but at the same time - simple.

I ended up with this go-templater. Here is the ut that comply with our goal:

                        cfg: `
...
    template: |
      value: {{ env "TESTTEMPLATE" }}
`,
			expectedOut: `value: testtemplatevalue
`,

The implementation doesn't' look difficult to me, but of course it's not the simplest option. Is it simple enough?
see GoogleContainerTools/kpt-functions-catalog#103

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 21, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: aodinokov
To complete the pull request process, please assign shell32-natsu
You can assign the PR to them by writing /assign @shell32-natsu in a comment when ready.

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

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 21, 2020
@aodinokov
Copy link
Contributor Author

@monopole , @Shell32-Natsu

by all means please contribute a simple test function in go that use env vars (e.g. accepts them and emits their values somewhere in the output).

please find this test I've added:
64cbfbe#diff-97cedd4af5012b151e61e21710553cc6R479

it will be necessary to wait for GoogleContainerTools/kpt-functions-catalog#103 to be able to change image to gcr.io/kpt-functions/templater .
And with that PR it may also take some time: I needed a little hack to make this to be able to pass e2e:
GoogleContainerTools/kpt-functions-catalog@84f2c57#diff-60fe268f71ae7f8409aff40d0a3e51d8R70 . I expect that there will be some changes related to CI first to be able to test go-functions, + thorough review of my function... It may be a long story :)
may be I should split this PR on 2: with the original changes and with the added test?

@Shell32-Natsu
Copy link
Contributor

Probably we should use one PR for both code and test. @monopole

@aodinokov
Copy link
Contributor Author

Probably we should use one PR for both code and test.

np. actually I just realized that these changes I propose now are not so critical, since it's now possible to make the following the plugin config file and basically get the previous behaviour, but for the limited number of vars:

envs:
- envvarname1 #without setting the value
...

the changes you made for env vars there + setting a user to run container are awesome 👍

Copy link
Contributor

@monopole monopole 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 Sep 26, 2020
@monopole monopole merged commit 1320e0c into kubernetes-sigs:master Sep 26, 2020
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. 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.

4 participants