|
| 1 | +## Copyright (c) 2024, 2025, Oracle and/or its affiliates. |
| 2 | +## Licensed under the Universal Permissive License v1.0 as shown at http://oss.oracle.com/licenses/upl. |
| 3 | +# spell-checker: ignore nindent freepdb1 oserror selectai sidb spfile sqlplus |
| 4 | +# spell-checker: ignore sqlcode sqlerror varchar nolog ptype sysdba tablespace tblspace |
| 5 | + |
| 6 | +# This file consolidates database-related Kubernetes resources: |
| 7 | +# - Secrets (auth, priv, wallet) |
| 8 | +# - Deployment (SIDB-FREE, ADB-FREE) |
| 9 | +# - Job (database initialization) |
| 10 | +# - AutonomousDatabase (ADB-S operator) |
| 11 | +# |
| 12 | +# Note: ConfigMap (initialization scripts) is now in db-configmap.yaml |
| 13 | + |
| 14 | +{{- if .Values.server.database }} |
| 15 | + |
| 16 | +--- |
| 17 | +# Database Authentication Secret |
| 18 | +{{- include "server.database.validateOtherType" . }} |
| 19 | +{{- $secretName := include "server.databaseSecret" . }} |
| 20 | +{{- $secret_existing := lookup "v1" "Secret" .Release.Namespace $secretName }} |
| 21 | +{{- if not $secret_existing }} |
| 22 | +apiVersion: v1 |
| 23 | +kind: Secret |
| 24 | +metadata: |
| 25 | + name: {{ $secretName }} |
| 26 | + labels: |
| 27 | + app.kubernetes.io/component: database |
| 28 | + {{- include "global.labels" . | nindent 4 }} |
| 29 | + annotations: |
| 30 | + helm.sh/resource-policy: keep |
| 31 | +type: Opaque |
| 32 | +stringData: |
| 33 | + username: "AI_OPTIMIZER" |
| 34 | + password: {{ include "server.randomPassword" . | quote }} |
| 35 | + {{- if eq (include "server.database.isSIDB" .) "true" }} |
| 36 | + service: "{{ .Release.Name }}-{{ include "server.database.shortType" . }}-1521:1521/FREEPDB1" |
| 37 | + {{- else if eq (include "server.database.isADBFree" .) "true" }} |
| 38 | + service: "{{ .Release.Name }}-{{ include "server.database.shortType" . }}-1521:1521/FREEPDB1" |
| 39 | + {{- else if eq (include "server.database.isOther" .) "true" }} |
| 40 | + {{- if and .Values.server.database.other.dsn (ne (.Values.server.database.other.dsn | trim) "") }} |
| 41 | + service: "{{ .Values.server.database.other.dsn }}" |
| 42 | + {{- else }} |
| 43 | + service: "{{ .Values.server.database.other.host }}:{{ .Values.server.database.other.port }}/{{ .Values.server.database.other.service_name }}" |
| 44 | + {{- end }} |
| 45 | + {{- end }} |
| 46 | +{{- end }} |
| 47 | + |
| 48 | +--- |
| 49 | +# Database Privileged User Secret |
| 50 | +{{- $secretName := include "server.databasePrivSecret" . }} |
| 51 | +{{- $secret_existing := lookup "v1" "Secret" .Release.Namespace $secretName }} |
| 52 | +{{- if not $secret_existing }} |
| 53 | +apiVersion: v1 |
| 54 | +kind: Secret |
| 55 | +metadata: |
| 56 | + name: {{ $secretName }} |
| 57 | + labels: |
| 58 | + app.kubernetes.io/component: database |
| 59 | + {{- include "global.labels" . | nindent 4 }} |
| 60 | + annotations: |
| 61 | + helm.sh/resource-policy: keep |
| 62 | +type: Opaque |
| 63 | +stringData: |
| 64 | + username: {{ if eq (include "server.database.isADB" .) "true" }}"ADMIN"{{ else }}"SYSTEM"{{ end }} |
| 65 | + password: {{ include "server.randomPassword" . | quote }} |
| 66 | +{{- end }} |
| 67 | + |
| 68 | +{{- if eq (include "server.database.isADBS" .) "true" }} |
| 69 | +--- |
| 70 | +# ADB Wallet Password Secret |
| 71 | +apiVersion: v1 |
| 72 | +kind: Secret |
| 73 | +metadata: |
| 74 | + name: {{ .Release.Name }}-adb-wallet-pass-{{ .Release.Revision }} |
| 75 | + labels: |
| 76 | + app.kubernetes.io/component: database |
| 77 | + {{- include "global.labels" . | nindent 4 }} |
| 78 | +stringData: |
| 79 | + {{ .Release.Name }}-adb-wallet-pass-{{ .Release.Revision }}: {{ include "server.randomPassword" . | quote }} |
| 80 | +{{- end }} |
| 81 | + |
| 82 | +{{- if eq (include "server.database.isContainerDB" .) "true" }} |
| 83 | +--- |
| 84 | +# Database Deployment (SIDB-FREE or ADB-FREE) |
| 85 | +apiVersion: apps/v1 |
| 86 | +kind: Deployment |
| 87 | +metadata: |
| 88 | + name: {{ include "global.fullname" . }}-{{ include "server.database.shortType" . }} |
| 89 | + labels: |
| 90 | + app.kubernetes.io/component: database |
| 91 | + {{- include "global.labels" . | nindent 4}} |
| 92 | +spec: |
| 93 | + replicas: 1 |
| 94 | + selector: |
| 95 | + matchLabels: |
| 96 | + app.kubernetes.io/component: database |
| 97 | + {{- include "global.selectorLabels" . | nindent 6 }} |
| 98 | + template: |
| 99 | + metadata: |
| 100 | + {{- with .Values.server.podAnnotations }} |
| 101 | + annotations: |
| 102 | + {{- toYaml . | nindent 8 }} |
| 103 | + {{- end }} |
| 104 | + labels: |
| 105 | + app.kubernetes.io/component: database |
| 106 | + {{- include "global.labels" . | nindent 8 }} |
| 107 | + {{- with .Values.server.podLabels }} |
| 108 | + {{- toYaml . | nindent 8 }} |
| 109 | + {{- end }} |
| 110 | + spec: |
| 111 | + securityContext: |
| 112 | + fsGroup: 54321 |
| 113 | + runAsGroup: 54321 |
| 114 | + runAsUser: 54321 |
| 115 | + containers: |
| 116 | + - name: db-container |
| 117 | + image: {{ .Values.server.database.image.repository }}:{{ .Values.server.database.image.tag }} |
| 118 | + imagePullPolicy: {{ .Values.server.database.image.pullPolicy | default "IfNotPresent" }} |
| 119 | + ports: |
| 120 | + - containerPort: 1521 |
| 121 | + readinessProbe: |
| 122 | + tcpSocket: |
| 123 | + port: 1521 |
| 124 | + initialDelaySeconds: 60 |
| 125 | + periodSeconds: 10 |
| 126 | + env: |
| 127 | + {{- include "server.database.authN" . | nindent 12 }} |
| 128 | + {{- if eq (include "server.database.isSIDB" .) "true" }} |
| 129 | + - name: ORACLE_PWD |
| 130 | + valueFrom: |
| 131 | + secretKeyRef: |
| 132 | + name: {{ include "server.databaseSecret" . }} |
| 133 | + key: {{ default "password" .Values.server.database.authN.passwordKey }} |
| 134 | + volumeMounts: |
| 135 | + - name: db-init-scripts |
| 136 | + mountPath: "/opt/oracle/scripts/startup" |
| 137 | + {{- else }} |
| 138 | + - name: DATABASE_NAME |
| 139 | + value: FREEPDB1 |
| 140 | + - name: ENABLE_ARCHIVE_LOG |
| 141 | + value: "False" |
| 142 | + - name: ADMIN_PASSWORD |
| 143 | + valueFrom: |
| 144 | + secretKeyRef: |
| 145 | + name: {{ include "server.databasePrivSecret" . }} |
| 146 | + key: {{ default "password" .Values.server.database.privAuthN.passwordKey }} |
| 147 | + - name: WALLET_PASSWORD |
| 148 | + valueFrom: |
| 149 | + secretKeyRef: |
| 150 | + name: {{ include "server.databaseSecret" . }} |
| 151 | + key: {{ default "password" .Values.server.database.authN.passwordKey }} |
| 152 | + {{- end }} |
| 153 | + {{- if eq (include "server.database.isSIDB" .) "true" }} |
| 154 | + volumes: |
| 155 | + - name: db-init-scripts |
| 156 | + configMap: |
| 157 | + name: {{ include "global.fullname" . }}-db-init |
| 158 | + {{- end }} |
| 159 | +{{- end }} |
| 160 | + |
| 161 | +{{- if .Values.server.database.privAuthN }} |
| 162 | +--- |
| 163 | +# Database Initialization Job |
| 164 | +apiVersion: batch/v1 |
| 165 | +kind: Job |
| 166 | +metadata: |
| 167 | + name: {{ include "global.fullname" . }}-run-sql-{{ .Release.Revision }} |
| 168 | + labels: |
| 169 | + app.kubernetes.io/component: database |
| 170 | + {{- include "global.labels" . | nindent 4 }} |
| 171 | +spec: |
| 172 | + ttlSecondsAfterFinished: 300 # 5 minutes |
| 173 | + template: |
| 174 | + spec: |
| 175 | + restartPolicy: Never |
| 176 | + containers: |
| 177 | + - name: oracle-sqlcl-runner |
| 178 | + image: container-registry.oracle.com/database/sqlcl:latest |
| 179 | + env: |
| 180 | + - name: TNS_ADMIN |
| 181 | + value: /app/tns_admin |
| 182 | + - name: API_SERVER_HOST |
| 183 | + value: {{ include "server.serviceName" . }} |
| 184 | + - name: API_SERVER_KEY |
| 185 | + valueFrom: |
| 186 | + secretKeyRef: |
| 187 | + name: {{ include "global.apiSecretName" . }} |
| 188 | + key: {{ include "global.apiSecretKey" . }} |
| 189 | + - name: PRIV_USERNAME |
| 190 | + valueFrom: |
| 191 | + secretKeyRef: |
| 192 | + name: {{ .Values.server.database.privAuthN.secretName }} |
| 193 | + key: {{ default "username" .Values.server.database.privAuthN.usernameKey }} |
| 194 | + - name: PRIV_PASSWORD |
| 195 | + valueFrom: |
| 196 | + secretKeyRef: |
| 197 | + name: {{ .Values.server.database.privAuthN.secretName }} |
| 198 | + key: {{ default "password" .Values.server.database.privAuthN.passwordKey }} |
| 199 | + {{- include "server.database.authN" . | nindent 8 }} |
| 200 | + command: ["/bin/sh", "-c"] |
| 201 | + args: |
| 202 | + - | |
| 203 | + attempt=1 |
| 204 | + while [ "$attempt" -lt 360 ]; do |
| 205 | + sh /opt/oracle/scripts/startup/init.sh |
| 206 | + if [ $? -eq 0 ]; then |
| 207 | + exit 0 |
| 208 | + fi |
| 209 | + echo "Waiting for connectivity to ${DB_DSN} ($attempt/360)" |
| 210 | + sleep 10 |
| 211 | + attempt=$((attempt + 1)) |
| 212 | + done |
| 213 | + volumeMounts: |
| 214 | + - name: db-init-scripts |
| 215 | + mountPath: /opt/oracle/scripts/startup |
| 216 | + {{- if eq (include "server.database.isADBS" .) "true" }} |
| 217 | + - name: tns-admin |
| 218 | + mountPath: /app/tns_admin |
| 219 | + {{- end }} |
| 220 | + volumes: |
| 221 | + - name: db-init-scripts |
| 222 | + configMap: |
| 223 | + name: {{ include "global.fullname" . }}-db-init |
| 224 | + {{- if eq (include "server.database.isADBS" .) "true" }} |
| 225 | + - name: tns-admin |
| 226 | + secret: |
| 227 | + secretName: {{ .Release.Name }}-adb-tns-admin-{{ .Release.Revision }} |
| 228 | + {{- end }} |
| 229 | +{{- end }} |
| 230 | + |
| 231 | +{{- if eq (include "server.database.isADBS" .) "true" }} |
| 232 | +--- |
| 233 | +# AutonomousDatabase Operator Resource (ADB-S) |
| 234 | +apiVersion: database.oracle.com/v4 |
| 235 | +kind: AutonomousDatabase |
| 236 | +metadata: |
| 237 | + name: {{ .Release.Name }}-adb-s |
| 238 | + labels: |
| 239 | + app.kubernetes.io/component: database |
| 240 | + {{- include "global.labels" . | nindent 4 }} |
| 241 | + annotations: |
| 242 | + "helm.sh/hook": pre-install,pre-upgrade |
| 243 | + "helm.sh/hook-weight": "-5" |
| 244 | + "helm.sh/hook-delete-policy": before-hook-creation |
| 245 | +spec: |
| 246 | + action: "Sync" |
| 247 | + details: |
| 248 | + id: {{ .Values.server.database.oci.ocid }} |
| 249 | + wallet: |
| 250 | + name: {{ .Release.Name }}-adb-tns-admin-{{ .Release.Revision }} |
| 251 | + password: |
| 252 | + k8sSecret: |
| 253 | + name: {{ .Release.Name }}-adb-wallet-pass-{{ .Release.Revision }} |
| 254 | + {{- if .Values.server.oci_config }} |
| 255 | + ociConfig: |
| 256 | + configMapName: {{ .Release.Name }}-oci-config |
| 257 | + {{- if .Values.server.oci_config.keySecretName }} |
| 258 | + secretName: {{ .Values.server.oci_config.keySecretName }} |
| 259 | + {{- end }} |
| 260 | + {{- end }} |
| 261 | +{{- end }} |
| 262 | + |
| 263 | +{{- end }} |
0 commit comments