Skip to content

Commit 9546486

Browse files
committed
Adds e2e test for basic pruning functionality
1 parent 31ac4ef commit 9546486

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
[kind]: https://github.com/kubernetes-sigs/kind
2+
3+
# Demo: Basic Prune
4+
5+
This demo shows basic pruning behavior by creating an
6+
"app" with three config maps. After the initial apply of the
7+
"app", pruning is demonstrated by locally deleting one
8+
of the config maps, and applying again.
9+
10+
First define a place to work:
11+
12+
<!-- @makeWorkplace @testE2EAgainstLatestRelease -->
13+
```
14+
DEMO_HOME=$(mktemp -d)
15+
```
16+
17+
Alternatively, use
18+
19+
> ```
20+
> DEMO_HOME=~/hello
21+
> ```
22+
23+
## Establish the base
24+
25+
<!-- @createBase @testE2EAgainstLatestRelease -->
26+
```
27+
BASE=$DEMO_HOME/base
28+
mkdir -p $BASE
29+
OUTPUT=$DEMO_HOME/output
30+
mkdir -p $OUTPUT
31+
32+
function expectedOutputLine() {
33+
test 1 == \
34+
$(grep "$@" $OUTPUT/status | wc -l); \
35+
echo $?
36+
}
37+
```
38+
39+
## Create the first "app"
40+
41+
Create the config yaml for three config maps: (cm-a, cm-b, cm-c).
42+
43+
<!-- @createFirstConfigMaps @testE2EAgainstLatestRelease-->
44+
```
45+
cat <<EOF >$BASE/config-map-a.yaml
46+
apiVersion: v1
47+
kind: ConfigMap
48+
metadata:
49+
name: cm-a
50+
labels:
51+
name: test-config-map-label
52+
EOF
53+
54+
cat <<EOF >$BASE/config-map-b.yaml
55+
apiVersion: v1
56+
kind: ConfigMap
57+
metadata:
58+
name: cm-b
59+
labels:
60+
name: test-config-map-label
61+
EOF
62+
63+
cat <<EOF >$BASE/config-map-c.yaml
64+
apiVersion: v1
65+
kind: ConfigMap
66+
metadata:
67+
name: cm-c
68+
labels:
69+
name: test-config-map-label
70+
EOF
71+
```
72+
73+
## Run end-to-end tests
74+
75+
The following requires installation of [kind].
76+
77+
Delete any existing kind cluster and create a new one. By default the name of the cluster is "kind".
78+
79+
<!-- @deleteAndCreateKindCluster @testE2EAgainstLatestRelease -->
80+
```
81+
kind delete cluster
82+
kind create cluster
83+
```
84+
85+
Use the kapply init command to generate the inventory template. This contains
86+
the namespace and inventory id used by apply to create inventory objects.
87+
<!-- @createInventoryTemplate @testE2EAgainstLatestRelease-->
88+
```
89+
kapply init $BASE > $OUTPUT/status
90+
expectedOutputLine "namespace: default is used for inventory object"
91+
```
92+
93+
Apply the "app" to the cluster. All the config maps should be created, and
94+
no resources should be pruned.
95+
<!-- @runApply @testE2EAgainstLatestRelease -->
96+
```
97+
kapply apply $BASE --reconcile-timeout=1m > $OUTPUT/status
98+
expectedOutputLine "configmap/cm-a created"
99+
expectedOutputLine "configmap/cm-b created"
100+
expectedOutputLine "configmap/cm-c created"
101+
expectedOutputLine "0 resource(s) pruned, 0 skipped"
102+
103+
# There should be only one inventory object
104+
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l > $OUTPUT/status
105+
expectedOutputLine "1"
106+
# Capture the inventory object name for later testing
107+
invName=$(kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | awk '{print $1}')
108+
# There should be three config maps
109+
kubectl get cm --selector='!cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l > $OUTPUT/status
110+
expectedOutputLine "3"
111+
# ConfigMap cm-a had been created in the cluster
112+
kubectl get configmap/cm-a --no-headers | wc -l > $OUTPUT/status
113+
expectedOutputLine "1"
114+
# ConfigMap cm-b had been created in the cluster
115+
kubectl get configmap/cm-b --no-headers | wc -l > $OUTPUT/status
116+
expectedOutputLine "1"
117+
# ConfigMap cm-c had been created in the cluster
118+
kubectl get configmap/cm-c --no-headers | wc -l > $OUTPUT/status
119+
expectedOutputLine "1"
120+
```
121+
122+
## Update the "app" to remove a config map, and add another config map.
123+
124+
Remove cm-a.
125+
126+
Create a fourth config map--cm-d.
127+
<!-- @createAnotherConfigMap @testE2EAgainstLatestRelease -->
128+
```
129+
rm -f $BASE/config-map-a.yaml
130+
131+
cat <<EOF >$BASE/config-map-d.yaml
132+
apiVersion: v1
133+
kind: ConfigMap
134+
metadata:
135+
name: cm-d
136+
labels:
137+
name: test-config-map-label
138+
EOF
139+
```
140+
141+
## Apply the updated "app"
142+
143+
cm-a should be pruned (since it has been deleted locally).
144+
145+
cm-b, cm-c should be unchanged.
146+
147+
cm-d should be created.
148+
<!-- @applySecondTime @testE2EAgainstLatestRelease -->
149+
```
150+
kapply apply $BASE --reconcile-timeout=1m > $OUTPUT/status
151+
expectedOutputLine "configmap/cm-a pruned"
152+
expectedOutputLine "configmap/cm-b unchanged"
153+
expectedOutputLine "configmap/cm-c unchanged"
154+
expectedOutputLine "configmap/cm-d created"
155+
expectedOutputLine "1 resource(s) pruned, 0 skipped"
156+
157+
# There should be only one inventory object
158+
kubectl get cm --selector='cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l > $OUTPUT/status
159+
expectedOutputLine "1"
160+
# The inventory object should have the same name
161+
kubectl get configmap/${invName} --no-headers > $OUTPUT/status
162+
expectedOutputLine "${invName}"
163+
# There should be three config maps
164+
kubectl get cm --selector='!cli-utils.sigs.k8s.io/inventory-id' --no-headers | wc -l > $OUTPUT/status
165+
expectedOutputLine "3"
166+
# ConfigMap cm-b had been created in the cluster
167+
kubectl get configmap/cm-b --no-headers | wc -l > $OUTPUT/status
168+
expectedOutputLine "1"
169+
# ConfigMap cm-c had been created in the cluster
170+
kubectl get configmap/cm-c --no-headers | wc -l > $OUTPUT/status
171+
expectedOutputLine "1"
172+
# ConfigMap cm-d had been created in the cluster
173+
kubectl get configmap/cm-d --no-headers | wc -l > $OUTPUT/status
174+
expectedOutputLine "1"
175+
```

0 commit comments

Comments
 (0)