@@ -23,6 +23,9 @@ PGO_IMAGE_PULL_SECRET='{{ pgo_image_pull_secret }}'
2323PGO_IMAGE_PULL_SECRET_MANIFEST=' {{ pgo_image_pull_secret_manifest }}'
2424TARGET_NAMESPACE=' {{ item }}'
2525
26+ # the name of the service account utilized by the PG pods
27+ PG_SA=" pgo-pg"
28+
2629# create the namespace if necessary
2730{{ kubectl_or_oc }} get ns {{ item }} > /dev/null
2831if [ $? -eq 0 ]; then
3740{{ kubectl_or_oc }} label namespace/{{ item }} vendor=crunchydata
3841{{ kubectl_or_oc }} label namespace/{{ item }} pgo-installation-name={{ pgo_installation_name }}
3942
43+ # determine if an existing pod is using the 'pgo-pg' service account. if so, do not delete
44+ # and recreate the SA or its associated role and role binding. this is to avoid any undesired
45+ # behavior with existing PG clusters that are actively utilizing the SA.
46+ {{ kubectl_or_oc }} -n {{ item }} get pods -o yaml | grep " serviceAccount: ${PG_SA} " > /dev/null
47+ if [ $? -ne 0 ]; then
48+ {{ kubectl_or_oc }} -n {{ item }} delete --ignore-not-found sa pgo-pg
49+ {{ kubectl_or_oc }} -n {{ item }} delete --ignore-not-found role pgo-pg-role
50+ {{ kubectl_or_oc }} -n {{ item }} delete --ignore-not-found rolebinding pgo-pg-role-binding
51+
52+ cat {{ role_path }}/files/pgo-configs/pgo-pg-sa.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
53+ cat {{ role_path }}/files/pgo-configs/pgo-pg-role.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
54+ cat {{ role_path }}/files/pgo-configs/pgo-pg-role-binding.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
55+ else
56+ echo " Running pods found using SA '${PG_SA} ' in namespace {{ item }}, will not recreate"
57+ fi
58+
4059# create RBAC
41- {{ kubectl_or_oc }} -n {{ item }} delete --ignore-not-found sa pgo-backrest pgo-default pgo-pg pgo- target
42- {{ kubectl_or_oc }} -n {{ item }} delete --ignore-not-found role pgo-backrest-role pgo-pg-role pgo- target-role
43- {{ kubectl_or_oc }} -n {{ item }} delete --ignore-not-found rolebinding pgo-backrest-role-binding pgo-pg-role-binding pgo- target-role-binding
60+ {{ kubectl_or_oc }} -n {{ item }} delete --ignore-not-found sa pgo-backrest pgo-default pgo-target
61+ {{ kubectl_or_oc }} -n {{ item }} delete --ignore-not-found role pgo-backrest-role pgo-target-role
62+ {{ kubectl_or_oc }} -n {{ item }} delete --ignore-not-found rolebinding pgo-backrest-role-binding pgo-target-role-binding
4463
4564cat {{ role_path }}/files/pgo-configs/pgo-default-sa.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
4665cat {{ role_path }}/files/pgo-configs/pgo-target-sa.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
@@ -49,9 +68,6 @@ cat {{ role_path }}/files/pgo-configs/pgo-target-role-binding.json | sed 's/{{ t
4968cat {{ role_path }}/files/pgo-configs/pgo-backrest-sa.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
5069cat {{ role_path }}/files/pgo-configs/pgo-backrest-role.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
5170cat {{ role_path }}/files/pgo-configs/pgo-backrest-role-binding.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
52- cat {{ role_path }}/files/pgo-configs/pgo-pg-sa.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
53- cat {{ role_path }}/files/pgo-configs/pgo-pg-role.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
54- cat {{ role_path }}/files/pgo-configs/pgo-pg-role-binding.json | sed ' s/{{ target_namespace }}/' " {{ item }}" ' /' | {{ kubectl_or_oc }} -n {{ item }} create -f -
5571
5672if [ -r " $PGO_IMAGE_PULL_SECRET_MANIFEST " ]; then
5773 $PGO_CMD -n " $TARGET_NAMESPACE " create -f " $PGO_IMAGE_PULL_SECRET_MANIFEST "
0 commit comments