Skip to content

Commit

Permalink
functionConfig validation for eval and render (#2133)
Browse files Browse the repository at this point in the history
  • Loading branch information
natasha41575 committed Jun 4, 2021
1 parent 98e3b67 commit 179a7c7
Show file tree
Hide file tree
Showing 24 changed files with 354 additions and 65 deletions.
17 changes: 17 additions & 0 deletions e2e/testdata/fn-eval/fnconfig-missing-name/config.yaml
@@ -0,0 +1,17 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: v1
kind: ConfigMap
data:
namespace: staging
@@ -0,0 +1,19 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

testType: eval
image: gcr.io/kpt-fn/set-namespace:v0.1
fnConfig: ../../config.yaml
exitCode: 1
stdErr: "resource must have `metadata.name`"
1 change: 1 addition & 0 deletions e2e/testdata/fn-eval/fnconfig-missing-name/pkg/.krmignore
@@ -0,0 +1 @@
.expected
26 changes: 26 additions & 0 deletions e2e/testdata/fn-eval/fnconfig-missing-name/pkg/resources.yaml
@@ -0,0 +1,26 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
---
apiVersion: custom.io/v1
kind: Custom
metadata:
name: custom
spec:
image: nginx:1.2.3
26 changes: 26 additions & 0 deletions e2e/testdata/fn-eval/multiple-fn-config-one-file/config.yaml
@@ -0,0 +1,26 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: v1
kind: ConfigMap
metadata:
name: config
data:
namespace: staging
---
apiVersion: v1
kind: ConfigMap
metadata:
name: config
data:
namespace: staging
@@ -0,0 +1,19 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

testType: eval
image: gcr.io/kpt-fn/set-namespace:v0.1.3
fnConfig: ../../config.yaml
exitCode: 1
stdErr: "must not contain more than one config, got 2"
@@ -0,0 +1 @@
.expected
@@ -0,0 +1,26 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
---
apiVersion: custom.io/v1
kind: Custom
metadata:
name: custom
spec:
image: nginx:1.2.3
16 changes: 16 additions & 0 deletions e2e/testdata/fn-render/fnconfig-missing-name/.expected/config.yaml
@@ -0,0 +1,16 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

exitCode: 1
stdErr: "resource must have `metadata.name`"
1 change: 1 addition & 0 deletions e2e/testdata/fn-render/fnconfig-missing-name/.krmignore
@@ -0,0 +1 @@
.expected
11 changes: 11 additions & 0 deletions e2e/testdata/fn-render/fnconfig-missing-name/Kptfile
@@ -0,0 +1,11 @@
apiVersion: kpt.dev/v1alpha2
kind: Kptfile
metadata:
name: app-with-db
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-namespace:unstable
configMap:
namespace: staging
- image: gcr.io/kpt-fn/set-label:unstable
configPath: labelconfig.yaml
17 changes: 17 additions & 0 deletions e2e/testdata/fn-render/fnconfig-missing-name/labelconfig.yaml
@@ -0,0 +1,17 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: v1
kind: ConfigMap
data:
tier: db
26 changes: 26 additions & 0 deletions e2e/testdata/fn-render/fnconfig-missing-name/resources.yaml
@@ -0,0 +1,26 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
---
apiVersion: custom.io/v1
kind: Custom
metadata:
name: custom
spec:
image: nginx:1.2.3
@@ -0,0 +1,15 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
exitCode: 1
stdErr: "functionConfig \"labelconfig.yaml\" must not contain more than one config, got 2"
@@ -0,0 +1 @@
.expected
@@ -0,0 +1,8 @@
apiVersion: kpt.dev/v1alpha2
kind: Kptfile
metadata:
name: app-with-db
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-labels:v0.1.4
configPath: labelconfig.yaml
@@ -0,0 +1,26 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: v1
kind: ConfigMap
metadata:
name: label-config
data:
tier: db
---
apiVersion: v1
kind: ConfigMap
metadata:
name: label-config
data:
tier: db
@@ -0,0 +1,26 @@
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
---
apiVersion: custom.io/v1
kind: Custom
metadata:
name: custom
spec:
image: nginx:1.2.3
3 changes: 0 additions & 3 deletions e2e/testdata/fn-render/missing-fnconfig/.expected/config.yaml
Expand Up @@ -18,6 +18,3 @@ stdErr: |
Field: `pipeline.mutators[1].configPath`
Value: "labelconfig1.yaml"
Reason: functionConfig must exist in the current package
stdOut: |
[RUNNING] "gcr.io/kpt-fn/set-labels:v0.1.4"
[PASS] "gcr.io/kpt-fn/set-labels:v0.1.4"
2 changes: 1 addition & 1 deletion internal/cmdrender/executor.go
Expand Up @@ -175,7 +175,7 @@ func newPkgNode(path string, p *pkg.Pkg) (pn *pkgNode, err error) {
return pn, errors.E(op, p.UniquePath, err)
}

if err := kf.Validate(); err != nil {
if err := kf.Validate(p.UniquePath); err != nil {
return pn, errors.E(op, p.UniquePath, err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/kptfile/v1alpha2/types.go
Expand Up @@ -167,7 +167,7 @@ type GitLock struct {
// PackageInfo contains optional information about the package such as license, documentation, etc.
// These fields are not consumed by any functionality in kpt and are simply passed through.
// Note that like any other KRM resource, humans and automation can also use `metadata.labels` and
// `metadata.annotations` as the extrension mechanism.
// `metadata.annotations` as the extension mechanism.
type PackageInfo struct {
// Site is the URL for package web page.
Site string `yaml:"site,omitempty"`
Expand Down

0 comments on commit 179a7c7

Please sign in to comment.