Skip to content

Commit a546935

Browse files
authored
Fixes problem reading from stdin for live status command (#2417)
1 parent 53b52cd commit a546935

File tree

3 files changed

+95
-7
lines changed

3 files changed

+95
-7
lines changed

e2e/live/end-to-end-test.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,11 +636,36 @@ assertPodNotExists "pod-c" "rg-test-namespace"
636636
assertPodNotExists "pod-d" "rg-test-namespace"
637637
printResult
638638

639+
# Test: Basic kpt live apply/status/destroy from stdin
640+
#
641+
echo "Testing apply/status/destroy from stdin"
642+
echo "cat e2e/live/testdata/stdin-test/pods.yaml | kpt live apply -"
643+
cat e2e/live/testdata/stdin-test/pods.yaml | ${BIN_DIR}/kpt live apply - > $OUTPUT_DIR/status 2>&1
644+
assertContains "pod/pod-a created"
645+
assertContains "pod/pod-b created"
646+
assertContains "pod/pod-c created"
647+
assertContains "3 resource(s) applied. 3 created, 0 unchanged, 0 configured, 0 failed"
648+
printResult
649+
echo "cat e2e/live/testdata/stdin-test/pods.yaml | kpt live status -"
650+
cat e2e/live/testdata/stdin-test/pods.yaml | ${BIN_DIR}/kpt live status - > $OUTPUT_DIR/status 2>&1
651+
assertContains "namespace/stdin-test-namespace is Current: Resource is current"
652+
assertContains "pod/pod-a is Current: Pod is Ready"
653+
assertContains "pod/pod-b is Current: Pod is Ready"
654+
assertContains "pod/pod-c is Current: Pod is Ready"
655+
printResult
656+
echo "cat e2e/live/testdata/stdin-test/pods.yaml | kpt live destroy -"
657+
cat e2e/live/testdata/stdin-test/pods.yaml | ${BIN_DIR}/kpt live destroy - > $OUTPUT_DIR/status 2>&1
658+
assertContains "pod/pod-a deleted"
659+
assertContains "pod/pod-b deleted"
660+
assertContains "pod/pod-c deleted"
661+
assertContains "3 resource(s) deleted, 0 skipped"
662+
printResult
663+
639664
# Test: kpt live apply continue-on-error
640665
echo "[ResourceGroup] Testing continue-on-error"
641666
echo "kpt live apply e2e/live/testdata/continue-on-error"
642667
cp -f e2e/live/testdata/Kptfile e2e/live/testdata/continue-on-error
643-
${BIN_DIR}/kpt live init e2e/live/testdata/continue-on-error > $OUTPUT_DIR/status
668+
${BIN_DIR}/kpt live init e2e/live/testdata/continue-on-error > $OUTPUT_DIR/status 2>&1
644669
diff e2e/live/testdata/Kptfile e2e/live/testdata/continue-on-error/Kptfile > $OUTPUT_DIR/status 2>&1
645670
assertContains "namespace: continue-err-namespace"
646671
${BIN_DIR}/kpt live apply e2e/live/testdata/continue-on-error > $OUTPUT_DIR/status
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
15+
apiVersion: kpt.dev/v1
16+
kind: Kptfile
17+
metadata:
18+
name: test1
19+
upstream:
20+
type: git
21+
git:
22+
repo: [email protected]:yuwenma/blueprint-helloworld
23+
directory: /
24+
ref: master
25+
inventory:
26+
namespace: stdin-test-namespace
27+
name: inventory-18030002
28+
inventoryID: 4a1bc0b4df68e583e23a7351a0a4d149edc0fa61-1627067858058570061
29+
---
30+
apiVersion: v1
31+
kind: Pod
32+
metadata:
33+
name: pod-b
34+
namespace: stdin-test-namespace
35+
labels:
36+
name: test-pod-label
37+
spec:
38+
containers:
39+
- name: kubernetes-pause
40+
image: k8s.gcr.io/pause:2.0
41+
---
42+
apiVersion: v1
43+
kind: Namespace
44+
metadata:
45+
name: stdin-test-namespace
46+
---
47+
apiVersion: v1
48+
kind: Pod
49+
metadata:
50+
name: pod-c
51+
namespace: stdin-test-namespace
52+
labels:
53+
name: test-pod-label
54+
spec:
55+
containers:
56+
- name: kubernetes-pause
57+
image: k8s.gcr.io/pause:2.0
58+
---
59+
apiVersion: v1
60+
kind: Pod
61+
metadata:
62+
name: pod-a
63+
namespace: stdin-test-namespace
64+
labels:
65+
name: test-pod-label
66+
spec:
67+
containers:
68+
- name: kubernetes-pause
69+
image: k8s.gcr.io/pause:2.0

thirdparty/cli-utils/status/cmdstatus.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"k8s.io/kubectl/pkg/cmd/util"
2222
"k8s.io/kubectl/pkg/util/slice"
2323
"sigs.k8s.io/cli-utils/pkg/apply/poller"
24-
"sigs.k8s.io/cli-utils/pkg/common"
2524
"sigs.k8s.io/cli-utils/pkg/inventory"
2625
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
2726
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator"
@@ -114,11 +113,6 @@ func (r *Runner) runE(c *cobra.Command, args []string) error {
114113
args = append(args, cwd)
115114
}
116115

117-
_, err := common.DemandOneDirectory(args)
118-
if err != nil {
119-
return err
120-
}
121-
122116
_, inv, err := live.Load(r.factory, args[0], c.InOrStdin())
123117
if err != nil {
124118
return err

0 commit comments

Comments
 (0)