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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/internal/plugins/fnplugin/fnplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func NewFnPlugin(o *types.FnPluginLoadingOptions) *FnPlugin {
EnableStarlark: o.EnableStar,
EnableExec: o.EnableExec,
StorageMounts: toStorageMounts(o.Mounts),
Env: o.Env,
},
}
}
Expand Down
47 changes: 47 additions & 0 deletions api/krusty/fnplugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,50 @@ metadata:
name: another-namespace
`)
}

func TestFnContainerEnvVars(t *testing.T) {
skipIfNoDocker(t)

th := kusttest_test.MakeEnhancedHarness(t)
defer th.Reset()

th.WriteK("/app", `
generators:
- gener.yaml
`)

// TODO: cheange image to gcr.io/kpt-functions/templater:stable
// when https://github.com/GoogleContainerTools/kpt-functions-catalog/pull/103
// is merged
th.WriteF("/app/gener.yaml", `
apiVersion: v1
kind: ConfigMap
metadata:
name: demo
annotations:
config.kubernetes.io/function: |
container:
image: quay.io/aodinokov/kpt-templater:0.0.1
envs:
- TESTTEMPLATE=value
data:
template: |
apiVersion: v1
kind: ConfigMap
metadata:
name: env
data:
value: '{{ env "TESTTEMPLATE" }}'
`)
m := th.Run("/app", th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
value: value
kind: ConfigMap
metadata:
annotations:
config.kubernetes.io/path: configmap_env.yaml
name: env
`)
}
2 changes: 2 additions & 0 deletions api/types/pluginrestrictions.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ type FnPluginLoadingOptions struct {
NetworkName string
// list of mounts
Mounts []string
// list of env variables to pass to fn
Env []string
}
3 changes: 3 additions & 0 deletions kustomize/internal/commands/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func NewCmdBuild(out io.Writer) *cobra.Command {
cmd.Flags().StringArrayVar(
&o.fnOptions.Mounts, "mount", []string{},
"a list of storage options read from the filesystem")
cmd.Flags().StringArrayVarP(
&o.fnOptions.Env, "env", "e", []string{},
"a list of environment variables to be used by functions")

addFlagLoadRestrictor(cmd.Flags())
addFlagEnablePlugins(cmd.Flags())
Expand Down