Skip to content

Commit 4db41d3

Browse files
committed
fix: use Recreate strategy for snyk-monitor when using PVC as storage
When using a PersistentVolumeClaim, it has a Volume attached to it that can be shared by Pods only on the same worker node. On upgrades to the Deployment, Kubernetes assigns the new Pods to random Kubernetes worker nodes. If the new Pod is assigned to a different worker node, the PVC cannot be detached from the old Pod and assigned to the new Pod. This is why when we use a PVC we now change the snyk-monitor Deployment strategy to Recreate. Kubernetes will first delete the old Pod, freeing up the PVC, which can then be used in the new Pod.
1 parent 33a6486 commit 4db41d3

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

.circleci/config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,12 +535,24 @@ jobs:
535535
sleep $SLEEP_SECONDS_BETWEEN_ATTEMPTS
536536
done
537537
538+
SNYK_MONITOR_POD=$(kubectl get pods -n snyk-monitor --no-headers | \
539+
grep "snyk-monitor" | \
540+
awk 'END { if (NR==0) exit 1; else print $1 }')
541+
538542
# If we polled for 5 minutes and the snyk-monitor still hasn't upgraded, fail the current job.
539543
if [[ "${VERSION}" != "${LATEST_TAG}" ]]; then
540544
&>2 echo "versions (${VERSION}) does not match expected (${LATEST_TAG})!"
545+
546+
kubectl describe pod ${SNYK_MONITOR_POD} -n snyk-monitor
547+
kubectl describe catalogsource snyk-operator -n openshift-marketplace
548+
kubectl get snykmonitors.charts.helm.k8s.io -n snyk-monitor -o yaml
549+
541550
exit 1
542551
fi
543552
553+
# We need to wait for the Pod to become Ready
554+
kubectl wait pod/${SNYK_MONITOR_POD} -n snyk-monitor --timeout 120s --for condition=Ready
555+
544556
echo "Update complete!"
545557
name: Upgrade Operator and check that snyk-monitor also upgraded
546558
- run:

.circleci/config/jobs/operator_upgrade_tests.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,24 @@ steps:
190190
sleep $SLEEP_SECONDS_BETWEEN_ATTEMPTS
191191
done
192192
193+
SNYK_MONITOR_POD=$(kubectl get pods -n snyk-monitor --no-headers | \
194+
grep "snyk-monitor" | \
195+
awk 'END { if (NR==0) exit 1; else print $1 }')
196+
193197
# If we polled for 5 minutes and the snyk-monitor still hasn't upgraded, fail the current job.
194198
if [[ "${VERSION}" != "${LATEST_TAG}" ]]; then
195199
&>2 echo "versions (${VERSION}) does not match expected (${LATEST_TAG})!"
200+
201+
kubectl describe pod ${SNYK_MONITOR_POD} -n snyk-monitor
202+
kubectl describe catalogsource snyk-operator -n openshift-marketplace
203+
kubectl get snykmonitors.charts.helm.k8s.io -n snyk-monitor -o yaml
204+
196205
exit 1
197206
fi
198207
208+
# We need to wait for the Pod to become Ready
209+
kubectl wait pod/${SNYK_MONITOR_POD} -n snyk-monitor --timeout 120s --for condition=Ready
210+
199211
echo "Update complete!"
200212
201213
- run:

snyk-monitor/templates/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ metadata:
88
app.kubernetes.io/instance: {{ .Release.Name }}
99
app.kubernetes.io/managed-by: {{ .Release.Service }}
1010
spec:
11+
{{- if .Values.pvc.enabled }}
12+
strategy:
13+
type: Recreate
14+
{{- end }}
1115
selector:
1216
matchLabels:
1317
app.kubernetes.io/name: {{ include "snyk-monitor.name" . }}

0 commit comments

Comments
 (0)