diff --git a/cmd/pluginator/internal/krmfunction/converter_test.go b/cmd/pluginator/internal/krmfunction/converter_test.go index bf8b75b6c..7bc1cc52c 100644 --- a/cmd/pluginator/internal/krmfunction/converter_test.go +++ b/cmd/pluginator/internal/krmfunction/converter_test.go @@ -81,15 +81,15 @@ functionConfig: kind: FulfillmentCenter metadata: name: staging - metadata: - annotations: - config.kubernetes.io/function: | - container: - image: gcr.io/example/foo:v1.0.0 - namespace: foo - fieldSpecs: - - path: metadata/namespace - create: true + annotations: + config.kubernetes.io/function: | + container: + image: gcr.io/example/foo:v1.0.0 + data: + namespace: foo + fieldSpecs: + - path: metadata/namespace + create: true items: - apiVersion: apps/v1 kind: foobar @@ -108,7 +108,9 @@ func runKrmFunction(t *testing.T, input []byte, dir string) []byte { cmd.Stderr = eb cmd.Dir = dir err := cmd.Run() - assert.NoErrorf(t, err, "Stdout:\n%s\nStderr:\n%s\n", ob.String(), eb.String()) + if !assert.NoErrorf(t, err, "Stdout:\n%s\nStderr:\n%s\n", ob.String(), eb.String()) { + t.FailNow() + } return ob.Bytes() } @@ -139,15 +141,15 @@ functionConfig: kind: FulfillmentCenter metadata: name: staging - metadata: - annotations: - config.kubernetes.io/function: | - container: - image: gcr.io/example/foo:v1.0.0 - namespace: foo - fieldSpecs: - - path: metadata/namespace - create: true + annotations: + config.kubernetes.io/function: | + container: + image: gcr.io/example/foo:v1.0.0 + data: + namespace: foo + fieldSpecs: + - path: metadata/namespace + create: true `, string(output)) } @@ -198,11 +200,13 @@ functionConfig: kind: FulfillmentCenter metadata: name: staging + annotations: + config.kubernetes.io/function: | + container: + image: gcr.io/example/foo:v1.0.0 + data: metadata: - annotations: - config.kubernetes.io/function: | - container: - image: gcr.io/example/foo:v1.0.0 + name: staging items: [] `) } @@ -232,10 +236,12 @@ functionConfig: kind: FulfillmentCenter metadata: name: staging + annotations: + config.kubernetes.io/function: | + container: + image: gcr.io/example/foo:v1.0.0 + data: metadata: - annotations: - config.kubernetes.io/function: | - container: - image: gcr.io/example/foo:v1.0.0 + name: staging `, string(output)) } diff --git a/cmd/pluginator/internal/krmfunction/funcwrappersrc/main.go b/cmd/pluginator/internal/krmfunction/funcwrappersrc/main.go index d01e72cd7..3862db205 100644 --- a/cmd/pluginator/internal/krmfunction/funcwrappersrc/main.go +++ b/cmd/pluginator/internal/krmfunction/funcwrappersrc/main.go @@ -21,18 +21,23 @@ func main() { pluginHelpers := newPluginHelpers(resmapFactory) resourceList := &framework.ResourceList{} + resourceList.FunctionConfig = map[string]interface{}{} cmd := framework.Command(resourceList, func() error { resMap, err := resmapFactory.NewResMapFromRNodeSlice(resourceList.Items) if err != nil { return err } - pluginConfig, err := functionConfigToPluginConfig(resourceList.FunctionConfig) + dataField, err := getDataFromFunctionConfig(resourceList.FunctionConfig) + if err != nil { + return err + } + dataValue, err := yaml.Marshal(dataField) if err != nil { return err } - err = plugin.Config(pluginHelpers, pluginConfig) + err = plugin.Config(pluginHelpers, dataValue) if err != nil { return err } @@ -72,6 +77,10 @@ func newResMapFactory() *resmap.Factory { } //nolint -func functionConfigToPluginConfig(fc interface{}) ([]byte, error) { - return yaml.Marshal(fc) +func getDataFromFunctionConfig(fc interface{}) (interface{}, error) { + f, ok := fc.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("function config %#v is not valid", fc) + } + return f["data"], nil }