diff --git a/.supported-k8s-versions b/.supported-k8s-versions new file mode 100644 index 0000000..4160daf --- /dev/null +++ b/.supported-k8s-versions @@ -0,0 +1,5 @@ +v1.19.0 +v1.18.0 +v1.17.0 +v1.16.0 +v1.15.0 diff --git a/README.md b/README.md index 8f4b000..63bc13b 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..1a69ac6 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,3 @@ +# Kubernetes Examples Tests + +`api_check.sh` - Checks yaml against API definitions diff --git a/tests/api_check.sh b/tests/api_check.sh new file mode 100755 index 0000000..16ac43e --- /dev/null +++ b/tests/api_check.sh @@ -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