Skip to content

Commit

Permalink
Merge pull request #3 from nico151999/feat/proxy-for-deletion
Browse files Browse the repository at this point in the history
feat: add optional proxy to cluster deletion call
  • Loading branch information
eumel8 authored Apr 4, 2024
2 parents bcdc0c5 + 8f6492c commit afda470
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 75 deletions.
4 changes: 2 additions & 2 deletions charts/rancher-cluster/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: v2
appVersion: "0.1.0"
appVersion: "0.1.1"
description: Job for create a cluster import in Rancher
maintainers:
- name: eumel8 # Frank Kloeker
email: [email protected]
url: https://www.telekom.com
name: rancher-cluster
version: 0.1.0
version: 0.1.1
55 changes: 41 additions & 14 deletions charts/rancher-cluster/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ data:
--request GET \
--url "$RANCHERURL/v3/clusters?name=$CLUSTERNAME" \
-u "$APITOKEN" | jq -r '.data[0].id')"
if [[ "$CLUSTER_ID" != 'null' ]]; then
if [[ "$CLUSTER_ID" != 'null' ]] && [[ -n "$CLUSTER_ID" ]]; then
break
elif [[ "$i" == '20' ]]; then
echo "Could not get cluster ID for $CLUSTERNAME"
Expand All @@ -91,7 +91,7 @@ data:
--request GET \
--url "$RANCHERURL/v3/clusterregistrationtokens?clusterId=$CLUSTER_ID" \
-u "$APITOKEN" | jq -r '.data[0].manifestUrl')"
if [[ "$AGENTURL" != 'null' ]]; then
if [[ "$AGENTURL" != 'null' ]] && [[ -n "$AGENTURL" ]]; then
break
elif [[ "$i" == '20' ]]; then
echo "Could not get cluster registration token for $CLUSTERNAME ($CLUSTER_ID)"
Expand Down Expand Up @@ -135,20 +135,47 @@ data:
echo "Successfully set up Vcluster as Rancher cluster"
delete.sh: |
echo "CLUSTERNAME: $CLUSTERNAME"
while [ -z "$CLUSTERRESPONSE" ]; do
sleep 5
CLUSTERRESPONSE=`curl {{ $insecure }} -s "$RANCHERURL/v3/clusters?name=$CLUSTERNAME" -H 'content-type: application/json' -u "$APITOKEN"`
echo "CLUSTERRESPONSE: $CLUSTERRESPONSE"
echo "Removing cluster $CLUSTERNAME"
echo "Getting cluster ID for $CLUSTERNAME"
while :
do
CLUSTER_ID="$(curl {{ $insecure }} {{ $http_proxy }} \
--retry 5 --retry-delay 5 \
-sfL \
--request GET \
--url "$RANCHERURL/v3/clusters?name=$CLUSTERNAME" \
-u "$APITOKEN" | jq -r '.data[0].id')"
if [[ "$CLUSTER_ID" != 'null' ]] && [[ -n "$CLUSTER_ID" ]]; then
break
elif [[ "$i" == '20' ]]; then
echo "Could not get cluster ID for $CLUSTERNAME"
exit 1
fi
sleep 5
done
CLUSTERID=`echo $CLUSTERRESPONSE | jq -r '.data[].id'`
echo "CLUSTERID: $CLUSTERID"
while [[ ! "$REMOVE" =~ "removing" ]]; do
sleep 5
REMOVE=`curl {{ $insecure }} -s -X DELETE "$RANCHERURL/v3/clusters/${CLUSTERID}" -H 'content-type: application/json' -u "$APITOKEN" |jq -r .state`
echo "REMOVE: $REMOVE"
echo "Got cluster ID ($CLUSTER_ID) for $CLUSTERNAME"
echo "Removing cluster with ID $CLUSTER_ID"
while :
do
RESULT="$(curl {{ $insecure }} {{ $http_proxy }} \
--retry 5 --retry-delay 5 \
-sfL \
--request DELETE \
--url "$RANCHERURL/v3/clusters/${CLUSTER_ID}" \
-u "$APITOKEN" | jq -r '.state')"
if [[ "$RESULT" != 'null' ]] && [[ -n "$RESULT" ]]; then
break
elif [[ "$i" == '20' ]]; then
echo "Could not remove cluster with ID $CLUSTER_ID"
exit 1
fi
sleep 5
done
echo "CLUSTER REMOVED: $CLUSTERID"
echo "Removed cluster with ID $CLUSTER_ID (Result: $RESULT)"
echo "Successfully removed cluster $CLUSTERNAME"
kind: ConfigMap
metadata:
labels:
Expand Down
Loading

0 comments on commit afda470

Please sign in to comment.