Skip to content

Commit 361c54e

Browse files
author
PJEstrada
authored
Merge pull request #3 from diffgram/improve-azure-install
Improve data validations for installs on azure
2 parents e9b244a + a047c9e commit 361c54e

13 files changed

+63
-64
lines changed

templates/default/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ spec:
2020
- name: diffgramsecret
2121
{{ end }}
2222
volumes:
23+
{{ if eq .Values.diffgramSettings.DIFFGRAM_STATIC_STORAGE_PROVIDER "gcp"}}
2324
- name: service-account-credentials-volume
2425
secret:
2526
secretName: gcp-service-account-credentials
2627
items:
2728
- key: sa_json
2829
path: sa_credentials.json
30+
{{ end }}
2931
initContainers:
3032
- name: check-db-ready
3133
image: postgres:9.6.5
@@ -51,10 +53,12 @@ spec:
5153
name: diffgram-default
5254
ports:
5355
- containerPort: 8080
56+
{{ if eq .Values.diffgramSettings.DIFFGRAM_STATIC_STORAGE_PROVIDER "gcp"}}
5457
volumeMounts:
5558
- name: service-account-credentials-volume
5659
mountPath: /etc/gcp
5760
readOnly: true
61+
{{ end }}
5862
envFrom:
5963
- configMapRef:
6064
name: diffgram-default-configmap

templates/hooks/configmap_db_migrations.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: ConfigMap
33
metadata:
44
annotations:
55
"helm.sh/hook": pre-install,pre-upgrade, pre-rollback
6-
"helm.sh/hook-weight": "1" # we use a smaller weight so it's created before the job
6+
"helm.sh/hook-weight": "-3" # we use a smaller weight so it's created before the job
77
"helm.sh/hook-delete-policy": before-hook-creation, hook-succeeded
88
name: db-migrations-configmap
99
data:

templates/hooks/database_pre_install.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ spec:
2828
- name: db-migrations-pull-secret
2929
{{ end }}
3030
volumes:
31+
{{ if eq .Values.diffgramSettings.DIFFGRAM_STATIC_STORAGE_PROVIDER "gcp"}}
3132
- name: service-account-credentials-volume-hook
3233
secret:
3334
secretName: gcp-service-account-credentials-hook
3435
items:
3536
- key: sa_json
3637
path: sa_credentials.json
38+
{{ end }}
39+
- name: postgres-storage
40+
persistentVolumeClaim:
41+
claimName: postgres-pv-claim
3742
containers:
3843
{{ if eq .Values.diffgramEdition "enterprise"}}
3944
- image: gcr.io/diffgram-enterprise/default:{{ .Values.diffgramVersion }}
@@ -43,14 +48,16 @@ spec:
4348
{{ end }}
4449
imagePullPolicy: Always
4550
name: pre-upgrade-alembic-hook
51+
{{ if eq .Values.diffgramSettings.DIFFGRAM_STATIC_STORAGE_PROVIDER "gcp"}}
4652
volumeMounts:
47-
- name: service-account-credentials-volume-hook
53+
- name: service-account-credentials-volume
4854
mountPath: /etc/gcp
4955
readOnly: true
56+
{{ end }}
5057
envFrom:
5158
- configMapRef:
5259
name: db-migrations-configmap
5360
- secretRef:
5461
name: db-migrations-secret
5562
# The actual migrations command
56-
command: ["sh","-c", "cd shared; export PYTHONPATH=/app; pip install sqlalchemy-utils==0.36.6;python /app/play_and_scripts/scripts/create_database.py; alembic upgrade head"]
63+
command: ["sh","-c", "cd shared; export PYTHONPATH=/app; pip install sqlalchemy-utils==0.36.6;python /app/play_and_scripts/scripts/create_database.py; alembic upgrade head"]

templates/hooks/db_service_migrations.yaml

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -40,52 +40,6 @@ spec:
4040
status:
4141
loadBalancer: {}
4242
{{ end }}
43-
44-
{{ if eq .Values.dbSettings.dbProvider "local"}}
45-
apiVersion: "apps/v1"
46-
kind: "Deployment"
47-
metadata:
48-
annotations:
49-
# This is what defines this resource as a hook. Without this line, the
50-
# job is considered part of the release.
51-
"helm.sh/hook": pre-install, pre-upgrade, pre-rollback
52-
"helm.sh/hook-weight": "0"
53-
"helm.sh/hook-delete-policy": before-hook-creation, hook-succeeded
54-
name: "postgres-hook"
55-
namespace: "default"
56-
labels:
57-
app: "postgres-hook"
58-
spec:
59-
replicas: 1
60-
selector:
61-
matchLabels:
62-
app: "postgres"
63-
template:
64-
metadata:
65-
labels:
66-
app: "postgres"
67-
spec:
68-
containers:
69-
- name: "postgres"
70-
image: "postgres:9.6.2"
71-
env:
72-
- name: "POSTGRES_DB"
73-
value: {{ .Values.dbSettings.dbName }}
74-
- name: "POSTGRES_USER"
75-
value: {{ .Values.dbSettings.dbUser }}
76-
- name: "POSTGRES_PASSWORD"
77-
value: {{ .Values.dbSettings.dbPassword }}
78-
ports:
79-
- containerPort: 5432
80-
name: postgres
81-
volumeMounts:
82-
- name: postgres-storage
83-
mountPath: /var/lib/postgresql/db-data
84-
volumes:
85-
- name: postgres-storage
86-
persistentVolumeClaim:
87-
claimName: postgres-pv-claim
88-
{{ end }}
8943
{{ if eq .Values.dbSettings.dbProvider "local"}}
9044
apiVersion: v1
9145
kind: Service
@@ -94,12 +48,12 @@ metadata:
9448
# This is what defines this resource as a hook. Without this line, the
9549
# job is considered part of the release.
9650
"helm.sh/hook": pre-install, pre-upgrade, pre-rollback
97-
"helm.sh/hook-weight": "0"
51+
"helm.sh/hook-weight": "1"
9852
"helm.sh/hook-delete-policy": before-hook-creation, hook-succeeded
9953
name: diffgram-postgres-hook
10054
spec:
10155
ports:
10256
- port: 5432
10357
selector:
104-
app: diffgram-postgres-hook
58+
app: postgres
10559
{{ end }}

templates/hooks/secret_gcp_service_account_hook.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{ if eq .Values.diffgramSettings.DIFFGRAM_STATIC_STORAGE_PROVIDER "gcp"}}
12
apiVersion: v1
23
kind: Secret
34
metadata:
@@ -9,4 +10,5 @@ metadata:
910
type: Opaque
1011
data:
1112
# This is the JSON file encoded in base64. It will be mounted as a volume on the container.
12-
sa_json: {{ .Values.diffgramSecrets.SERVICE_ACCOUNT_JSON_B64 }}
13+
sa_json: {{ .Values.diffgramSecrets.SERVICE_ACCOUNT_JSON_B64 }}
14+
{{ end }}

templates/hooks/secret_gcr_db_migrations.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{ if eq .Values.diffgramEdition "enterprise"}}
12
apiVersion: v1
23
data:
34
.dockerconfigjson: {{ .Values.imagePullCredentials.gcrCredentials }}
@@ -21,3 +22,4 @@ metadata:
2122
name: db-migrations-pull-secret
2223
namespace: default
2324
type: kubernetes.io/dockerconfigjson
25+
{{ end }}

templates/hooks/secrets_db_migrations.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: Secret
44
metadata:
55
annotations:
66
"helm.sh/hook": pre-install, pre-upgrade, pre-rollback
7-
"helm.sh/hook-weight": "1"
7+
"helm.sh/hook-weight": "-3"
88
"helm.sh/hook-delete-policy": before-hook-creation, hook-succeeded
99
name: db-migrations-secret
1010
type: Opaque
@@ -17,7 +17,7 @@ stringData:
1717
SECRET_KEY: {{ .Values.diffgramSecrets.SECRET_KEY }}
1818
INTER_SERVICE_SECRET: {{ .Values.diffgramSecrets.INTER_SERVICE_SECRET }}
1919
{{ if eq .Values.dbSettings.dbProvider "local"}}
20-
DATABASE_URL: "postgresql+psycopg2://{{ .Values.dbSettings.dbUser }}:{{ .Values.dbSettings.dbPassword }}@diffgram-postgres/{{ .Values.dbSettings.dbName }}"
20+
DATABASE_URL: "postgresql+psycopg2://{{ .Values.dbSettings.dbUser }}:{{ .Values.dbSettings.dbPassword }}@diffgram-postgres-hook/{{ .Values.dbSettings.dbName }}"
2121
{{ end }}
2222
{{ if eq .Values.dbSettings.dbProvider "rds"}}
2323
DATABASE_URL: "postgresql+psycopg2://{{ .Values.dbSettings.dbUser }}:{{ .Values.dbSettings.dbPassword }}@{{ .Values.dbSettings.rdsEndpoint }}/{{ .Values.dbSettings.dbName }}"
@@ -26,4 +26,4 @@ stringData:
2626
DATABASE_URL: "postgresql+psycopg2://{{ .Values.dbSettings.dbUser }}:{{ .Values.dbSettings.dbPassword }}@{{ .Values.dbSettings.azureSqlEndpoint }}/{{ .Values.dbSettings.dbName }}"
2727
{{ end }}
2828
USER_PASSWORDS_SECRET: {{ .Values.diffgramSecrets.USER_PASSWORDS_SECRET }}
29-
DIFFGRAM_AZURE_CONNECTION_STRING: {{ .Values.diffgramSecrets.DIFFGRAM_AZURE_CONNECTION_STRING }}
29+
DIFFGRAM_AZURE_CONNECTION_STRING: {{ .Values.diffgramSecrets.DIFFGRAM_AZURE_CONNECTION_STRING }}

templates/postgres/deployment.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
{{ if eq .Values.dbSettings.dbProvider "local"}}
1+
{{- $postgresdeploy := (lookup "apps/v1" "Deployment" .Release.Namespace (printf "postgres")) }}
2+
{{ if eq .Values.dbSettings.dbProvider "local" }}
3+
{{ if not $postgresdeploy }}
24
apiVersion: "apps/v1"
35
kind: "Deployment"
46
metadata:
57
name: "postgres"
68
namespace: "default"
79
labels:
810
app: "postgres"
11+
annotations:
12+
# This is what defines this resource as a hook. Without this line, the
13+
# job is considered part of the release.
14+
"helm.sh/hook": pre-install
15+
"helm.sh/hook-weight": "-3"
16+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
917
spec:
1018
replicas: 1
1119
selector:
@@ -36,4 +44,5 @@ spec:
3644
- name: postgres-storage
3745
persistentVolumeClaim:
3846
claimName: postgres-pv-claim
47+
{{ end }}
3948
{{ end }}

templates/postgres/volumeclaim.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
{{- $mypvc := (lookup "v1" "PersistentVolumeClaim" .Release.Namespace (printf "postgres-pv-claim")) }}
2+
{{ if eq .Values.dbSettings.dbProvider "local" }}
3+
{{ if not $mypvc}}
14
apiVersion: v1
25
kind: PersistentVolumeClaim
36
metadata:
47
name: postgres-pv-claim
8+
annotations:
9+
"helm.sh/resource-policy": keep
10+
"helm.sh/hook": "pre-install"
11+
"helm.sh/hook-weight": "-5"
512
spec:
613
accessModes:
7-
- ReadWriteOnce
14+
- ReadWriteOnce
815
resources:
916
requests:
10-
storage: {{ .Values.dbSettings.storageAmount }}
17+
storage: {{ .Values.dbSettings.storageAmount }}
18+
{{ end }}
19+
{{ end }}

templates/secret-gcr.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{ if eq .Values.diffgramEdition "enterprise"}}
12
apiVersion: v1
23
data:
34
.dockerconfigjson: {{ .Values.imagePullCredentials.gcrCredentials }}
@@ -16,3 +17,4 @@ metadata:
1617
name: diffgramsecret
1718
namespace: default
1819
type: kubernetes.io/dockerconfigjson
20+
{{ end }}

0 commit comments

Comments
 (0)