#!/bin/bash
if [ ! -n "$1" ]
then
echo "usage: apply-with-check overlay/foo"
exit 1
fi
if [ ! -f "$1/CONTEXT" ]; then
echo "CONTEXT missing, won't apply!"
exit 1
fi
CONTEXT_TO_USE=$(<$1/CONTEXT)
echo "checking context: $CONTEXT_TO_USE"
CURRENT_CONTEXT=$(kubectl config current-context)
if [[ $CONTEXT_TO_USE != $CURRENT_CONTEXT ]]; then
echo "ALARM! current context is: $CURRENT_CONTEXT **not applying**"
exit 1
fi
echo "ok, current context is: $CURRENT_CONTEXT, now applying"
kubectl apply -k $1
1条答案
按热度按时间pvcm50d11#
剧本似乎是目前唯一的办法。也许有人也可以使用它。CONTEXT文件的内容是应该使用的上下文。