Skip to content

Commit acf5b57

Browse files
committed
include test harness
1 parent 0380489 commit acf5b57

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
# Test runner using KUTTL against a target cluster.
20+
# https://kuttl.dev
21+
# https://kind.sigs.k8s.io
22+
#
23+
# Materialize a kustomize directory for a kuttl test.
24+
#
25+
# Kustomize is clunky for automated testing. It's pretty opinionated in that it will only evaluate
26+
# a directory off of disk -- you cannot generate a kustomization and pass it in via stdin.
27+
# In order to use kuttl generated namespaces within the kustomization, we have to modify the
28+
# kustomization.yaml before applying it. If we modify that file in the source tree, we end up with
29+
# the test namespace appended to the file under source control. So, this script creates a temp
30+
# directory, copies all the resources into that directory, and modifies the kustomization.yaml as
31+
# necessary. It then runs `kubectl apply -k` against that temporary directory.
32+
#
33+
34+
declare DEBUG="${DEBUG:false}"
35+
if [ "${DEBUG}" = 'true' ] ; then
36+
set -x
37+
fi
38+
39+
set -eou pipefail
40+
41+
declare NAMESPACE
42+
declare NEW_RESOURCES='[]'
43+
declare NEW_COMPONENTS='[]'
44+
declare kustomize_dir
45+
declare -a rewritten_resources=()
46+
declare -a rewritten_components=()
47+
48+
kustomize_dir="$(mktemp -d -p /tmp "${NAMESPACE}.XXXXXXXXXX")"
49+
trap '[ -d "${kustomize_dir}" ] && rm -rf "${kustomize_dir}"' EXIT
50+
51+
cp -r ./* "${kustomize_dir}/"
52+
53+
for r in $(yq '.resources[]' kustomization.yaml) ; do
54+
if [[ "${r}" =~ ^\.\./.* ]] ; then
55+
# resolve the new relative location for any resource path that is not in the local directory
56+
canonized="$(cd "${r}" ; pwd)"
57+
r="../..${canonized}"
58+
fi
59+
rewritten_resources+=("'${r}'")
60+
done
61+
if [ "${#rewritten_resources[@]}" -gt 0 ] ; then
62+
NEW_RESOURCES="[ $(printf '%s,' "${rewritten_resources[@]}") ]"
63+
fi
64+
65+
for r in $(yq '.components[]' kustomization.yaml) ; do
66+
if [[ "${r}" =~ ^\.\./.* ]] ; then
67+
# resolve the new relative location for any resource path that is not in the local directory
68+
canonized="$(cd "${r}" ; pwd)"
69+
r="../..${canonized}"
70+
fi
71+
rewritten_components+=("'${r}'")
72+
done
73+
if [ "${#rewritten_components[@]}" -gt 0 ] ; then
74+
NEW_COMPONENTS="[ $(printf '%s,' "${rewritten_components[@]}") ]"
75+
fi
76+
77+
env NAMESPACE="${NAMESPACE}" \
78+
NEW_RESOURCES="${NEW_RESOURCES}" \
79+
NEW_COMPONENTS="${NEW_COMPONENTS}" \
80+
yq -i '
81+
.namespace = strenv(NAMESPACE) |
82+
.resources = env(NEW_RESOURCES) |
83+
.components = env(NEW_COMPONENTS)
84+
' "${kustomize_dir}/kustomization.yaml"
85+
86+
if [ "${DEBUG}" = 'true' ] ; then
87+
cat "${kustomize_dir}/kustomization.yaml"
88+
fi
89+
90+
kubectl apply -k "${kustomize_dir}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# Test runner using KUTTL against a target cluster.
18+
# https://kuttl.dev
19+
# https://kind.sigs.k8s.io
20+
#
21+
# Test runner using KUTTL against a target cluster.
22+
# https://kuttl.dev
23+
# https://kind.sigs.k8s.io
24+
---
25+
# Does not use Kuttl's built-in KIND support -- it doesn't quite work correctly with a VM-based
26+
# (Docker Desktop) style of runtime. Instead, assumes the cluster is established outside of kuttl
27+
# and configuration is provided via `--env`.
28+
apiVersion: kuttl.dev/v1beta1
29+
kind: TestSuite
30+
testDirs:
31+
- ./tests/integration
32+
timeout:
33+
# these tests allocate several pods with dependencies between them, allow some time for
34+
# everything to launch and settle.
35+
300
36+
reportName: kuttl-report-integration
37+
reportFormat: xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# Test runner using KUTTL against a target cluster.
18+
# https://kuttl.dev
19+
# https://kind.sigs.k8s.io
20+
# Test runner using https://kuttl.dev
21+
---
22+
apiVersion: kuttl.dev/v1beta1
23+
kind: TestSuite
24+
startControlPlane: true
25+
testDirs:
26+
- ./tests/unit
27+
reportName: kuttl-report-unit
28+
reportFormat: xml

0 commit comments

Comments
 (0)