Skip to content

Commit

Permalink
Out of place hydration using render and eval (#2137)
Browse files Browse the repository at this point in the history
* Implement out of place hydration for eval and render

* e2e tests for oop hydration

* Reference docs

* Fix tests

* Address suggested changes

* Unit tests for WriteFnOutput

* out of place support in test harness

* added support for fn-eval

* output of place tests

* --results-dir option should not print progress to stdout

* print results dir message for error

* Update reference docs with default behavior

Co-authored-by: droot <sunilarora@google.com>
  • Loading branch information
phanimarupaka and droot committed Jun 5, 2021
1 parent 4618a59 commit 7d765c3
Show file tree
Hide file tree
Showing 73 changed files with 1,510 additions and 176 deletions.
34 changes: 34 additions & 0 deletions e2e/testdata/fn-eval/out-of-place-dir/.expected/diff.patch
@@ -0,0 +1,34 @@
diff --git a/out/resources.yaml b/out/resources.yaml
new file mode 100644
index 0000000..254b9cd
--- /dev/null
+++ b/out/resources.yaml
@@ -0,0 +1,28 @@
+# 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
+ namespace: staging
+spec:
+ replicas: 3
+---
+apiVersion: custom.io/v1
+kind: Custom
+metadata:
+ name: custom
+ namespace: staging
+spec:
+ image: nginx:1.2.3
18 changes: 18 additions & 0 deletions e2e/testdata/fn-eval/out-of-place-dir/.expected/exec.sh
@@ -0,0 +1,18 @@
#! /bin/bash
# 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.

set -eo pipefail

kpt fn eval --image gcr.io/kpt-fn/set-namespace:v0.1.3 -o out -- namespace=staging
2 changes: 2 additions & 0 deletions e2e/testdata/fn-eval/out-of-place-dir/.krmignore
@@ -0,0 +1,2 @@
.expected
out
@@ -0,0 +1,52 @@
stdOut: |
apiVersion: config.kubernetes.io/v1alpha1
kind: ResourceList
items:
# 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
namespace: staging
labels:
tier: backend
annotations:
config.kubernetes.io/index: "0"
config.kubernetes.io/path: resources.yaml
foo: bar
spec:
replicas: 3
selector:
matchLabels:
tier: backend
template:
metadata:
labels:
tier: backend
annotations:
foo: bar
- apiVersion: custom.io/v1
kind: Custom
metadata:
name: custom
namespace: staging
labels:
tier: backend
annotations:
config.kubernetes.io/index: "1"
config.kubernetes.io/path: resources.yaml
foo: bar
spec:
image: nginx:1.2.3
@@ -0,0 +1,7 @@
#! /bin/bash

set -eo pipefail

kpt fn eval --image gcr.io/kpt-fn/set-namespace:v0.1.3 -o stdout -- namespace=staging \
| kpt fn eval - --image gcr.io/kpt-fn/set-annotations:v0.1.3 -- foo=bar \
| kpt fn eval - --image gcr.io/kpt-fn/set-labels:v0.1.3 -- tier=backend
27 changes: 27 additions & 0 deletions e2e/testdata/fn-eval/out-of-place-fnchain-stdout/resources.yaml
@@ -0,0 +1,27 @@
# 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,33 @@
stdOut: |
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: staging
labels:
tier: backend
annotations:
foo: bar
spec:
replicas: 3
selector:
matchLabels:
tier: backend
template:
metadata:
labels:
tier: backend
annotations:
foo: bar
---
apiVersion: custom.io/v1
kind: Custom
metadata:
name: custom
namespace: staging
labels:
tier: backend
annotations:
foo: bar
spec:
image: nginx:1.2.3
@@ -0,0 +1,7 @@
#! /bin/bash

set -eo pipefail

kpt fn eval --image gcr.io/kpt-fn/set-namespace:v0.1.3 -o stdout -- namespace=staging \
| kpt fn eval - --image gcr.io/kpt-fn/set-annotations:v0.1.3 -- foo=bar \
| kpt fn eval - --image gcr.io/kpt-fn/set-labels:v0.1.3 -o unwrap -- tier=backend
@@ -0,0 +1 @@
.expected
9 changes: 9 additions & 0 deletions e2e/testdata/fn-eval/out-of-place-fnchain-unwrap/Kptfile
@@ -0,0 +1,9 @@
apiVersion: kpt.dev/v1alpha2
kind: Kptfile
metadata:
name: app
pipeline:
mutators:
- image: gcr.io/kpt-fn/set-namespace:v0.1.3
configMap:
namespace: staging
13 changes: 13 additions & 0 deletions e2e/testdata/fn-eval/out-of-place-fnchain-unwrap/resources.yaml
@@ -0,0 +1,13 @@
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
34 changes: 34 additions & 0 deletions e2e/testdata/fn-eval/out-of-place-source-sink/.expected/diff.patch
@@ -0,0 +1,34 @@
diff --git a/out/resources.yaml b/out/resources.yaml
new file mode 100644
index 0000000..254b9cd
--- /dev/null
+++ b/out/resources.yaml
@@ -0,0 +1,28 @@
+# 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
+ namespace: staging
+spec:
+ replicas: 3
+---
+apiVersion: custom.io/v1
+kind: Custom
+metadata:
+ name: custom
+ namespace: staging
+spec:
+ image: nginx:1.2.3
Expand Up @@ -15,16 +15,8 @@

set -eo pipefail

# create a temporary directory
TEMP_DIR=$(mktemp -d)
rm -rf out; mkdir out

kpt fn source \
| kpt fn eval - --image gcr.io/kpt-fn/set-namespace:v0.1.3 -- namespace=staging \
| kpt fn sink $TEMP_DIR

# copy back the resources
rm -r ./*
cp $TEMP_DIR/* .

# remove temporary directory
rm -r $TEMP_DIR
| kpt fn sink out
2 changes: 2 additions & 0 deletions e2e/testdata/fn-eval/out-of-place-source-sink/.krmignore
@@ -0,0 +1,2 @@
.expected
out
26 changes: 26 additions & 0 deletions e2e/testdata/fn-eval/out-of-place-source-sink/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
19 changes: 0 additions & 19 deletions e2e/testdata/fn-eval/out-of-place/.expected/diff.patch

This file was deleted.

68 changes: 36 additions & 32 deletions e2e/testdata/fn-eval/output-to-stdout/.expected/config.yaml
Expand Up @@ -13,35 +13,39 @@
# limitations under the License.

stdOut: |
# 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
namespace: staging
annotations:
config.kubernetes.io/path: resources.yaml
spec:
replicas: 3
---
apiVersion: custom.io/v1
kind: Custom
metadata:
name: custom
namespace: staging
annotations:
config.kubernetes.io/path: resources.yaml
spec:
image: nginx:1.2.3
apiVersion: config.kubernetes.io/v1alpha1
kind: ResourceList
items:
- # 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
namespace: staging
annotations:
config.kubernetes.io/index: "0"
config.kubernetes.io/path: resources.yaml
spec:
replicas: 3
- apiVersion: custom.io/v1
kind: Custom
metadata:
name: custom
namespace: staging
annotations:
config.kubernetes.io/index: "1"
config.kubernetes.io/path: resources.yaml
spec:
image: nginx:1.2.3

0 comments on commit 7d765c3

Please sign in to comment.