@@ -737,26 +737,28 @@ func TestAddServerToInstancePod(t *testing.T) {
737
737
# Parameters for curl when managing autogrow annotation.
738
738
APISERVER="https://kubernetes.default.svc"
739
739
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)
742
742
CACERT=${SERVICEACCOUNT}/ca.crt
743
743
744
744
# Manage autogrow annotation.
745
745
# Return size in Mebibytes.
746
746
manageAutogrowAnnotation() {
747
747
local volume=1ドル
748
748
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'}"
751
753
sizeInt="${size//M/}"
752
754
# 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:]]/}
754
756
triggerExpansion="$((useInt > 75))"
755
- if [ $ triggerExpansion -eq 1 ]; then
757
+ if [[ ${ triggerExpansion} -eq 1 ] ]; then
756
758
newSize="$(((sizeInt / 2)+sizeInt))"
757
759
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} "
760
762
fi
761
763
}
762
764
@@ -779,22 +781,22 @@ func TestAddServerToInstancePod(t *testing.T) {
779
781
fi
780
782
781
783
# manage autogrow annotation for the repo1 volume, if it exists
782
- if [ -d /pgbackrest/repo1 ]; then
784
+ if [[ -d /pgbackrest/repo1 ] ]; then
783
785
manageAutogrowAnnotation "repo1"
784
786
fi
785
787
786
788
# manage autogrow annotation for the repo2 volume, if it exists
787
- if [ -d /pgbackrest/repo2 ]; then
789
+ if [[ -d /pgbackrest/repo2 ] ]; then
788
790
manageAutogrowAnnotation "repo2"
789
791
fi
790
792
791
793
# manage autogrow annotation for the repo3 volume, if it exists
792
- if [ -d /pgbackrest/repo3 ]; then
794
+ if [[ -d /pgbackrest/repo3 ] ]; then
793
795
manageAutogrowAnnotation "repo3"
794
796
fi
795
797
796
798
# manage autogrow annotation for the repo4 volume, if it exists
797
- if [ -d /pgbackrest/repo4 ]; then
799
+ if [[ -d /pgbackrest/repo4 ] ]; then
798
800
manageAutogrowAnnotation "repo4"
799
801
fi
800
802
@@ -913,26 +915,28 @@ func TestAddServerToInstancePod(t *testing.T) {
913
915
# Parameters for curl when managing autogrow annotation.
914
916
APISERVER="https://kubernetes.default.svc"
915
917
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)
918
920
CACERT=${SERVICEACCOUNT}/ca.crt
919
921
920
922
# Manage autogrow annotation.
921
923
# Return size in Mebibytes.
922
924
manageAutogrowAnnotation() {
923
925
local volume=1ドル
924
926
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'}"
927
931
sizeInt="${size//M/}"
928
932
# 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:]]/}
930
934
triggerExpansion="$((useInt > 75))"
931
- if [ $ triggerExpansion -eq 1 ]; then
935
+ if [[ ${ triggerExpansion} -eq 1 ] ]; then
932
936
newSize="$(((sizeInt / 2)+sizeInt))"
933
937
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} "
936
940
fi
937
941
}
938
942
@@ -955,22 +959,22 @@ func TestAddServerToInstancePod(t *testing.T) {
955
959
fi
956
960
957
961
# manage autogrow annotation for the repo1 volume, if it exists
958
- if [ -d /pgbackrest/repo1 ]; then
962
+ if [[ -d /pgbackrest/repo1 ] ]; then
959
963
manageAutogrowAnnotation "repo1"
960
964
fi
961
965
962
966
# manage autogrow annotation for the repo2 volume, if it exists
963
- if [ -d /pgbackrest/repo2 ]; then
967
+ if [[ -d /pgbackrest/repo2 ] ]; then
964
968
manageAutogrowAnnotation "repo2"
965
969
fi
966
970
967
971
# manage autogrow annotation for the repo3 volume, if it exists
968
- if [ -d /pgbackrest/repo3 ]; then
972
+ if [[ -d /pgbackrest/repo3 ] ]; then
969
973
manageAutogrowAnnotation "repo3"
970
974
fi
971
975
972
976
# manage autogrow annotation for the repo4 volume, if it exists
973
- if [ -d /pgbackrest/repo4 ]; then
977
+ if [[ -d /pgbackrest/repo4 ] ]; then
974
978
manageAutogrowAnnotation "repo4"
975
979
fi
976
980
@@ -1078,26 +1082,28 @@ func TestAddServerToRepoPod(t *testing.T) {
1078
1082
# Parameters for curl when managing autogrow annotation.
1079
1083
APISERVER="https://kubernetes.default.svc"
1080
1084
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)
1083
1087
CACERT=${SERVICEACCOUNT}/ca.crt
1084
1088
1085
1089
# Manage autogrow annotation.
1086
1090
# Return size in Mebibytes.
1087
1091
manageAutogrowAnnotation() {
1088
1092
local volume=1ドル
1089
1093
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'}"
1092
1098
sizeInt="${size//M/}"
1093
1099
# 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:]]/}
1095
1101
triggerExpansion="$((useInt > 75))"
1096
- if [ $ triggerExpansion -eq 1 ]; then
1102
+ if [[ ${ triggerExpansion} -eq 1 ] ]; then
1097
1103
newSize="$(((sizeInt / 2)+sizeInt))"
1098
1104
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} "
1101
1107
fi
1102
1108
}
1103
1109
@@ -1120,22 +1126,22 @@ func TestAddServerToRepoPod(t *testing.T) {
1120
1126
fi
1121
1127
1122
1128
# manage autogrow annotation for the repo1 volume, if it exists
1123
- if [ -d /pgbackrest/repo1 ]; then
1129
+ if [[ -d /pgbackrest/repo1 ] ]; then
1124
1130
manageAutogrowAnnotation "repo1"
1125
1131
fi
1126
1132
1127
1133
# manage autogrow annotation for the repo2 volume, if it exists
1128
- if [ -d /pgbackrest/repo2 ]; then
1134
+ if [[ -d /pgbackrest/repo2 ] ]; then
1129
1135
manageAutogrowAnnotation "repo2"
1130
1136
fi
1131
1137
1132
1138
# manage autogrow annotation for the repo3 volume, if it exists
1133
- if [ -d /pgbackrest/repo3 ]; then
1139
+ if [[ -d /pgbackrest/repo3 ] ]; then
1134
1140
manageAutogrowAnnotation "repo3"
1135
1141
fi
1136
1142
1137
1143
# manage autogrow annotation for the repo4 volume, if it exists
1138
- if [ -d /pgbackrest/repo4 ]; then
1144
+ if [[ -d /pgbackrest/repo4 ] ]; then
1139
1145
manageAutogrowAnnotation "repo4"
1140
1146
fi
1141
1147
0 commit comments