Skip to content

Commit

Permalink
feat(deploy) use Job to run migrations for Kong
Browse files Browse the repository at this point in the history
Using InitContainer can result in two Kong nodes running migrations
concurrently.
Job is the right way to run migrations.

From #161
  • Loading branch information
hbagdi authored Oct 15, 2018
1 parent 647c94a commit 35e71c8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
9 changes: 0 additions & 9 deletions deploy/manifests/ingress-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ spec:
app: ingress-kong
spec:
serviceAccountName: kong-serviceaccount
initContainers:
- name: kong-migration
image: kong:0.14.1-centos
env:
- name: KONG_PG_PASSWORD
value: kong
- name: KONG_PG_HOST
value: postgres
command: [ "/bin/sh", "-c", "kong migrations up" ]
containers:
- name: admin-api
image: kong:0.14.1-centos
Expand Down
31 changes: 31 additions & 0 deletions deploy/manifests/migration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: batch/v1
kind: Job
metadata:
name: kong-migrations
namespace: kong
spec:
template:
metadata:
name: kong-migrations
spec:
initContainers:
- name: wait-for-postgres
image: busybox
env:
- name: KONG_PG_HOST
value: postgres
- name: KONG_PG_PORT
value: "5432"
command: [ "/bin/sh", "-c", "until nc -zv $KONG_PG_HOST $KONG_PG_PORT -w1; do echo 'waiting for db'; sleep 1; done" ]
containers:
- name: kong-migrations
image: kong:0.14.1-centos
env:
- name: KONG_PG_PASSWORD
value: kong
- name: KONG_PG_HOST
value: postgres
- name: KONG_PG_PORT
value: "5432"
command: [ "/bin/sh", "-c", "kong migrations up" ]
restartPolicy: OnFailure
42 changes: 32 additions & 10 deletions deploy/single/all-in-one-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,6 @@ spec:
app: ingress-kong
spec:
serviceAccountName: kong-serviceaccount
initContainers:
- name: kong-migration
image: kong:0.14.1-centos
env:
- name: KONG_PG_PASSWORD
value: kong
- name: KONG_PG_HOST
value: postgres
command: [ "/bin/sh", "-c", "kong migrations up" ]
containers:
- name: admin-api
image: kong:0.14.1-centos
Expand Down Expand Up @@ -419,7 +410,7 @@ metadata:
name: kong-proxy
namespace: kong
spec:
type: LoadBalancer
type: NodePort
ports:
- name: kong-proxy
port: 80
Expand Down Expand Up @@ -470,3 +461,34 @@ spec:
protocol: TCP

---
apiVersion: batch/v1
kind: Job
metadata:
name: kong-migrations
namespace: kong
spec:
template:
metadata:
name: kong-migrations
spec:
initContainers:
- name: wait-for-postgres
image: busybox
env:
- name: KONG_PG_HOST
value: postgres
- name: KONG_PG_PORT
value: "5432"
command: [ "/bin/sh", "-c", "until nc -zv $KONG_PG_HOST $KONG_PG_PORT -w1; do echo 'waiting for db'; sleep 1; done" ]
containers:
- name: kong-migrations
image: kong:0.14.1-centos
env:
- name: KONG_PG_PASSWORD
value: kong
- name: KONG_PG_HOST
value: postgres
- name: KONG_PG_PORT
value: "5432"
command: [ "/bin/sh", "-c", "kong migrations up" ]
restartPolicy: OnFailure
2 changes: 1 addition & 1 deletion hack/build-single-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -o pipefail

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..

WITH_POSTGRESQL="manifests/namespace.yaml manifests/custom-types.yaml manifests/postgres.yaml manifests/rbac.yaml manifests/ingress-controller.yaml provider/baremetal/kong-proxy-nodeport.yaml manifests/kong.yaml"
WITH_POSTGRESQL="manifests/namespace.yaml manifests/custom-types.yaml manifests/postgres.yaml manifests/rbac.yaml manifests/ingress-controller.yaml provider/baremetal/kong-proxy-nodeport.yaml manifests/kong.yaml manifests/migration.yaml"
MANIFEST=$(cd ${SCRIPT_ROOT}/deploy; cat ${WITH_POSTGRESQL})

echo "${MANIFEST}" > ${SCRIPT_ROOT}/deploy/single/all-in-one-postgres.yaml
Expand Down

0 comments on commit 35e71c8

Please sign in to comment.