From 7476464518c34af0396fa9e330299f373202b7dc Mon Sep 17 00:00:00 2001 From: Gareth Rushgrove Date: Sun, 11 Aug 2019 20:28:10 +0100 Subject: [PATCH] Support passing options to Helm template and Kubeval --- README.md | 13 ++++++++++--- scripts/run.sh | 39 +++++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 362ca53..46fbada 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,7 @@ As an example of usage, here is `helm kubeval` running against one of the stable ```console $ git clone git@github.com:helm/charts.git -$ cd charts/stable/nginx-ingress -$ helm kubeval +$ helm kubeval charts/stable/nginx-ingress The file nginx-ingress/templates/serviceaccount.yaml contains a valid ServiceAccount The file nginx-ingress/templates/clusterrole.yaml contains a valid ClusterRole The file nginx-ingress/templates/clusterrolebinding.yaml contains a valid ClusterRoleBinding @@ -46,8 +45,16 @@ The file nginx-ingress/templates/udp-configmap.yaml contains an empty YAML docum You can also specify a specific Kubernetes version to validate the chart against. ``` -helm kubeval -v 1.9.0 +helm kubeval . -v 1.9.0 ``` +Kubeval has a number of flags which can alter it's behaviour, from ignoring specific resources to +exiting on the first error to disallowing properties not specified in the schema. Kubeval options +automatically passed to Kubeval, with any other options being passed to Helm in the same way as +`helm template`. This means you could set values before validating the chart. eg. + +``` +helm kubeval charts/stable/nginx-ingress --set controller.image.tag=latest +``` diff --git a/scripts/run.sh b/scripts/run.sh index 6a0967b..a5fa219 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -1,10 +1,37 @@ #! /bin/bash -e -if [[ $1 == "--version" || $1 == "--help" ]]; then - $HELM_PLUGIN_DIR/bin/kubeval $1 - exit -fi +helm_options=() +kubeval_options=() +eoo=0 -render=$(helm template .) +while [[ $1 ]] +do + if ! ((eoo)); then + case "$1" in + --version|--help) + $HELM_PLUGIN_DIR/bin/kubeval $1 + exit + ;; + --strict|--exit-on-error|--openshift|--force-color|--ignore-missing-schemas) + kubeval_options+=("$1") + shift + ;; + --output|-o|--kubernetes-version|-v|--schema-location|-s|--skip-kinds) + kubeval_options+=("$1") + kubeval_options+=("$2") + shift 2 + ;; + *) + helm_options+=("$1") + shift + ;; + esac + else + helm_options+=("$1") + shift + fi +done -echo "$render" | $HELM_PLUGIN_DIR/bin/kubeval ${@} +render=$(helm template "${helm_options[@]}") + +echo "$render" | $HELM_PLUGIN_DIR/bin/kubeval "${kubeval_options[@]}"