WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit c41e342

Browse files
committed
Sync MariaDB databases and users
1 parent 6024ea1 commit c41e342

File tree

5 files changed

+104
-1
lines changed

5 files changed

+104
-1
lines changed

infra/clusterroles/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
name: clusterroles
3+
version: 1.0.0
4+
5+
description: "Special cluster roles"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Roles to access configMaps and secrets in all namespaces.
2+
# This is a very dangerous role, only use it with care!
3+
apiVersion: rbac.authorization.k8s.io/v1
4+
kind: ClusterRole
5+
metadata:
6+
name: read-cm-secrets
7+
rules:
8+
- apiGroups: [""]
9+
resources: ["configmaps", "secrets"]
10+
verbs: ["get", "list"]
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: init-apps
5+
6+
---
7+
8+
apiVersion: rbac.authorization.k8s.io/v1
9+
kind: RoleBinding
10+
metadata:
11+
name: allow-init-apps-read-app-config
12+
namespace: faf-apps
13+
subjects:
14+
- kind: ServiceAccount
15+
name: init-apps
16+
namespace: faf-ops
17+
roleRef:
18+
apiGroup: rbac.authorization.k8s.io
19+
kind: ClusterRole
20+
name: read-cm-secrets
21+
22+
---
23+
24+
{{- $wave := 1 }}
25+
{{- range .Values.databasesAndUsers }}
26+
---
27+
apiVersion: batch/v1
28+
kind: Job
29+
metadata:
30+
name: mariadb-sync-db-user-{{ $wave }}
31+
labels:
32+
app: mariadb-sync-db-user
33+
argocd.argoproj.io/instance: mariadb
34+
annotations:
35+
argocd.argoproj.io/hook: PostSync
36+
argocd.argoproj.io/hook-delete-policy: HookSucceeded
37+
argocd.argoproj.io/sync-wave: '{{ $wave }}'
38+
spec:
39+
backoffLimit: 1
40+
template:
41+
spec:
42+
serviceAccountName: init-apps
43+
containers:
44+
- name: mariadb-sync-db-user
45+
image: {{ $.Values.image.repository }}:{{ $.Values.image.tag }}
46+
imagePullPolicy: Always
47+
env:
48+
- name: SYNC_DATABASE
49+
valueFrom:
50+
configMapKeyRef:
51+
name: {{ .configMapRef }}
52+
key: {{ .databaseKey }}
53+
- name: SYNC_USERNAME
54+
valueFrom:
55+
configMapKeyRef:
56+
name: {{ .configMapRef }}
57+
key: {{ .usernameKey }}
58+
- name: SYNC_PASSWORD
59+
valueFrom:
60+
secretKeyRef:
61+
name: {{ .secretRef }}
62+
key: {{ .passwordKey }}
63+
envFrom:
64+
- secretRef:
65+
name: mariadb
66+
67+
command: ["/bin/sh", "-c"]
68+
args:
69+
- |
70+
mariadb --user=root --password="${MARIADB_ROOT_PASSWORD}" <<SQL_SCRIPT
71+
CREATE DATABASE IF NOT EXISTS \`${SYNC_DATABASE}\`;
72+
CREATE USER IF NOT EXISTS '${SYNC_USERNAME}'@'%' IDENTIFIED BY '${SYNC_PASSWORD}';
73+
GRANT ALL PRIVILEGES ON \`${SYNC_DATABASE}\`.* TO '${SYNC_USERNAME}'@'%';
74+
SQL_SCRIPT
75+
restartPolicy: Never
76+
{{- $wave = add $wave 1 }}
77+
{{- end }}

infra/mariadb/templates/statefulset.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
app: mariadb
1818
spec:
1919
containers:
20-
- image: mariadb:12.1
20+
- image: {{ $.Values.image.repository }}:{{ $.Values.image.tag }}
2121
imagePullPolicy: Always
2222
name: mariadb
2323
ports:

infra/mariadb/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1+
image:
2+
repository: "mariadb"
3+
tag: "12.1"
4+
15
infisical-secret:
26
name: mariadb
7+
8+
databasesAndUsers:
9+
- configMapRef: faf-api
10+
secretRef: faf-api
11+
databaseKey: DATABASE_NAME
12+
usernameKey: DATABASE_USERNAME
13+
passwordKey: DATABASE_USERNAME

0 commit comments

Comments
 (0)