#!/bin/bash

warn=0

for ns in $(kubectl get ns --no-headers | awk '{print $1":"$2}') ; do
    name=$(echo $ns | cut -d ':' -f 1)
    state=$(echo $ns | cut -d ':' -f 2)
    if [[ $state == "Active" ]] ; then
        ok_message=$ok_message"$name is $state\n"
    else
        warn=1
        warn_message=$warn_message"$name is $state\n"
    fi
done

if [[ $warn -eq 1 ]] ; then
    echo "WARNING: One or more namespaces are not actives"
    echo -e $warn_message
    exit 1
else
    echo "OK: All the namespaces are in active state"
    echo -e $ok_message
    exit 0
fi
