Skip to content

Commit

Permalink
feat(setup): check if pvcs can be created automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
aboguszewski-sumo committed Oct 10, 2023
1 parent 35e73e3 commit 6187cab
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions deploy/helm/sumologic/conf/setup/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,58 @@

readonly DEBUG_MODE=${DEBUG_MODE:="false"}
readonly DEBUG_MODE_ENABLED_FLAG="true"
readonly TEST_PVC_FILE="test-pvc-ss.yaml"
readonly TEST_PVC_STATEFULSET="pvc-nginx"
readonly TEST_PVC_NAMESPACE="test-pvc"
readonly TEST_PVC_STATEFULSET_CONFIG="apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
ports:
- port: 80
name: web
clusterIP: None
selector:
app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web
spec:
selector:
matchLabels:
app: nginx
serviceName: \"nginx\"
replicas: 1
minReadySeconds: 10 # by default is 0
template:
metadata:
labels:
app: nginx
spec:
terminationGracePeriodSeconds: 10
containers:
- name: nginx
image: registry.k8s.io/nginx-slim:0.8
ports:
- containerPort: 80
name: web
volumeMounts:
- name: www
mountPath: /usr/share/nginx/html
volumeClaimTemplates:
- metadata:
name: www
spec:
accessModes: [ \"ReadWriteOnce\" ]
resources:
requests:
storage: 1Gi
"

# Let's compare the variables ignoring the case with help of ${VARIABLE,,} which makes the string lowercased
# so that we don't have to deal with True vs true vs TRUE
Expand Down Expand Up @@ -83,6 +135,52 @@ function should_create_fields() {
fi
}

function pvc_test_create_statefulset() {
kubectl create namespace ${TEST_PVC_NAMESPACE}
echo "${TEST_PVC_STATEFULSET_CONFIG}" > ${TEST_PVC_FILE}

kubectl -n ${TEST_PVC_NAMESPACE} apply -f ${TEST_PVC_FILE}
if [[ $? -eq 0 ]]; then
return 0
else
echo "Creating statefulset failed"
pvc_test_cleanup
exit 1
fi
}

function pvc_test_check() {
local pending_pvcs
pending_pvcs=$(kubectl -n ${TEST_PVC_NAMESPACE} get pvc | grep -c "Pending")
readonly pending_pvcs

if [[ $? -ne 0 ]]; then
echo "Querying pvcs failed"
exit 1
else
return $pending_pvcs
fi
}

function pvc_test_cleanup() {
kubectl delete all --all -n ${TEST_PVC_NAMESPACE}
kubectl delete pvc --all -n ${TEST_PVC_NAMESPACE}
rm ${TEST_PVC_FILE}
}

function can_create_pvc() {
pvc_test_create_statefulset
sleep 30
pvc_test_check
if [[ $? -ne 0 ]]; then
echo "PVC could not be created automatically"
exit 1
else
echo "PVC can be created automatically"
return 0
fi
}

cp /etc/terraform/{locals,main,providers,resources,variables,fields}.tf /terraform/
cd /terraform || exit 1

Expand Down Expand Up @@ -176,3 +274,8 @@ export SUMOLOGIC_ACCESSKEY=
export SUMOLOGIC_ACCESSID=

bash /etc/terraform/custom.sh

{{- if (or .Values.metadata.persistence.enabled (or .Values.sumologic.events.persistence.enabled .Values.sumologic.logs.collector.otelcloudwatch.persistence.enabled)) }}
can_create_pvc
pvc_test_cleanup > /dev/null
{{- end }}

0 comments on commit 6187cab

Please sign in to comment.