Use strategic merge patch with restart annotation in deploy step
The JSON Patch was updating the deployment spec image but K8s wasn't creating new pods — the rollout was stuck from previous failed builds. Switch to strategic-merge-patch that also sets restartedAt annotation, equivalent to 'kubectl rollout restart', which forces K8s to create a new ReplicaSet regardless of stalled rollout state.
This commit is contained in:
parent
339e2cf2ab
commit
0a2b207bee
1 changed files with 37 additions and 6 deletions
43
.drone.yml
43
.drone.yml
|
|
@ -116,8 +116,24 @@ steps:
|
|||
depends_on:
|
||||
- publish-frontend-image
|
||||
commands:
|
||||
- apk add curl
|
||||
- 'curl -s -X PATCH "https://kubernetes:6443/apis/apps/v1/namespaces/realestate-crawler/deployments/realestate-crawler-ui" -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -H "Content-Type: application/json-patch+json" -k -d ''[{"op":"replace","path":"/spec/template/spec/containers/0/image","value":"viktorbarzin/immoweb:''"$DRONE_BUILD_NUMBER"''"}]'' | head'
|
||||
- apk add --no-cache curl jq
|
||||
- |
|
||||
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
||||
IMAGE="viktorbarzin/immoweb:${DRONE_BUILD_NUMBER}"
|
||||
RESTART_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
API="https://kubernetes:6443/apis/apps/v1/namespaces/realestate-crawler/deployments"
|
||||
DEPLOY="realestate-crawler-ui"
|
||||
|
||||
CONTAINER=$(curl -sfk "$API/$DEPLOY" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Accept: application/json" | jq -r '.spec.template.spec.containers[0].name')
|
||||
echo "Patching $DEPLOY (container=$CONTAINER) to image $IMAGE with restartedAt=$RESTART_AT..."
|
||||
|
||||
curl -sf -X PATCH "$API/$DEPLOY" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/strategic-merge-patch+json" \
|
||||
-k -d "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"kubectl.kubernetes.io/restartedAt\":\"$RESTART_AT\"}},\"spec\":{\"containers\":[{\"name\":\"$CONTAINER\",\"image\":\"$IMAGE\"}]}}}}" \
|
||||
| jq '{name: .metadata.name, generation: .metadata.generation, image: .spec.template.spec.containers[0].image}'
|
||||
|
||||
- name: verify-deploy
|
||||
image: alpine
|
||||
|
|
@ -269,10 +285,25 @@ steps:
|
|||
depends_on:
|
||||
- publish-api-image
|
||||
commands:
|
||||
- apk add curl
|
||||
- 'curl -s -X PATCH "https://kubernetes:6443/apis/apps/v1/namespaces/realestate-crawler/deployments/realestate-crawler-api" -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -H "Content-Type: application/json-patch+json" -k -d ''[{"op":"replace","path":"/spec/template/spec/containers/0/image","value":"viktorbarzin/realestatecrawler:''"$DRONE_BUILD_NUMBER"''"}]'' | head'
|
||||
- 'curl -s -X PATCH "https://kubernetes:6443/apis/apps/v1/namespaces/realestate-crawler/deployments/realestate-crawler-celery" -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -H "Content-Type: application/json-patch+json" -k -d ''[{"op":"replace","path":"/spec/template/spec/containers/0/image","value":"viktorbarzin/realestatecrawler:''"$DRONE_BUILD_NUMBER"''"}]'' | head'
|
||||
- 'curl -s -X PATCH "https://kubernetes:6443/apis/apps/v1/namespaces/realestate-crawler/deployments/realestate-crawler-celery-beat" -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" -H "Content-Type: application/json-patch+json" -k -d ''[{"op":"replace","path":"/spec/template/spec/containers/0/image","value":"viktorbarzin/realestatecrawler:''"$DRONE_BUILD_NUMBER"''"}]'' | head'
|
||||
- apk add --no-cache curl jq
|
||||
- |
|
||||
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
||||
IMAGE="viktorbarzin/realestatecrawler:${DRONE_BUILD_NUMBER}"
|
||||
RESTART_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
API="https://kubernetes:6443/apis/apps/v1/namespaces/realestate-crawler/deployments"
|
||||
|
||||
for DEPLOY in realestate-crawler-api realestate-crawler-celery realestate-crawler-celery-beat; do
|
||||
CONTAINER=$(curl -sfk "$API/$DEPLOY" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Accept: application/json" | jq -r '.spec.template.spec.containers[0].name')
|
||||
echo "Patching $DEPLOY (container=$CONTAINER) to image $IMAGE with restartedAt=$RESTART_AT..."
|
||||
|
||||
curl -sf -X PATCH "$API/$DEPLOY" \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Content-Type: application/strategic-merge-patch+json" \
|
||||
-k -d "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"kubectl.kubernetes.io/restartedAt\":\"$RESTART_AT\"}},\"spec\":{\"containers\":[{\"name\":\"$CONTAINER\",\"image\":\"$IMAGE\"}]}}}}" \
|
||||
| jq '{name: .metadata.name, generation: .metadata.generation, image: .spec.template.spec.containers[0].image}'
|
||||
done
|
||||
|
||||
- name: verify-deploy
|
||||
image: alpine
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue