Skip to content

Commit ef8a4a6

Browse files
committed
feat(helm-chart): Add storage and bundled-MariaDB templates.
Adds the Spider Helm chart's templates and values: the storage gRPC service (Deployment + Service + ConfigMap) and a bundled MariaDB (StatefulSet + Service + Secret), gated on `spiderConfig.bundled`. Remove "database" from `bundled` to connect to an external MariaDB. Builds on the chart scaffolding + linting from the companion PR.
1 parent a1d05e8 commit ef8a4a6

8 files changed

Lines changed: 354 additions & 0 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
{{/*
2+
Expands the name of the chart.
3+
4+
@return {string} The chart name (truncated to 63 characters)
5+
*/}}
6+
{{- define "spider.name" -}}
7+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
8+
{{- end }}
9+
10+
{{/*
11+
Creates a default fully qualified app name (truncated to 63 chars for the DNS naming spec). If the
12+
release name already contains the chart name it is used as-is.
13+
14+
@return {string} The fully qualified app name (truncated to 63 characters)
15+
*/}}
16+
{{- define "spider.fullname" -}}
17+
{{- if .Values.fullnameOverride }}
18+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
19+
{{- else }}
20+
{{- $name := default .Chart.Name .Values.nameOverride }}
21+
{{- if contains $name .Release.Name }}
22+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
23+
{{- else }}
24+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
25+
{{- end }}
26+
{{- end }}
27+
{{- end }}
28+
29+
{{/*
30+
Creates chart name and version as used by the chart label.
31+
32+
@return {string} Chart name and version (truncated to 63 characters)
33+
*/}}
34+
{{- define "spider.chart" -}}
35+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
36+
{{- end }}
37+
38+
{{/*
39+
Creates common labels for all resources.
40+
41+
@return {string} YAML-formatted common labels
42+
*/}}
43+
{{- define "spider.labels" -}}
44+
helm.sh/chart: {{ include "spider.chart" . }}
45+
{{ include "spider.selectorLabels" . }}
46+
{{- if .Chart.AppVersion }}
47+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
48+
{{- end }}
49+
app.kubernetes.io/managed-by: {{ .Release.Service }}
50+
{{- end }}
51+
52+
{{/*
53+
Creates selector labels for matching resources.
54+
55+
@return {string} YAML-formatted selector labels
56+
*/}}
57+
{{- define "spider.selectorLabels" -}}
58+
app.kubernetes.io/name: {{ include "spider.name" . }}
59+
app.kubernetes.io/instance: {{ .Release.Name }}
60+
{{- end }}
61+
62+
{{/*
63+
Creates a container image reference from `.Values.image.<component>`.
64+
65+
The tag defaults to the chart's appVersion when the component omits it.
66+
67+
@param {object} root Root template context (required)
68+
@param {string} component Key under `.Values.image` (e.g. "storage", "mariadb")
69+
@return {string} Full image reference (repository:tag)
70+
*/}}
71+
{{- define "spider.imageRef" -}}
72+
{{- $img := index .root.Values.image .component -}}
73+
{{- $tag := $img.tag | default .root.Chart.AppVersion -}}
74+
{{- printf "%s:%s" $img.repository $tag -}}
75+
{{- end }}
76+
77+
{{/*
78+
Creates timings for readiness probes (faster checks for quicker startup).
79+
80+
@return {string} YAML-formatted readiness probe timing configuration
81+
*/}}
82+
{{- define "spider.readinessProbeTimings" -}}
83+
initialDelaySeconds: 6
84+
periodSeconds: 2
85+
timeoutSeconds: 2
86+
failureThreshold: 10
87+
{{- end }}
88+
89+
{{/*
90+
Creates timings for liveness probes.
91+
92+
@return {string} YAML-formatted liveness probe timing configuration
93+
*/}}
94+
{{- define "spider.livenessProbeTimings" -}}
95+
initialDelaySeconds: 180
96+
periodSeconds: 30
97+
timeoutSeconds: 4
98+
failureThreshold: 3
99+
{{- end }}
100+
101+
{{/*
102+
Gets the database host. When "database" is bundled, this is the in-cluster MariaDB Service; when not
103+
bundled, it is the external `spiderConfig.database.host`.
104+
105+
@param {object} . Root template context
106+
@return {string} The database host
107+
*/}}
108+
{{- define "spider.databaseHost" -}}
109+
{{- if has "database" .Values.spiderConfig.bundled -}}
110+
{{- printf "%s-database" (include "spider.fullname" .) -}}
111+
{{- else -}}
112+
{{- .Values.spiderConfig.database.host -}}
113+
{{- end -}}
114+
{{- end }}
115+
116+
{{/*
117+
Gets the database port. When "database" is bundled, this is 3306 (the bundled MariaDB's port);
118+
otherwise it is the external `spiderConfig.database.port`.
119+
120+
@param {object} . Root template context
121+
@return {string} The database port
122+
*/}}
123+
{{- define "spider.databasePort" -}}
124+
{{- if has "database" .Values.spiderConfig.bundled -}}
125+
3306
126+
{{- else -}}
127+
{{- .Values.spiderConfig.database.port -}}
128+
{{- end -}}
129+
{{- end }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: "v1"
2+
kind: "ConfigMap"
3+
metadata:
4+
name: {{ include "spider.fullname" . }}-config
5+
labels:
6+
{{- include "spider.labels" . | nindent 4 }}
7+
data:
8+
storage.yaml: |
9+
host: "0.0.0.0"
10+
port: {{ .Values.spiderConfig.storage_endpoint.port }}
11+
runtime:
12+
db_config:
13+
host: {{ include "spider.databaseHost" . | quote }}
14+
port: {{ include "spider.databasePort" . }}
15+
name: {{ .Values.spiderConfig.database.name | quote }}
16+
username: {{ .Values.spiderConfig.database.username | quote }}
17+
password: {{ .Values.spiderConfig.database.password | quote }}
18+
max_connections: {{ .Values.spiderConfig.storage.max_connections }}
19+
{{- with omit .Values.spiderConfig.storage "max_connections" }}
20+
{{- toYaml . | nindent 6 }}
21+
{{- end }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if has "database" .Values.spiderConfig.bundled }}
2+
apiVersion: "v1"
3+
kind: "Secret"
4+
metadata:
5+
name: {{ include "spider.fullname" . }}-database
6+
labels:
7+
{{- include "spider.labels" . | nindent 4 }}
8+
app.kubernetes.io/component: "database"
9+
type: "Opaque"
10+
stringData:
11+
username: {{ .Values.spiderConfig.database.username | quote }}
12+
password: {{ .Values.spiderConfig.database.password | quote }}
13+
root_password: {{ .Values.spiderConfig.database.root_password | quote }}
14+
{{- end }}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- if has "database" .Values.spiderConfig.bundled }}
2+
apiVersion: "v1"
3+
kind: "Service"
4+
metadata:
5+
name: {{ include "spider.fullname" . }}-database
6+
labels:
7+
{{- include "spider.labels" . | nindent 4 }}
8+
app.kubernetes.io/component: "database"
9+
spec:
10+
clusterIP: "None"
11+
selector:
12+
{{- include "spider.selectorLabels" . | nindent 4 }}
13+
app.kubernetes.io/component: "database"
14+
ports:
15+
- port: 3306
16+
targetPort: "database"
17+
{{- end }}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{{- if has "database" .Values.spiderConfig.bundled }}
2+
apiVersion: "apps/v1"
3+
kind: "StatefulSet"
4+
metadata:
5+
name: {{ include "spider.fullname" . }}-database
6+
labels:
7+
{{- include "spider.labels" . | nindent 4 }}
8+
app.kubernetes.io/component: "database"
9+
spec:
10+
serviceName: {{ include "spider.fullname" . }}-database
11+
replicas: 1
12+
selector:
13+
matchLabels:
14+
{{- include "spider.selectorLabels" . | nindent 6 }}
15+
app.kubernetes.io/component: "database"
16+
template:
17+
metadata:
18+
labels:
19+
{{- include "spider.labels" . | nindent 8 }}
20+
app.kubernetes.io/component: "database"
21+
spec:
22+
containers:
23+
- name: "database"
24+
image: {{ include "spider.imageRef" (dict "root" . "component" "mariadb") | quote }}
25+
imagePullPolicy: {{ .Values.image.mariadb.pullPolicy | quote }}
26+
env:
27+
- name: "MYSQL_DATABASE"
28+
value: {{ .Values.spiderConfig.database.name | quote }}
29+
- name: "MYSQL_USER"
30+
valueFrom:
31+
secretKeyRef:
32+
name: {{ include "spider.fullname" . }}-database
33+
key: "username"
34+
- name: "MYSQL_PASSWORD"
35+
valueFrom:
36+
secretKeyRef:
37+
name: {{ include "spider.fullname" . }}-database
38+
key: "password"
39+
- name: "MYSQL_ROOT_PASSWORD"
40+
valueFrom:
41+
secretKeyRef:
42+
name: {{ include "spider.fullname" . }}-database
43+
key: "root_password"
44+
ports:
45+
- name: "database"
46+
containerPort: 3306
47+
volumeMounts:
48+
- name: "data"
49+
mountPath: "/var/lib/mysql"
50+
readinessProbe:
51+
{{- include "spider.readinessProbeTimings" . | nindent 12 }}
52+
exec: &health-check
53+
command: [
54+
"mysqladmin", "ping",
55+
"--host=127.0.0.1",
56+
"--port=3306",
57+
"--user=$(MYSQL_USER)",
58+
"--password=$(MYSQL_PASSWORD)"
59+
]
60+
livenessProbe:
61+
{{- include "spider.livenessProbeTimings" . | nindent 12 }}
62+
exec: *health-check
63+
volumeClaimTemplates:
64+
- metadata:
65+
name: "data"
66+
spec:
67+
accessModes: ["ReadWriteOnce"]
68+
resources:
69+
requests:
70+
storage: "20Gi"
71+
{{- end }}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: "apps/v1"
2+
kind: "Deployment"
3+
metadata:
4+
name: {{ include "spider.fullname" . }}-storage
5+
labels:
6+
{{- include "spider.labels" . | nindent 4 }}
7+
app.kubernetes.io/component: "storage"
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
{{- include "spider.selectorLabels" . | nindent 6 }}
13+
app.kubernetes.io/component: "storage"
14+
template:
15+
metadata:
16+
labels:
17+
{{- include "spider.labels" . | nindent 8 }}
18+
app.kubernetes.io/component: "storage"
19+
spec:
20+
containers:
21+
- name: "storage"
22+
image: {{ include "spider.imageRef" (dict "root" . "component" "storage") | quote }}
23+
imagePullPolicy: {{ .Values.image.storage.pullPolicy | quote }}
24+
command: ["spider-storage", "--config", "/etc/spider/storage.yaml"]
25+
ports:
26+
- name: "grpc"
27+
containerPort: {{ .Values.spiderConfig.storage_endpoint.port }}
28+
volumeMounts:
29+
- name: "config"
30+
mountPath: "/etc/spider"
31+
readOnly: true
32+
readinessProbe:
33+
{{- include "spider.readinessProbeTimings" . | nindent 12 }}
34+
tcpSocket:
35+
port: "grpc"
36+
livenessProbe:
37+
{{- include "spider.livenessProbeTimings" . | nindent 12 }}
38+
tcpSocket:
39+
port: "grpc"
40+
volumes:
41+
- name: "config"
42+
configMap:
43+
name: {{ include "spider.fullname" . }}-config
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: "v1"
2+
kind: "Service"
3+
metadata:
4+
name: {{ include "spider.fullname" . }}-storage
5+
labels:
6+
{{- include "spider.labels" . | nindent 4 }}
7+
app.kubernetes.io/component: "storage"
8+
spec:
9+
selector:
10+
{{- include "spider.selectorLabels" . | nindent 4 }}
11+
app.kubernetes.io/component: "storage"
12+
ports:
13+
- name: "grpc"
14+
port: {{ .Values.spiderConfig.storage_endpoint.port }}
15+
targetPort: "grpc"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
nameOverride: ""
2+
fullnameOverride: ""
3+
4+
image:
5+
storage:
6+
repository: "ghcr.io/y-scope/spider/storage"
7+
pullPolicy: "Always"
8+
tag: "main"
9+
mariadb:
10+
repository: "mariadb"
11+
pullPolicy: "Always"
12+
tag: "10.11.16"
13+
14+
spiderConfig:
15+
# List of third-party services bundled (deployed) as part of the chart.
16+
# Remove a service from this list to use an external instance instead, and configure its host/port
17+
# accordingly in the service-specific sections below.
18+
bundled:
19+
- "database"
20+
21+
database:
22+
host: "127.0.0.1"
23+
port: 3306
24+
username: "spider-user"
25+
password: "spider-password"
26+
root_password: "spider-root-password"
27+
name: "spider-db"
28+
29+
storage_endpoint:
30+
port: 50051
31+
32+
storage:
33+
max_connections: 64
34+
# task_instance_pool_config:
35+
# execution_manager_stale_cutoff_sec: 30
36+
# gc_interval_sec: 5
37+
# message_channel_capacity: 1024
38+
# job_cache_gc_config:
39+
# terminated_job_retention_sec: 300
40+
# gc_interval_sec: 10
41+
ready_queue_config:
42+
task_capacity: 1048576
43+
commit_capacity: 256
44+
cleanup_capacity: 256

0 commit comments

Comments
 (0)