fix: kubectl replace fails if not exists
Some checks failed
/ deploy (push) Failing after 6s

This commit is contained in:
ange 2025-02-27 01:21:31 +00:00
parent 03ca2e37e5
commit c457cda583
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D

View File

@ -3,34 +3,30 @@ set -o pipefail
function kapply() {
for f in "$@"; do
kubectl apply -f <(envsubst < "manifests/$f")
kubectl apply --server-side -f<(envsubst < "manifests/$f")
done
}; export -f kapply
function kcreatesec() {
kubectl create secret generic --dry-run=client -oyaml "$@" | kubectl replace -f-
kapply <(kubectl create secret generic --dry-run=server -oyaml "$@")
}; export -f kcreatesec
function kcreatecm() {
kubectl create configmap --dry-run=client -oyaml "$@" | kubectl replace -f-
kapply <(kubectl create secret configmap --dry-run=server -oyaml "$@")
}; export -f kcreatecm
function kgseckey() {
local sec="$1"; shift
local key="$1"; shift
if ! kubectl get secret "$sec" -ojson | jq -re ".data.\"$key\" // empty" | base64 -d; then
return 1
fi
kubectl get secret "$sec" -ojson | jq -re ".data.\"$key\"" | base64 -d
}; export -f kgseckey
function kgcmkey() {
local cm="$1"; shift
local key="$1"; shift
if ! kubectl get configmap "$cm" -ojson | jq -re ".data.\"$key\" // empty"; then
return 1
fi
kubectl get configmap "$cm" -ojson | jq -re ".data.\"$key\""
}; export -f kgcmkey