Skip to content

Commit

Permalink
Merge pull request #8 from ContainerSolutions/api_check_script
Browse files Browse the repository at this point in the history
really simple and inefficient script for checking api deprecation
  • Loading branch information
ianmiell authored Sep 10, 2020
2 parents 4d37272 + ab67f07 commit b8ea14a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .supported-k8s-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
v1.19.0
v1.18.0
v1.17.0
v1.16.0
v1.15.0
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ $ kubectl examples Ingress fanout | kubectl create -f - --edit

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

`test` - Scripts to test or validate the YAML

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/`.

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`.
Expand Down
3 changes: 3 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Kubernetes Examples Tests

`api_check.sh` - Checks yaml against API definitions
50 changes: 50 additions & 0 deletions tests/api_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

# Move to parent folder
SOURCE="${BASH_SOURCE[0]}"
while [ -h "${SOURCE}" ]; do # resolve $SOURCE until the file is no longer a symlink
readonly BIN_DIR="$(cd -P "$(dirname "$SOURCE}")" && pwd)"
SOURCE="$(readlink "${SOURCE}")"
[[ ${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
done
readonly DIR="$(cd -P "$(dirname "${SOURCE}")" && pwd)"
# Move to this directory's parent
cd "${DIR}/.."

if ! RES=$(kubectl deprecations --input-file Pod/simple.yaml 2>&1)
then
echo '`kubectl deprecations` did not run ok. You may need to install the krew 'deprecations' package. See https://krew.sigs.k8s.io/'
echo 'OUTPUT:'
echo "${RES}"
exit 1
fi

if [[ $# -eq 0 ]]
then
while IFS= read -r line
do
echo "================================================================================"
echo "Looking at k8s version: ${line}"
echo "================================================================================"
echo
for f in $(find . -type f -name "*.yaml")
do
echo -n "${f} "
if RES=$(kubectl deprecations --error-on-deleted --error-on-deprecated --k8s-version="$line" --input-file "${f}" 2>&1)
then
echo '....OK'
else
echo
echo "================================================================================"
echo "Problem with file: ${f} on k8s version ${line}"
echo "================================================================================"
echo "Output was: ${RES}"
echo "================================================================================"
echo
echo "Checking files... "
fi
done
done < .supported-k8s-versions
else
find . -type f -name "*.yaml" -exec echo {} \; -exec kubectl deprecations --error-on-deleted --error-on-deprecated --k8s-version="v$1" --input-file {} \;
fi

0 comments on commit b8ea14a

Please sign in to comment.