Przeglądaj źródła

Remove project metadata prefixed with the cluster prefix

Allows other scripts to create metadata that is cleaned up safely.
Clayton Coleman 7 lat temu
rodzic
commit
d2dd9cb8a8
1 zmienionych plików z 10 dodań i 1 usunięć
  1. 10 1
      roles/openshift_gcp/templates/remove.j2.sh

+ 10 - 1
roles/openshift_gcp/templates/remove.j2.sh

@@ -37,7 +37,7 @@ function teardown() {
 # scale down {{ node_group.name }}
 (
     # performs a delete and scale down as one operation to ensure maximum parallelism
-    if ! instances=$( gcloud --project "{{ openshift_gcp_project }}" compute instance-groups managed list-instances "{{ openshift_gcp_prefix }}ig-{{ node_group.suffix }}" --zone "{{ openshift_gcp_zone }}" --format='value[terminator=","](instance)' ); then
+    if ! instances=$( gcloud --project "{{ openshift_gcp_project }}" compute instance-groups managed list-instances "{{ openshift_gcp_prefix }}ig-{{ node_group.suffix }}" --zone "{{ openshift_gcp_zone }}" --format='value[terminator=","](instance)' 2>/dev/null ); then
         exit 0
     fi
     instances="${instances%?}"
@@ -59,6 +59,15 @@ if gsutil ls -p "{{ openshift_gcp_project }}" "gs://{{ openshift_gcp_registry_bu
 fi
 ) &
 
+# Project metadata prefixed with {{ openshift_gcp_prefix }}
+(
+    for key in $( gcloud --project "{{ openshift_gcp_project }}" compute project-info describe --flatten=commonInstanceMetadata.items[] '--format=value(commonInstanceMetadata.items.key)' ); do
+        if [[ "${key}" == "{{ openshift_gcp_prefix }}"* ]]; then
+            gcloud --project "{{ openshift_gcp_project }}" compute project-info remove-metadata "--keys=${key}"
+        fi
+    done
+) &
+
 # DNS
 (
 dns_zone="{{ dns_managed_zone | default(openshift_gcp_prefix + 'managed-zone') }}"