feat: add exec-plugin argument and environment support (#5316)

* feat: add exec-plugin argument and environment support

Previously, the documentation lead to think that this is working, but
it's not been implemented.

This PR is fixing this

Signed-off-by: Matthias Riegler <matthias.riegler@ankorstore.com>

* chore: disable linting for env var split

Signed-off-by: Matthias Riegler <matthias.riegler@ankorstore.com>

---------

Signed-off-by: Matthias Riegler <matthias.riegler@ankorstore.com>
This commit is contained in:
Matthias Riegler
2025-02-16 22:28:21 +01:00
committed by GitHub
parent 3be1af6798
commit cc7a71c288
5 changed files with 92 additions and 5 deletions

View File

@@ -21,6 +21,9 @@ type Filter struct {
// Args are the arguments to the executable
Args []string `yaml:"args,omitempty"`
// Env is exposed to the environment
Env []string `yaml:"env,omitempty"`
// WorkingDir is the working directory that the executable
// should run in
WorkingDir string
@@ -35,6 +38,7 @@ func (c *Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
func (c *Filter) Run(reader io.Reader, writer io.Writer) error {
cmd := exec.Command(c.Path, c.Args...) //nolint:gosec
cmd.Env = append(os.Environ(), c.Env...)
cmd.Stdin = reader
cmd.Stdout = writer
cmd.Stderr = os.Stderr

View File

@@ -17,7 +17,7 @@ import (
func TestFunctionFilter_Filter(t *testing.T) {
wd, err := os.Getwd()
require.NoError(t, err)
var tests = []struct {
tests := []struct {
name string
input []string
functionConfig string
@@ -57,8 +57,9 @@ metadata:
},
expectedError: "",
instance: exec.Filter{
Path: "sed",
Args: []string{"s/Deployment/StatefulSet/g"},
Path: "sh",
Env: []string{"TARGET=StatefulSet"},
Args: []string{"-c", `sed "s/Deployment/$TARGET/g"`},
WorkingDir: wd,
},
},

View File

@@ -138,6 +138,12 @@ type FunctionSpec struct {
type ExecSpec struct {
Path string `json:"path,omitempty" yaml:"path,omitempty"`
// Args is a slice of args that will be passed as arguments to script
Args []string `json:"args,omitempty" yaml:"args,omitempty"`
// Env is a slice of env string that will be exposed to container
Env []string `json:"envs,omitempty" yaml:"envs,omitempty"`
}
// ContainerSpec defines a spec for running a function as a container