@@ -737,26 +737,28 @@ func TestAddServerToInstancePod(t *testing.T) {
737737 # Parameters for curl when managing autogrow annotation.
738738 APISERVER="https://kubernetes.default.svc"
739739 SERVICEACCOUNT="/var/run/secrets/kubernetes.io/serviceaccount"
740- NAMESPACE=$(cat ${SERVICEACCOUNT}/namespace)
741- TOKEN=$(cat ${SERVICEACCOUNT}/token)
740+ NAMESPACE=$(cat " ${SERVICEACCOUNT}" /namespace)
741+ TOKEN=$(cat " ${SERVICEACCOUNT}" /token)
742742 CACERT=${SERVICEACCOUNT}/ca.crt
743743
744744 # Manage autogrow annotation.
745745 # Return size in Mebibytes.
746746 manageAutogrowAnnotation() {
747747 local volume=$1
748748
749- size=$(df --human-readable --block-size=M /pgbackrest/"${volume}" | awk 'FNR == 2 {print $2}')
750- use=$(df --human-readable /pgbackrest/"${volume}" | awk 'FNR == 2 {print $5}')
749+ size=$(df --human-readable --block-size=M "/pgbackrest/${volume}")
750+ read -r _ size _ <<< "${size#*$'\n'}"
751+ use=$(df --human-readable "/pgbackrest/${volume}")
752+ read -r _ _ _ _ use _ <<< "${use#*$'\n'}"
751753 sizeInt="${size//M/}"
752754 # Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.
753- useInt=$(echo $ use | sed 's/ [[:punct:]]//g')
755+ useInt=${ use// [[:punct:]]/}
754756 triggerExpansion="$((useInt > 75))"
755- if [ $ triggerExpansion -eq 1 ]; then
757+ if [[ ${ triggerExpansion} -eq 1 ] ]; then
756758 newSize="$(((sizeInt / 2)+sizeInt))"
757759 newSizeMi="${newSize}Mi"
758- d='[{"op": "add", "path": "/metadata/annotations/suggested-'"${volume}"'-pvc-size", "value": "'"$newSizeMi"'"}]'
759- curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -XPATCH "${APISERVER}/api/v1/namespaces/${NAMESPACE}/pods/${HOSTNAME}?fieldManager=kubectl-annotate" -H "Content-Type: application/json-patch+json" --data "$d "
760+ d='[{"op": "add", "path": "/metadata/annotations/suggested-'"${volume}"'-pvc-size", "value": "'"${ newSizeMi} "'"}]'
761+ curl --cacert " ${CACERT}" --header "Authorization: Bearer ${TOKEN}" -XPATCH "${APISERVER}/api/v1/namespaces/${NAMESPACE}/pods/${HOSTNAME}?fieldManager=kubectl-annotate" -H "Content-Type: application/json-patch+json" --data "${d} "
760762 fi
761763 }
762764
@@ -779,22 +781,22 @@ func TestAddServerToInstancePod(t *testing.T) {
779781 fi
780782
781783 # manage autogrow annotation for the repo1 volume, if it exists
782- if [ -d /pgbackrest/repo1 ]; then
784+ if [[ -d /pgbackrest/repo1 ] ]; then
783785 manageAutogrowAnnotation "repo1"
784786 fi
785787
786788 # manage autogrow annotation for the repo2 volume, if it exists
787- if [ -d /pgbackrest/repo2 ]; then
789+ if [[ -d /pgbackrest/repo2 ] ]; then
788790 manageAutogrowAnnotation "repo2"
789791 fi
790792
791793 # manage autogrow annotation for the repo3 volume, if it exists
792- if [ -d /pgbackrest/repo3 ]; then
794+ if [[ -d /pgbackrest/repo3 ] ]; then
793795 manageAutogrowAnnotation "repo3"
794796 fi
795797
796798 # manage autogrow annotation for the repo4 volume, if it exists
797- if [ -d /pgbackrest/repo4 ]; then
799+ if [[ -d /pgbackrest/repo4 ] ]; then
798800 manageAutogrowAnnotation "repo4"
799801 fi
800802
@@ -913,26 +915,28 @@ func TestAddServerToInstancePod(t *testing.T) {
913915 # Parameters for curl when managing autogrow annotation.
914916 APISERVER="https://kubernetes.default.svc"
915917 SERVICEACCOUNT="/var/run/secrets/kubernetes.io/serviceaccount"
916- NAMESPACE=$(cat ${SERVICEACCOUNT}/namespace)
917- TOKEN=$(cat ${SERVICEACCOUNT}/token)
918+ NAMESPACE=$(cat " ${SERVICEACCOUNT}" /namespace)
919+ TOKEN=$(cat " ${SERVICEACCOUNT}" /token)
918920 CACERT=${SERVICEACCOUNT}/ca.crt
919921
920922 # Manage autogrow annotation.
921923 # Return size in Mebibytes.
922924 manageAutogrowAnnotation() {
923925 local volume=$1
924926
925- size=$(df --human-readable --block-size=M /pgbackrest/"${volume}" | awk 'FNR == 2 {print $2}')
926- use=$(df --human-readable /pgbackrest/"${volume}" | awk 'FNR == 2 {print $5}')
927+ size=$(df --human-readable --block-size=M "/pgbackrest/${volume}")
928+ read -r _ size _ <<< "${size#*$'\n'}"
929+ use=$(df --human-readable "/pgbackrest/${volume}")
930+ read -r _ _ _ _ use _ <<< "${use#*$'\n'}"
927931 sizeInt="${size//M/}"
928932 # Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.
929- useInt=$(echo $ use | sed 's/ [[:punct:]]//g')
933+ useInt=${ use// [[:punct:]]/}
930934 triggerExpansion="$((useInt > 75))"
931- if [ $ triggerExpansion -eq 1 ]; then
935+ if [[ ${ triggerExpansion} -eq 1 ] ]; then
932936 newSize="$(((sizeInt / 2)+sizeInt))"
933937 newSizeMi="${newSize}Mi"
934- d='[{"op": "add", "path": "/metadata/annotations/suggested-'"${volume}"'-pvc-size", "value": "'"$newSizeMi"'"}]'
935- curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -XPATCH "${APISERVER}/api/v1/namespaces/${NAMESPACE}/pods/${HOSTNAME}?fieldManager=kubectl-annotate" -H "Content-Type: application/json-patch+json" --data "$d "
938+ d='[{"op": "add", "path": "/metadata/annotations/suggested-'"${volume}"'-pvc-size", "value": "'"${ newSizeMi} "'"}]'
939+ curl --cacert " ${CACERT}" --header "Authorization: Bearer ${TOKEN}" -XPATCH "${APISERVER}/api/v1/namespaces/${NAMESPACE}/pods/${HOSTNAME}?fieldManager=kubectl-annotate" -H "Content-Type: application/json-patch+json" --data "${d} "
936940 fi
937941 }
938942
@@ -955,22 +959,22 @@ func TestAddServerToInstancePod(t *testing.T) {
955959 fi
956960
957961 # manage autogrow annotation for the repo1 volume, if it exists
958- if [ -d /pgbackrest/repo1 ]; then
962+ if [[ -d /pgbackrest/repo1 ] ]; then
959963 manageAutogrowAnnotation "repo1"
960964 fi
961965
962966 # manage autogrow annotation for the repo2 volume, if it exists
963- if [ -d /pgbackrest/repo2 ]; then
967+ if [[ -d /pgbackrest/repo2 ] ]; then
964968 manageAutogrowAnnotation "repo2"
965969 fi
966970
967971 # manage autogrow annotation for the repo3 volume, if it exists
968- if [ -d /pgbackrest/repo3 ]; then
972+ if [[ -d /pgbackrest/repo3 ] ]; then
969973 manageAutogrowAnnotation "repo3"
970974 fi
971975
972976 # manage autogrow annotation for the repo4 volume, if it exists
973- if [ -d /pgbackrest/repo4 ]; then
977+ if [[ -d /pgbackrest/repo4 ] ]; then
974978 manageAutogrowAnnotation "repo4"
975979 fi
976980
@@ -1078,26 +1082,28 @@ func TestAddServerToRepoPod(t *testing.T) {
10781082 # Parameters for curl when managing autogrow annotation.
10791083 APISERVER="https://kubernetes.default.svc"
10801084 SERVICEACCOUNT="/var/run/secrets/kubernetes.io/serviceaccount"
1081- NAMESPACE=$(cat ${SERVICEACCOUNT}/namespace)
1082- TOKEN=$(cat ${SERVICEACCOUNT}/token)
1085+ NAMESPACE=$(cat " ${SERVICEACCOUNT}" /namespace)
1086+ TOKEN=$(cat " ${SERVICEACCOUNT}" /token)
10831087 CACERT=${SERVICEACCOUNT}/ca.crt
10841088
10851089 # Manage autogrow annotation.
10861090 # Return size in Mebibytes.
10871091 manageAutogrowAnnotation() {
10881092 local volume=$1
10891093
1090- size=$(df --human-readable --block-size=M /pgbackrest/"${volume}" | awk 'FNR == 2 {print $2}')
1091- use=$(df --human-readable /pgbackrest/"${volume}" | awk 'FNR == 2 {print $5}')
1094+ size=$(df --human-readable --block-size=M "/pgbackrest/${volume}")
1095+ read -r _ size _ <<< "${size#*$'\n'}"
1096+ use=$(df --human-readable "/pgbackrest/${volume}")
1097+ read -r _ _ _ _ use _ <<< "${use#*$'\n'}"
10921098 sizeInt="${size//M/}"
10931099 # Use the sed punctuation class, because the shell will not accept the percent sign in an expansion.
1094- useInt=$(echo $ use | sed 's/ [[:punct:]]//g')
1100+ useInt=${ use// [[:punct:]]/}
10951101 triggerExpansion="$((useInt > 75))"
1096- if [ $ triggerExpansion -eq 1 ]; then
1102+ if [[ ${ triggerExpansion} -eq 1 ] ]; then
10971103 newSize="$(((sizeInt / 2)+sizeInt))"
10981104 newSizeMi="${newSize}Mi"
1099- d='[{"op": "add", "path": "/metadata/annotations/suggested-'"${volume}"'-pvc-size", "value": "'"$newSizeMi"'"}]'
1100- curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -XPATCH "${APISERVER}/api/v1/namespaces/${NAMESPACE}/pods/${HOSTNAME}?fieldManager=kubectl-annotate" -H "Content-Type: application/json-patch+json" --data "$d "
1105+ d='[{"op": "add", "path": "/metadata/annotations/suggested-'"${volume}"'-pvc-size", "value": "'"${ newSizeMi} "'"}]'
1106+ curl --cacert " ${CACERT}" --header "Authorization: Bearer ${TOKEN}" -XPATCH "${APISERVER}/api/v1/namespaces/${NAMESPACE}/pods/${HOSTNAME}?fieldManager=kubectl-annotate" -H "Content-Type: application/json-patch+json" --data "${d} "
11011107 fi
11021108 }
11031109
@@ -1120,22 +1126,22 @@ func TestAddServerToRepoPod(t *testing.T) {
11201126 fi
11211127
11221128 # manage autogrow annotation for the repo1 volume, if it exists
1123- if [ -d /pgbackrest/repo1 ]; then
1129+ if [[ -d /pgbackrest/repo1 ] ]; then
11241130 manageAutogrowAnnotation "repo1"
11251131 fi
11261132
11271133 # manage autogrow annotation for the repo2 volume, if it exists
1128- if [ -d /pgbackrest/repo2 ]; then
1134+ if [[ -d /pgbackrest/repo2 ] ]; then
11291135 manageAutogrowAnnotation "repo2"
11301136 fi
11311137
11321138 # manage autogrow annotation for the repo3 volume, if it exists
1133- if [ -d /pgbackrest/repo3 ]; then
1139+ if [[ -d /pgbackrest/repo3 ] ]; then
11341140 manageAutogrowAnnotation "repo3"
11351141 fi
11361142
11371143 # manage autogrow annotation for the repo4 volume, if it exists
1138- if [ -d /pgbackrest/repo4 ]; then
1144+ if [[ -d /pgbackrest/repo4 ] ]; then
11391145 manageAutogrowAnnotation "repo4"
11401146 fi
11411147
0 commit comments