Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to install and run on Windows #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Install the plugin using the built-in plugin manager.
helm plugin install https://github.com/instrumenta/helm-kubeval
```

### Windows

On Windows, you *must* use GitBash to install (since the install script is a ".sh" file)

## Usage

Expand Down
4 changes: 4 additions & 0 deletions plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ usage: "Validate Helm charts"
description: |-
"Validate Helm charts against the Kubernetes schemas"
command: "$HELM_PLUGIN_DIR/scripts/run.sh"
platformCommand:
- os: windows
arch: amd64
command: "powershell -File $HELM_PLUGIN_DIR/scripts/run.ps1 $HELM_PLUGIN_DIR"

hooks:
install: "cd $HELM_PLUGIN_DIR; ./scripts/install.sh"
Expand Down
21 changes: 19 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,32 @@ cd $HELM_PLUGIN_DIR
version="$(cat plugin.yaml | grep "version" | cut -d '"' -f 2)"
echo "Installing helm-kubeval v${version} ..."

unpackCommand="tar xzvf"
directoryTargetFlag="-C"
format=".tar.gz"
arch="-amd64"
unameOut="$(uname -s)"

case "${unameOut}" in
Linux*) os=linux;;
Darwin*) os=darwin;;
MINGW32*)
os=windows
arch="-386"
format=".zip"
unpackCommand="unzip"
directoryTargetFlag="-d"
;;
MINGW64*)
os=windows
format=".zip"
unpackCommand="unzip"
directoryTargetFlag="-d"
;;
*) os="UNKNOWN:${unameOut}"
esac

url="https://github.com/instrumenta/kubeval/releases/download/${version}/kubeval-${os}-amd64.tar.gz"
url="https://github.com/instrumenta/kubeval/releases/download/${version}/kubeval-${os}${arch}${format}"

if [ "$url" = "" ]
then
Expand All @@ -33,7 +50,7 @@ else
exit -1
fi

rm -rf bin && mkdir bin && tar xzvf $filename -C bin > /dev/null && rm -f $filename
rm -rf bin && mkdir bin && $unpackCommand $filename $directoryTargetFlag bin > /dev/null && rm -f $filename

echo "helm-kubeval ${version} is installed."
echo
Expand Down
37 changes: 37 additions & 0 deletions scripts/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
$helmOptions=@()
$kubevalOptions=@()
$HELM_PLUGIN_DIR="$($args[0])" #This is not getting set when the powershell is called, so we pass it
$kubevalCommand="$HELM_PLUGIN_DIR\\bin\\kubeval"

# We're going to try and take out the kubeval options from the helm ones
for ($i=1; $i -lt $args.Length; $i++)
{
$currArg="$($args[$i])"

switch ("$($args[$i])")
{
# Kubeval commands
{ ($_ -eq "--version") -or ($_ -eq "--help")}
{
# Just send to kubeval
Invoke-Expression "& $kubevalCommand $currArg"
exit
}
{($_ -eq "--strict") -or ($_ -eq "--exit-on-error") -or ($_ -eq "--openshift") -or ($_ -eq "--force-color") -or ($_ -eq "--ignore-missing-schemas")}
{
$kubevalOptions += "$currArg"
}
{($_ -eq "--output") -or ($_ -eq "-o") -or ($_ -eq "--kubernetes-version") -or ($_ -eq "-v") -or ($_ -eq "--schema-location") -or ($_ -eq "-s") -or ($_ -eq "--skip-kinds")}
{
$kubevalOptions += "$currArg"
$kubevalOptions += "$($args[$i+1])"

#Skip the "value"
$i++
}
Default { $helmOptions += "$currArg" }
}
}

# Send it to kubeval
Invoke-Expression "helm template $helmOptions | $kubevalCommand $kubevalOptions"