29 lines
903 B
Bash
Executable File
29 lines
903 B
Bash
Executable File
#!/bin/bash -e
|
|
|
|
kubectl config use-context "$1"
|
|
|
|
namespace=$2
|
|
lb_name=$3
|
|
new_name=$4
|
|
annotations="/tmp/annotations_${lb_name}.json"
|
|
|
|
original_lb="/tmp/${namespace}_${lb_name}.json"
|
|
kubectl get ingress -n "${namespace}" "${lb_name}" -o json > "$original_lb"
|
|
|
|
# change name
|
|
final_lb="/tmp/${namespace}_${new_name}_.json"
|
|
jq --arg name "${new_name}" '.metadata.name = $name' "$original_lb" > "$final_lb"
|
|
|
|
# add annotation
|
|
if [ "$(jq 'if . == {} then error(empty) else 1 end' < "$annotations")" ]; then
|
|
echo 'Applying annotations'
|
|
annotation_changed_lb="/tmp/${namespace}_${new_name}_annotation.json"
|
|
jq --argjson annotations "$(<"$annotations")" '.metadata.annotations = $annotations' "$final_lb" > "$annotation_changed_lb"
|
|
cp "$annotation_changed_lb" "$final_lb"
|
|
else
|
|
echo 'Skipping applying annotations because they were empty'
|
|
fi
|
|
|
|
kubectl delete -f "$original_lb"
|
|
kubectl apply -f "$final_lb"
|