Skip to content

Commit b8ea14a

Browse files
authored
Merge pull request #8 from ContainerSolutions/api_check_script
really simple and inefficient script for checking api deprecation
2 parents 4d37272 + ab67f07 commit b8ea14a

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

.supported-k8s-versions

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
v1.19.0
2+
v1.18.0
3+
v1.17.0
4+
v1.16.0
5+
v1.15.0

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ $ kubectl examples Ingress fanout | kubectl create -f - --edit
5252

5353
`[A-Z][a-zA-Z]*` - Example yamls that correspond to resource types.
5454

55+
`test` - Scripts to test or validate the YAML
56+
5557
Within those folders are either simple/canonical examples, or examples in subfolders that expose particular items of functionality that are highlighted by their yaml path, eg `Pod/spec.initContainers/`.
5658

5759
If an example is an exemplar of a particular feature but tightly related to another resource, then an absolute folder might be added eg in Service there is `Service/Pod.spec.subdomain`.

tests/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Kubernetes Examples Tests
2+
3+
`api_check.sh` - Checks yaml against API definitions

tests/api_check.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
# Move to parent folder
4+
SOURCE="${BASH_SOURCE[0]}"
5+
while [ -h "${SOURCE}" ]; do # resolve $SOURCE until the file is no longer a symlink
6+
readonly BIN_DIR="$(cd -P "$(dirname "$SOURCE}")" && pwd)"
7+
SOURCE="$(readlink "${SOURCE}")"
8+
[[ ${SOURCE} != /* ]] && SOURCE="${BIN_DIR}/${SOURCE}" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
9+
done
10+
readonly DIR="$(cd -P "$(dirname "${SOURCE}")" && pwd)"
11+
# Move to this directory's parent
12+
cd "${DIR}/.."
13+
14+
if ! RES=$(kubectl deprecations --input-file Pod/simple.yaml 2>&1)
15+
then
16+
echo '`kubectl deprecations` did not run ok. You may need to install the krew 'deprecations' package. See https://krew.sigs.k8s.io/'
17+
echo 'OUTPUT:'
18+
echo "${RES}"
19+
exit 1
20+
fi
21+
22+
if [[ $# -eq 0 ]]
23+
then
24+
while IFS= read -r line
25+
do
26+
echo "================================================================================"
27+
echo "Looking at k8s version: ${line}"
28+
echo "================================================================================"
29+
echo
30+
for f in $(find . -type f -name "*.yaml")
31+
do
32+
echo -n "${f} "
33+
if RES=$(kubectl deprecations --error-on-deleted --error-on-deprecated --k8s-version="$line" --input-file "${f}" 2>&1)
34+
then
35+
echo '....OK'
36+
else
37+
echo
38+
echo "================================================================================"
39+
echo "Problem with file: ${f} on k8s version ${line}"
40+
echo "================================================================================"
41+
echo "Output was: ${RES}"
42+
echo "================================================================================"
43+
echo
44+
echo "Checking files... "
45+
fi
46+
done
47+
done < .supported-k8s-versions
48+
else
49+
find . -type f -name "*.yaml" -exec echo {} \; -exec kubectl deprecations --error-on-deleted --error-on-deprecated --k8s-version="v$1" --input-file {} \;
50+
fi

0 commit comments

Comments
 (0)