|
| 1 | +{{/* |
| 2 | +CUBE file storage |
| 3 | +-------------------------------------------------------------------------------- |
| 4 | +In the default configuration, pfcon is configured as "innetwork" and CUBE uses |
| 5 | +the volume managed by the pfcon subchart for file storage. |
| 6 | +If pfcon is not enabled or not configured as "innetwork" then CUBE needs to create |
| 7 | +its own PVC. |
| 8 | +*/}} |
| 9 | + |
| 10 | +{{- define "cube.useOwnVolume" -}} |
| 11 | +{{- if (and .Values.pfcon.enabled .Values.pfcon.pfcon.config.innetwork) -}} |
| 12 | +{{- /* no (empty value) */ -}} |
| 13 | +{{- else -}} |
| 14 | +yes |
| 15 | +{{- end }} |
| 16 | +{{- end }} |
| 17 | + |
| 18 | +{{- define "cube.wasUsingOwnVolume" -}} |
| 19 | +{{- with (lookup "v1" "PersistentVolumeClaim" .Release.Namespace ( print .Release.Name "-cube-files")) -}} |
| 20 | +yes |
| 21 | +{{- end -}} |
| 22 | +{{- end -}} |
| 23 | + |
| 24 | +{{- define "cube.filesVolume" -}} |
| 25 | +{{- /* |
| 26 | + Validators to check that you aren't self-destructive. |
| 27 | +
|
| 28 | + You should never: |
| 29 | + - enable "innetwork pfcon" where previously it wasn't |
| 30 | + - disable "innetwork pfcon" where it previously was |
| 31 | +*/ -}} |
| 32 | +{{- if (and .Release.IsUpgrade (eq "yes" (include "cube.wasUsingOwnVolume" .)) (ne "yes" (include "cube.useOwnVolume" .))) -}} |
| 33 | +{{- fail "Cannot set pfcon.enabled=true and/or pfcon.pfcon.config.innetwork=true now because CUBE is using its own PersistentVolumeClaim for storage." -}} |
| 34 | +{{- else if (and .Release.IsUpgrade (ne "yes" (include "cube.wasUsingOwnVolume" .)) (eq "yes" (include "cube.useOwnVolume" .))) -}} |
| 35 | +{{- fail "Cannot set pfcon.enabled=false and/or pfcon.pfcon.config.innetwork=false now because CUBE currently depends on pfcon configured in \"innetwork\" mode for storage." -}} |
| 36 | +{{- else if (include "cube.useOwnVolume" .) -}} |
| 37 | +{{- /* will be created by ./storage.yml */ -}} |
| 38 | +{{ .Release.Name }}-cube-files |
| 39 | +{{- else -}} |
| 40 | +{{- /* defined in ../../pfcon/templates/storage.yml */ -}} |
| 41 | +{{ .Release.Name }}-storebase |
| 42 | +{{- end }} |
| 43 | +{{- end }} |
| 44 | + |
| 45 | +{{- define "cube.db.secret" -}} |
| 46 | +{{- if .Values.postgresSecret.name -}} |
| 47 | +{{- .Values.postgresSecret.name -}} |
| 48 | +{{- else if .Values.postgresql.enabled -}} |
| 49 | +{{ .Release.Name }}-postgresql-svcbind-custom-user |
| 50 | +{{- else -}} |
| 51 | +{{- fail "postgresSecret.name cannot be unset because postgresql.enabled=false" -}} |
| 52 | +{{- end -}} |
| 53 | +{{- end -}} |
| 54 | + |
| 55 | +{{- define "cube.image" -}} |
| 56 | +{{ .Values.cube.image.repository }}:{{ .Values.cube.image.tag | default .Chart.AppVersion }} |
| 57 | +{{- end -}} |
| 58 | +{{- define "cube.container" -}} |
| 59 | +image: {{ include "cube.image" . }} |
| 60 | +imagePullPolicy: {{ .Values.cube.image.pullPolicy }} |
| 61 | +volumeMounts: |
| 62 | + - mountPath: /data |
| 63 | + name: file-storage |
| 64 | +envFrom: |
| 65 | + - configMapRef: |
| 66 | + name: {{ .Release.Name }}-cube-config |
| 67 | + - secretRef: |
| 68 | + name: {{ .Release.Name }}-chris-backend |
| 69 | +env: |
| 70 | + {{- $dbenvs := (dict |
| 71 | + "POSTGRES_DB" (include "chris.db.secretItemKey" (dict "Values" .Values "name" "database" "crunchyName" "dbname")) |
| 72 | + "POSTGRES_USER" (include "chris.db.secretItemKey" (dict "Values" .Values "name" "username" "crunchyName" "user")) |
| 73 | + "POSTGRES_PASSWORD" (include "chris.db.secretItemKey" (dict "Values" .Values "name" "password" "crunchyName" "password")) |
| 74 | + "DATABASE_HOST" (include "chris.db.secretItemKey" (dict "Values" .Values "name" "host" "crunchyName" "host")) |
| 75 | + "DATABASE_PORT" (include "chris.db.secretItemKey" (dict "Values" .Values "name" "port" "crunchyName" "port")) |
| 76 | + ) }} |
| 77 | + {{- $secretName := include "cube.db.secret" . }} |
| 78 | + {{- range $name, $key := $dbenvs }} |
| 79 | + - name: {{ $name }} |
| 80 | + valueFrom: |
| 81 | + secretKeyRef: |
| 82 | + name: {{ $secretName }} |
| 83 | + key: {{ $key }} |
| 84 | + {{- end }} |
| 85 | + - name: CELERY_BROKER_URL |
| 86 | + valueFrom: |
| 87 | + secretKeyRef: |
| 88 | + name: {{ .Release.Name }}-rabbitmq-svcbind |
| 89 | + key: uri |
| 90 | + {{- range $name, $val := .moreEnv }} |
| 91 | + - name: {{ $name }} |
| 92 | + valueFrom: |
| 93 | + {{ get $val "valueFrom" }}: |
| 94 | + name: {{ get $val "name" }} |
| 95 | + key: {{ get $val "key" }} |
| 96 | + {{- end }} |
| 97 | +{{- end }} |
| 98 | + |
| 99 | +{{- /* Helper function to get the name of an item of a key. If unspecified in Values, use a default name |
| 100 | + where the default may be different for Crunchy PGO. */}} |
| 101 | +{{- define "chris.db.secretItemKey" }} |
| 102 | +{{- get .Values.postgresSecret.keys .name | default (ternary .crunchyName .name .Values.postgresSecret.isCrunchy) -}} |
| 103 | +{{- end }} |
| 104 | + |
| 105 | +{{- define "cube.pod" -}} |
| 106 | +volumes: |
| 107 | + - name: file-storage |
| 108 | + persistentVolumeClaim: |
| 109 | + claimName: {{ include "cube.filesVolume" . }} |
| 110 | +{{- if .Values.global.podSecurityContext }} |
| 111 | +securityContext: |
| 112 | + {{- toYaml .Values.global.podSecurityContext | nindent 2 }} |
| 113 | +{{- end }} |
| 114 | +{{- end }} |
| 115 | + |
| 116 | +{{- define "cube.podAffinityWorkaround" -}} |
| 117 | +{{ if .Values.cube.enablePodAffinityWorkaround }} |
| 118 | +affinity: |
| 119 | + podAffinity: |
| 120 | + requiredDuringSchedulingIgnoredDuringExecution: |
| 121 | + - labelSelector: |
| 122 | + matchExpressions: |
| 123 | + - key: app.kubernetes.io/instance |
| 124 | + operator: In |
| 125 | + values: |
| 126 | + - {{ .Release.Name }} |
| 127 | + {{- /* if CUBE is using its own volume, pods should be attracted to heart. Otherwise, pods should be attracted to pfcon. */}} |
| 128 | + - key: app.kubernetes.io/name |
| 129 | + operator: In |
| 130 | + values: |
| 131 | + - {{ if (include "cube.useOwnVolume" .) }}{{ include "chris.heart.appName" . }}{{ else }}pfcon{{ end }} |
| 132 | + topologyKey: kubernetes.io/hostname |
| 133 | +{{- end }} |
| 134 | +{{- end }} |
| 135 | + |
| 136 | +{{- /* |
| 137 | +Since the server deployment is the one which defines the database migrations, everything else |
| 138 | +should start after the server. It's ok for ancillary services to be started late. |
| 139 | +*/ -}} |
| 140 | +{{- define "cube.waitServerReady" -}} |
| 141 | +- name: wait-for-server |
| 142 | + image: quay.io/prometheus/busybox:latest |
| 143 | + command: ["/bin/sh", "-c"] |
| 144 | + args: ["until wget --spider 'http://{{ include "chris.heart.name" . }}:{{ include "chris.heart.port" . }}/api/v1/users/'; do sleep 5; done"] |
| 145 | +{{- end }} |
| 146 | + |
0 commit comments