Skip to content

Commit

Permalink
remove config in function spec (#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Jun 2, 2021
1 parent 8275a46 commit 6d374d2
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 197 deletions.
30 changes: 0 additions & 30 deletions e2e/testdata/fn-render/inline-fnconfig/.expected/diff.patch

This file was deleted.

1 change: 0 additions & 1 deletion e2e/testdata/fn-render/inline-fnconfig/.krmignore

This file was deleted.

15 changes: 0 additions & 15 deletions e2e/testdata/fn-render/inline-fnconfig/Kptfile

This file was deleted.

26 changes: 0 additions & 26 deletions e2e/testdata/fn-render/inline-fnconfig/resources.yaml

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion e2e/testdata/fn-render/invalid-inline-fnconfig/.krmignore

This file was deleted.

26 changes: 0 additions & 26 deletions e2e/testdata/fn-render/invalid-inline-fnconfig/resources.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.

exitCode: 1
stdErr: 'only one of ''config'', ''configMap'', ''configPath'' can be specified. Got "configPath, configMap"'
stdErr: 'functionConfig must not specify both `configMap` and `configPath` at the same time'
3 changes: 0 additions & 3 deletions internal/fnruntime/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,6 @@ func newFnConfig(f *kptfilev1alpha2.Function, pkgPath types.UniquePath) (*yaml.R
}
// directly use the config from file
return node, nil
case !kptfilev1alpha2.IsNodeZero(&f.Config):
// directly use the inline config
return yaml.NewRNode(&f.Config), nil
case len(f.ConfigMap) != 0:
node = yaml.NewMapRNode(&f.ConfigMap)
if node == nil {
Expand Down
16 changes: 0 additions & 16 deletions internal/fnruntime/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@ func TestFunctionConfig(t *testing.T) {
fn: kptfilev1alpha2.Function{},
expected: "",
},
{
name: "inline config",
fn: kptfilev1alpha2.Function{
Config: *yaml.MustParse(`apiVersion: cft.dev/v1alpha1
kind: ResourceHierarchy
metadata:
name: root-hierarchy
namespace: hierarchy`).YNode(),
},
expected: `apiVersion: cft.dev/v1alpha1
kind: ResourceHierarchy
metadata:
name: root-hierarchy
namespace: hierarchy
`,
},
{
name: "file config",
fn: kptfilev1alpha2.Function{},
Expand Down
9 changes: 2 additions & 7 deletions package-examples/pipeline-validate/Kptfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ metadata:
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:unstable
config:
apiVersion: fn.kpt.dev/v1alpha1
kind: SetLabelConfig
metadata:
name: label-color-blue
labels:
color: blue
configMap:
color: blue
validators:
- image: gcr.io/kpt-fn/enforce-gatekeeper:unstable
9 changes: 2 additions & 7 deletions package-examples/pipeline-validate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,8 @@ you to use gatekeeper for checks on the configuration.
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:unstable
config:
apiVersion: fn.kpt.dev/v1alpha1
kind: SetLabelConfig
metadata:
name: label-color-blue
labels:
color: blue
configMap:
color: blue
validators:
- image: gcr.io/kpt-fn/enforce-gatekeeper:unstable
```
Expand Down
6 changes: 0 additions & 6 deletions pkg/api/kptfile/v1alpha2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,6 @@ type Function struct {
// image: set-labels
Image string `yaml:"image,omitempty"`

// `Config` specifies an inline KRM resource used as the function config.
// Config, ConfigPath, and ConfigMap fields are mutually exclusive.
// We cannot use a pointer to yaml.Node because it will cause errors when
// we try to unmarshal the YAML.
Config yaml.Node `yaml:"config,omitempty"`

// `ConfigPath` specifies a slash-delimited relative path to a file in the current directory
// containing a KRM resource used as the function config. This resource is
// excluded when resolving 'sources', and as a result cannot be operated on
Expand Down
29 changes: 7 additions & 22 deletions pkg/api/kptfile/v1alpha2/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ func (f *Function) validate(fnType string, idx int) error {
}
}

var configFields []string
if len(f.ConfigMap) != 0 && f.ConfigPath != "" {
return &ValidateError{
Field: fmt.Sprintf("pipeline.%s[%d]", fnType, idx),
Reason: "functionConfig must not specify both `configMap` and `configPath` at the same time",
}
}

if f.ConfigPath != "" {
if err := validateFnConfigPath(f.ConfigPath); err != nil {
return &ValidateError{
Expand All @@ -74,27 +80,6 @@ func (f *Function) validate(fnType string, idx int) error {
Reason: err.Error(),
}
}
configFields = append(configFields, "configPath")
}
if len(f.ConfigMap) != 0 {
configFields = append(configFields, "configMap")
}
if !IsNodeZero(&f.Config) {
config := yaml.NewRNode(&f.Config)
if _, err := config.GetMeta(); err != nil {
return &ValidateError{
Field: fmt.Sprintf("pipeline.%s[%d].config", fnType, idx),
Reason: "functionConfig must be a valid KRM resource with `apiVersion` and `kind` fields",
}
}
configFields = append(configFields, "config")
}
if len(configFields) > 1 {
return &ValidateError{
Field: fmt.Sprintf("pipeline.%s[%d]", fnType, idx),
Reason: fmt.Sprintf("only one of 'config', 'configMap', 'configPath' can be specified. Got %q",
strings.Join(configFields, ", ")),
}
}

return nil
Expand Down
10 changes: 0 additions & 10 deletions pkg/api/kptfile/v1alpha2/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ package v1alpha2

import (
"testing"

"sigs.k8s.io/kustomize/kyaml/yaml"
)

func TestKptfileValidate(t *testing.T) {
Expand All @@ -39,14 +37,6 @@ func TestKptfileValidate(t *testing.T) {
kptfile: KptFile{
Pipeline: &Pipeline{
Mutators: []Function{
{
Image: "gcr.io/kpt-functions/generate-folders",
Config: *yaml.MustParse(`apiVersion: cft.dev/v1alpha1
kind: ResourceHierarchy
metadata:
name: root-hierarchy
namespace: hierarchy # {"$kpt-set":"namespace"}`).YNode(),
},
{
Image: "patch-strategic-merge",
ConfigPath: "./patch.yaml",
Expand Down
14 changes: 4 additions & 10 deletions pkg/kptfile/kptfileutil/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,8 @@ metadata:
pipeline:
mutators:
- image: my:image
config:
apiVersion: kpt.dev/v1alpha2
kind: Function
spec:
foo: bar
configMap:
foo: bar
- image: foo:bar
`,
updateUpstream: true,
Expand All @@ -393,11 +390,8 @@ metadata:
pipeline:
mutators:
- image: my:image
config:
apiVersion: kpt.dev/v1alpha2
kind: Function
spec:
foo: bar
configMap:
foo: bar
- image: foo:bar
`,
},
Expand Down

0 comments on commit 6d374d2

Please sign in to comment.