Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functionConfig validation for eval and render #2133

Merged
merged 6 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions e2e/testdata/fn-eval/fnconfig-missing-name/config.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use non-concrete tag like unstable or v0.1 if it's possible. Use full version v0.1.x in kpt e2e test. So we will not suffer from break changes in function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mengqiy Why are we overwriting 0.1 tags? That may have been OK earlier, but going forward 0.1 should not be treated special (otherwise what's the difference between unstable and v0.1?), and the versioning scheme should apply to it. Using 0.1 should be fine in order to pick up patch releases if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had an issue about breaking change in v0.1 in past a few weeks. 0.1 should be stable but for kpt e2e test I think we should pin to a specific version of function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should dogfood the versioning scheme we're promising our users. If we're telling them v0.1 is floating to pick up only patches, then we want to feel the pain if it breaks. Otherwise, our e2e is stable, but the user's workflow are broken. Which is worse?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense.

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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
26 changes: 26 additions & 0 deletions e2e/testdata/fn-eval/fnconfig-missing-name/pkg/resources.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 1 config, got 2"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
11 changes: 11 additions & 0 deletions e2e/testdata/fn-render/fnconfig-missing-name/Kptfile
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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: "must not contain more than 1 config, got 2"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.expected
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ stdErr: |
Field: `pipeline.mutators[1].configPath`
Value: "labelconfig1.yaml"
Reason: functionConfig must exist in the current package
stdOut: |
natasha41575 marked this conversation as resolved.
Show resolved Hide resolved
[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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,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