Skip to content

Commit fe4ead7

Browse files
author
Mengqi Yu
authored
support podman as a runtime for kpt CLI (#3133)
* support podman as function runtime * add defauting in individual e2e test * add test with default runtime
1 parent c10249e commit fe4ead7

File tree

46 files changed

+552
-189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+552
-189
lines changed

.github/workflows/go.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ on:
2929

3030
jobs:
3131
build:
32-
name: Build
32+
name: Build-test-kpt-CLI
3333
runs-on: ubuntu-latest
34+
strategy:
35+
matrix:
36+
runtime: [docker, podman]
3437
steps:
3538
- name: Set up Go 1.17
3639
uses: actions/setup-go@v1
@@ -45,3 +48,5 @@ jobs:
4548
git config --global user.name Your Name
4649
make all
4750
make test-docker
51+
env:
52+
KPT_FN_RUNTIME: ${{ matrix.runtime }}

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,21 @@ test:
9595

9696
# This target is used to run Go tests that require docker runtime.
9797
# Some tests, like pipeline tests, need to have docker available to run.
98+
# KPT_FN_RUNTIME can be set to select the desired function runtime.
99+
# If unspecified, the default function runtime will be used.
98100
test-docker: build
99101
PATH=$(GOBIN):$(PATH) go test -cover --tags=docker ./...
100102

101103
# KPT_E2E_UPDATE_EXPECTED=true (if expected output to be updated)
102104
# target to run e2e tests for "kpt fn render" command
105+
# KPT_FN_RUNTIME can be set to select the desired function runtime.
106+
# If unspecified, the default function runtime will be used.
103107
test-fn-render: build
104108
PATH=$(GOBIN):$(PATH) go test -v --tags=docker --run=TestFnRender/testdata/fn-render/$(T) ./e2e/
105109

106110
# target to run e2e tests for "kpt fn eval" command
111+
# KPT_FN_RUNTIME can be set to select the desired function runtime.
112+
# If unspecified, the default function runtime will be used.
107113
test-fn-eval: build
108114
PATH=$(GOBIN):$(PATH) go test -v --tags=docker --run=TestFnEval/testdata/fn-eval/$(T) ./e2e/
109115

e2e/fn_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
package e2e_test
1919

2020
import (
21+
"os"
2122
"path/filepath"
23+
"strings"
2224
"testing"
2325

26+
"github.com/GoogleContainerTools/kpt/internal/fnruntime"
2427
"github.com/GoogleContainerTools/kpt/pkg/test/runner"
2528
)
2629

@@ -56,6 +59,20 @@ func runTests(t *testing.T, cases *runner.TestCases, sequential bool) {
5659
if c.Config.Sequential != sequential {
5760
continue
5861
}
62+
// If the current function runtime doesn't match, we skip this test case.
63+
currRuntime := strings.ToLower(os.Getenv(fnruntime.ContainerRuntimeEnv))
64+
if len(c.Config.Runtimes) > 0 {
65+
skip := true
66+
for _, rt := range c.Config.Runtimes {
67+
if currRuntime == strings.ToLower(rt) {
68+
skip = false
69+
break
70+
}
71+
}
72+
if skip {
73+
continue
74+
}
75+
}
5976
t.Run(c.Path, func(t *testing.T) {
6077
if !c.Config.Sequential {
6178
t.Parallel()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff --git a/resources.yaml b/resources.yaml
2+
index 7a494c9..254b9cd 100644
3+
--- a/resources.yaml
4+
+++ b/resources.yaml
5+
@@ -15,6 +15,7 @@ apiVersion: apps/v1
6+
kind: Deployment
7+
metadata:
8+
name: nginx-deployment
9+
+ namespace: staging
10+
spec:
11+
replicas: 3
12+
---
13+
@@ -22,5 +23,6 @@ apiVersion: custom.io/v1
14+
kind: Custom
15+
metadata:
16+
name: custom
17+
+ namespace: staging
18+
spec:
19+
image: nginx:1.2.3
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /bin/bash
2+
# Copyright 2021 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -eo pipefail
17+
18+
# clear environment variable KPT_FN_RUNTIME if it matches the default
19+
if [ "${KPT_FN_RUNTIME}" = "docker" ]; then
20+
unset KPT_FN_RUNTIME
21+
fi
22+
23+
echo "KPT_FN_RUNTIME is ${KPT_FN_RUNTIME}"
24+
# run eval with KPT_FN_RUNTIME unset.
25+
kpt fn eval -i gcr.io/kpt-fn/set-namespace:v0.1.3 -- namespace=staging
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.expected
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
apiVersion: apps/v1
15+
kind: Deployment
16+
metadata:
17+
name: nginx-deployment
18+
spec:
19+
replicas: 3
20+
---
21+
apiVersion: custom.io/v1
22+
kind: Custom
23+
metadata:
24+
name: custom
25+
spec:
26+
image: nginx:1.2.3

e2e/testdata/fn-eval/error-in-pipe/.expected/config.yaml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,4 @@
1313
# limitations under the License.
1414

1515
exitCode: 1
16-
stdErr: |
17-
[RUNNING] "gcr.io/kpt-fn/set-namespace:v0.1.3"
18-
[FAIL] "gcr.io/kpt-fn/set-namespace:v0.1.3" in 0s
19-
Results:
20-
[error]: failed to configure function: input namespace cannot be empty
21-
Stderr:
22-
"[error] /// : failed to configure function: input namespace cannot be empty"
23-
Exit code: 1
24-
25-
[RUNNING] "gcr.io/kpt-fn/dne"
26-
[FAIL] "gcr.io/kpt-fn/dne" in 0s
27-
Stderr:
28-
"docker: Error response from daemon: manifest for gcr.io/kpt-fn/dne:latest not found: manifest unknown: Failed to fetch \"latest\" from request \"/v2/kpt-fn/dne/manifests/latest\"."
29-
"See 'docker run --help'."
30-
Exit code: 125
16+
stdErr: Failed to fetch

e2e/testdata/fn-eval/image-pull-policy-always/.expected/setup.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515

1616
set -eo pipefail
1717

18+
KPT_FN_RUNTIME="${KPT_FN_RUNTIME:=docker}"
19+
1820
# Function gcr.io/kpt-fn-demo/foo:v0.1 prints "foo" to stderr and
1921
# function gcr.io/kpt-fn-demo/bar:v0.1 prints "bar" to stderr.
2022
# We intentionally tag a wrong image as gcr.io/kpt-fn-demo/foo:v0.1, since we
2123
# expect the correct image to be pulled and override the wrong image.
22-
docker pull gcr.io/kpt-fn-demo/bar:v0.1
23-
docker tag gcr.io/kpt-fn-demo/bar:v0.1 gcr.io/kpt-fn-demo/foo:v0.1
24+
${KPT_FN_RUNTIME} pull gcr.io/kpt-fn-demo/bar:v0.1
25+
${KPT_FN_RUNTIME} tag gcr.io/kpt-fn-demo/bar:v0.1 gcr.io/kpt-fn-demo/foo:v0.1

e2e/testdata/fn-eval/image-pull-policy-if-not-present/.expected/setup.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616
set -eo pipefail
1717

18+
KPT_FN_RUNTIME="${KPT_FN_RUNTIME:=docker}"
19+
1820
# Function gcr.io/kpt-fn-demo/foo:v0.1 prints "foo" to stderr and
1921
# function gcr.io/kpt-fn-demo/bar:v0.1 prints "bar" to stderr.
2022
# We intentionally tag a wrong image as pull gcr.io/kpt-fn-demo/bar:v0.1
21-
docker pull gcr.io/kpt-fn-demo/foo:v0.1
22-
docker tag gcr.io/kpt-fn-demo/foo:v0.1 gcr.io/kpt-fn-demo/bar:v0.1
23+
${KPT_FN_RUNTIME} pull gcr.io/kpt-fn-demo/foo:v0.1
24+
${KPT_FN_RUNTIME} tag gcr.io/kpt-fn-demo/foo:v0.1 gcr.io/kpt-fn-demo/bar:v0.1

0 commit comments

Comments
 (0)