Skip to content

Commit 2eadc4f

Browse files
jmckulkJonathan S. Katz
authored andcommitted
Updates add-targeted-namespace script
- Removes dependency on expenv by using sed to replace environment variables - If a namespace existed in the environment we need to confirm that it has the correct labels. This is done by blindly adding the labels to the existing namespace. These commands are moved inside of the if statement so that they are only called if the namespace exists. If the namespace doesn't exist it is created with the labels so adding them again adds unnecessary errors. Moving the lines also makes the script and the purpose of these commands more clear.
1 parent 83c5dce commit 2eadc4f

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

ansible/roles/pgo-operator/templates/add-targeted-namespace.sh.j2

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ PG_SA="pgo-pg"
2929
# create the namespace if necessary
3030
{{ kubectl_or_oc }} get ns {{ item }} > /dev/null
3131
if [ $? -eq 0 ]; then
32-
echo "namespace" {{ item }} "already exists"
32+
echo "namespace" {{ item }} "already exists, adding labels"
33+
# set the labels so that existing namespace is owned by this installation
34+
{{ kubectl_or_oc }} label namespace/{{ item }} pgo-created-by=add-script
35+
{{ kubectl_or_oc }} label namespace/{{ item }} vendor=crunchydata
36+
{{ kubectl_or_oc }} label namespace/{{ item }} pgo-installation-name={{ pgo_installation_name }}
3337
else
3438
echo "namespace" {{ item }} "is new"
3539
{{ kubectl_or_oc }} create ns {{ item }}
3640
fi
3741

38-
# set the labels so that this namespace is owned by this installation
39-
{{ kubectl_or_oc }} label namespace/{{ item }} pgo-created-by=add-script
40-
{{ kubectl_or_oc }} label namespace/{{ item }} vendor=crunchydata
41-
{{ kubectl_or_oc }} label namespace/{{ item }} pgo-installation-name={{ pgo_installation_name }}
42-
4342
# determine if an existing pod is using the 'pgo-pg' service account. if so, do not delete
4443
# and recreate the SA or its associated role and role binding. this is to avoid any undesired
4544
# behavior with existing PG clusters that are actively utilizing the SA.

deploy/add-targeted-namespace.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@ fi
3232
# create the namespace if necessary
3333
$PGO_CMD get ns $1 > /dev/null
3434
if [ $? -eq 0 ]; then
35-
echo "namespace" $1 "already exists"
35+
echo "namespace" $1 "already exists, adding labels"
36+
# set the labels so that existing namespace is owned by this installation
37+
$PGO_CMD label namespace/$1 pgo-created-by=add-script
38+
$PGO_CMD label namespace/$1 vendor=crunchydata
39+
$PGO_CMD label namespace/$1 pgo-installation-name=$PGO_INSTALLATION_NAME
3640
else
3741
echo "namespace" $1 "is new"
38-
TARGET_NAMESPACE=$1 expenv -f $DIR/target-namespace.yaml | $PGO_CMD create -f -
42+
cat $DIR/target-namespace.yaml | sed -e 's/$TARGET_NAMESPACE/'"$1"'/' -e 's/$PGO_INSTALLATION_NAME/'"$PGO_INSTALLATION_NAME"'/' | $PGO_CMD create -f -
3943
fi
4044

41-
# set the labels so that this namespace is owned by this installation
42-
$PGO_CMD label namespace/$1 pgo-created-by=add-script
43-
$PGO_CMD label namespace/$1 vendor=crunchydata
44-
$PGO_CMD label namespace/$1 pgo-installation-name=$PGO_INSTALLATION_NAME
45-
4645
# determine if an existing pod is using the 'pgo-pg' service account. if so, do not delete
4746
# and recreate the SA or its associated role and role binding. this is to avoid any undesired
4847
# behavior with existing PG clusters that are actively utilizing the SA.

0 commit comments

Comments
 (0)