| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
|
| 4 |
# Validator transformer plugin by kubeval |
| 5 |
# https://github.com/instrumenta/kubeval |
| 6 |
# |
| 7 |
# Assumes that kubeval is available from $PATH |
| 8 |
# |
| 9 |
# Reads Kubernetes resources from stdin |
| 10 |
# Validates them and output in the stdout |
| 11 |
# |
| 12 |
# Example execution: |
| 13 |
# cat <raw K8s yaml> | ./plugin/someteam.example.com/v1/validator/Validator |
| 14 |
|
| 15 |
if ! [ -x "$(command -v kubeval)" ]; then |
| 16 |
echo "Error: kubeval is not installed." |
| 17 |
exit 1 |
| 18 |
fi |
| 19 |
|
| 20 |
temp_file=$(mktemp) |
| 21 |
output_file=$(mktemp) |
| 22 |
cat - > $temp_file |
| 23 |
|
| 24 |
kubeval $temp_file > $output_file |
| 25 |
|
| 26 |
if [ $? -eq 0 ]; then |
| 27 |
cat $temp_file |
| 28 |
rm $temp_file $output_file |
| 29 |
exit 0 |
| 30 |
fi |
| 31 |
|
| 32 |
cat $output_file |
| 33 |
rm $temp_file $output_file |
| 34 |
exit 1 |
| 35 |
|