Merge pull request #2999 from aodinokov/fixenv

Added list of env variables for fn-plugins
This commit is contained in:
Jeff Regan
2020-09-25 17:00:28 -07:00
committed by GitHub
4 changed files with 53 additions and 0 deletions

View File

@@ -77,6 +77,7 @@ func NewFnPlugin(o *types.FnPluginLoadingOptions) *FnPlugin {
EnableStarlark: o.EnableStar,
EnableExec: o.EnableExec,
StorageMounts: toStorageMounts(o.Mounts),
Env: o.Env,
},
}
}

View File

@@ -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
`)
}

View File

@@ -53,4 +53,6 @@ type FnPluginLoadingOptions struct {
NetworkName string
// list of mounts
Mounts []string
// list of env variables to pass to fn
Env []string
}

View File

@@ -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())