Skip to content

Commit b9946d2

Browse files
committed
Expose node locality to pod
1 parent 3cd9797 commit b9946d2

File tree

11 files changed

+88
-31
lines changed

11 files changed

+88
-31
lines changed

cockroachdb/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v1
22
name: cockroachdb
33
home: https://www.cockroachlabs.com
4-
version: 6.0.8
4+
version: 6.1.8
55
appVersion: 21.1.7
66
description: CockroachDB is a scalable, survivable, strongly-consistent SQL database.
77
icon: https://raw.githubusercontent.com/cockroachdb/cockroach/master/docs/media/cockroach_db.png

cockroachdb/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ For details see the [`values.yaml`](values.yaml) file.
300300
| `conf.locality` | Locality attribute for this deployment | `""` |
301301
| `conf.single-node` | Disable CockroachDB clustering (standalone mode) | `no` |
302302
| `conf.sql-audit-dir` | Directory for SQL audit log | `""` |
303+
| `conf.useHostLocality.enabled` | Use host node labels to set region, zone, host locality keys | `false` |
304+
| `conf.useHostLocality.image.repository` | The init-container image name to query the kubernetes API | `scottcrossen/kube-node-labels` |
305+
| `conf.useHostLocality.image` | The init-container image tag to query the kubernetes API | `1.0.0` |
303306
| `conf.port` | CockroachDB primary serving port in Pods | `26257` |
304307
| `conf.http-port` | CockroachDB HTTP port in Pods | `8080` |
305308
| `conf.path` | CockroachDB data directory mount path | `cockroach-data` |
@@ -345,6 +348,8 @@ For details see the [`values.yaml`](values.yaml) file.
345348
| `service.public.type` | Public Service type | `ClusterIP` |
346349
| `service.public.labels` | Additional labels of public Service | `{"app.kubernetes.io/component": "cockroachdb"}` |
347350
| `service.public.annotations` | Additional annotations of public Service | `{}` |
351+
| `statefulset.serviceAccount.create` | Whether to create a new RBAC service account | `yes` |
352+
| `statefulset.serviceAccount.name` | Name of RBAC service account to use | `""` |
348353
| `service.discovery.labels` | Additional labels of discovery Service | `{"app.kubernetes.io/component": "cockroachdb"}` |
349354
| `service.discovery.annotations` | Additional annotations of discovery Service | `{}` |
350355
| `ingress.enabled` | Enable ingress resource for CockroachDB | `false` |
@@ -368,12 +373,11 @@ For details see the [`values.yaml`](values.yaml) file.
368373
| `init.labels` | Additional labels of init Job and its Pod | `{"app.kubernetes.io/component": "init"}` |
369374
| `init.annotations` | Additional labels of the Pod of init Job | `{}` |
370375
| `init.affinity` | [Affinity rules][2] of init Job Pod | `{}` |
376+
| `init.force` | Create the init pod even if the join URL is set | `false` |
371377
| `init.nodeSelector` | Node labels for init Job Pod assignment | `{}` |
372378
| `init.tolerations` | Node taints to tolerate by init Job Pod | `[]` |
373379
| `init.resources` | Resource requests and limits for the Pod of init Job | `{}` |
374380
| `tls.enabled` | Whether to run securely using TLS certificates | `no` |
375-
| `tls.serviceAccount.create` | Whether to create a new RBAC service account | `yes` |
376-
| `tls.serviceAccount.name` | Name of RBAC service account to use | `""` |
377381
| `tls.certs.provided` | Bring your own certs scenario, i.e certificates are provided | `no` |
378382
| `tls.certs.clientRootSecret` | If certs are provided, secret name for client root cert | `cockroachdb-root` |
379383
| `tls.certs.nodeSecret` | If certs are provided, secret name for node cert | `cockroachdb-node` |

cockroachdb/templates/_helpers.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ Create chart name and version as used by the chart label.
3333
{{/*
3434
Create the name of the ServiceAccount to use.
3535
*/}}
36-
{{- define "cockroachdb.tls.serviceAccount.name" -}}
37-
{{- if .Values.tls.serviceAccount.create -}}
38-
{{- default (include "cockroachdb.fullname" .) .Values.tls.serviceAccount.name -}}
36+
{{- define "cockroachdb.statefulset.serviceAccount.name" -}}
37+
{{- if .Values.statefulset.serviceAccount.create -}}
38+
{{- default (include "cockroachdb.fullname" .) .Values.statefulset.serviceAccount.name -}}
3939
{{- else -}}
40-
{{- default "default" .Values.tls.serviceAccount.name -}}
40+
{{- default "default" .Values.statefulset.serviceAccount.name -}}
4141
{{- end -}}
4242
{{- end -}}
4343

cockroachdb/templates/clusterrole.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.tls.enabled (not .Values.tls.certs.provided) (not .Values.tls.certs.certManager) }}
1+
{{- if or (and .Values.tls.enabled (not .Values.tls.certs.provided) (not .Values.tls.certs.certManager)) .Values.conf.useHostLocality.enabled }}
22
kind: ClusterRole
33
apiVersion: rbac.authorization.k8s.io/v1
44
metadata:
@@ -13,7 +13,14 @@ metadata:
1313
{{- toYaml . | nindent 4 }}
1414
{{- end }}
1515
rules:
16+
{{- if and .Values.tls.enabled (not .Values.tls.certs.provided) (not .Values.tls.certs.certManager) }}
1617
- apiGroups: ["certificates.k8s.io"]
1718
resources: ["certificatesigningrequests"]
1819
verbs: ["create", "get", "watch"]
19-
{{- end }}
20+
{{- end }}
21+
{{- if .Values.conf.useHostLocality.enabled }}
22+
- apiGroups: [""]
23+
resources: ["nodes"]
24+
verbs: ["get"]
25+
{{- end }}
26+
{{- end }}

cockroachdb/templates/clusterrolebinding.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and .Values.tls.enabled (not .Values.tls.certs.provided) (not .Values.tls.certs.certManager) }}
1+
{{- if or (and .Values.tls.enabled (not .Values.tls.certs.provided) (not .Values.tls.certs.certManager)) .Values.conf.useHostLocality.enabled }}
22
kind: ClusterRoleBinding
33
apiVersion: rbac.authorization.k8s.io/v1
44
metadata:
@@ -18,6 +18,6 @@ roleRef:
1818
name: {{ template "cockroachdb.fullname" . }}
1919
subjects:
2020
- kind: ServiceAccount
21-
name: {{ template "cockroachdb.tls.serviceAccount.name" . }}
21+
name: {{ template "cockroachdb.statefulset.serviceAccount.name" . }}
2222
namespace: {{ .Release.Namespace | quote }}
23-
{{- end }}
23+
{{- end }}

cockroachdb/templates/job.init.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if and (eq (len .Values.conf.join) 0) (not (index .Values.conf `single-node`)) }}
1+
{{- if and (or .Values.init.force (eq (len .Values.conf.join) 0)) (not (index .Values.conf `single-node`)) }}
22
kind: Job
33
apiVersion: batch/v1
44
metadata:
@@ -15,9 +15,9 @@ metadata:
1515
{{- with .Values.labels }}
1616
{{- toYaml . | nindent 4 }}
1717
{{- end }}
18-
annotations:
19-
helm.sh/hook: post-install,post-upgrade
20-
helm.sh/hook-delete-policy: hook-succeeded,before-hook-creation
18+
{{- with .Values.init.jobAnnotations }}
19+
annotations: {{- toYaml . | nindent 4 }}
20+
{{- end }}
2121
spec:
2222
template:
2323
metadata:
@@ -43,7 +43,7 @@ spec:
4343
{{- end }}
4444
{{- end }}
4545
{{- if and .Values.tls.enabled (not .Values.tls.certs.provided) (not .Values.tls.certs.certManager) }}
46-
serviceAccountName: {{ template "cockroachdb.tls.serviceAccount.name" . }}
46+
serviceAccountName: {{ template "cockroachdb.statefulset.serviceAccount.name" . }}
4747
initContainers:
4848
# The init-certs container sends a CSR (certificate signing request) to
4949
# the Kubernetes cluster.
@@ -77,7 +77,7 @@ spec:
7777
mountPath: /cockroach-certs/
7878
{{- end }}
7979
{{- if or .Values.tls.certs.certManager (and .Values.tls.enabled (.Values.tls.certs.provided))}}
80-
serviceAccountName: {{ template "cockroachdb.tls.serviceAccount.name" . }}
80+
serviceAccountName: {{ template "cockroachdb.statefulset.serviceAccount.name" . }}
8181
initContainers:
8282
- name: copy-certs
8383
image: "busybox"

cockroachdb/templates/networkpolicy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
kind: NetworkPolicy
33
apiVersion: {{ template "cockroachdb.networkPolicy.apiVersion" . }}
44
metadata:
5-
name: {{ template "cockroachdb.tls.serviceAccount.name" . }}
5+
name: {{ template "cockroachdb.statefulset.serviceAccount.name" . }}
66
namespace: {{ .Release.Namespace | quote }}
77
labels:
88
helm.sh/chart: {{ template "cockroachdb.chart" . }}

cockroachdb/templates/rolebinding.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ roleRef:
1818
name: {{ template "cockroachdb.fullname" . }}
1919
subjects:
2020
- kind: ServiceAccount
21-
name: {{ template "cockroachdb.tls.serviceAccount.name" . }}
21+
name: {{ template "cockroachdb.statefulset.serviceAccount.name" . }}
2222
namespace: {{ .Release.Namespace | quote }}
2323
{{- end }}

cockroachdb/templates/serviceaccount.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
{{- if and .Values.tls.enabled .Values.tls.serviceAccount.create }}
1+
{{- if and (or .Values.tls.enabled .Values.conf.useHostLocality.enabled) .Values.statefulset.serviceAccount.create }}
22
kind: ServiceAccount
33
apiVersion: v1
44
metadata:
5-
name: {{ template "cockroachdb.tls.serviceAccount.name" . }}
5+
name: {{ template "cockroachdb.statefulset.serviceAccount.name" . }}
66
namespace: {{ .Release.Namespace | quote }}
77
labels:
88
helm.sh/chart: {{ template "cockroachdb.chart" . }}

cockroachdb/templates/statefulset.yaml

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ spec:
5050
- name: {{ template "cockroachdb.fullname" . }}.init-certs.registry
5151
{{- end }}
5252
{{- end }}
53+
{{- if or .Values.tls.enabled .Values.conf.useHostLocality.enabled }}
54+
serviceAccountName: {{ template "cockroachdb.statefulset.serviceAccount.name" . }}
55+
{{- end }}
56+
initContainers:
5357
{{- if .Values.tls.enabled }}
54-
serviceAccountName: {{ template "cockroachdb.tls.serviceAccount.name" . }}
5558
{{- if and (not .Values.tls.certs.provided) (not .Values.tls.certs.certManager) }}
56-
initContainers:
5759
# The init-certs container sends a CSR (certificate signing request) to
5860
# the Kubernetes cluster.
5961
# You can see pending requests using:
@@ -109,6 +111,21 @@ spec:
109111
mountPath: /certs/
110112
{{- end }}
111113
{{- end }}
114+
{{- if .Values.conf.useHostLocality.enabled }}
115+
- name: get-node-info
116+
image: {{ .Values.conf.useHostLocality.image.repository }}:{{ .Values.conf.useHostLocality.image.tag }}
117+
imagePullPolicy: IfNotPresent
118+
env:
119+
- name: NODE
120+
valueFrom:
121+
fieldRef:
122+
fieldPath: spec.nodeName
123+
- name: OUTPUT_DIR
124+
value: /output
125+
volumeMounts:
126+
- name: node-data
127+
mountPath: /output
128+
{{- end }}
112129
{{- if or .Values.statefulset.nodeAffinity .Values.statefulset.podAffinity .Values.statefulset.podAntiAffinity }}
113130
affinity:
114131
{{- with .Values.statefulset.nodeAffinity }}
@@ -239,8 +256,12 @@ spec:
239256
--max-offset={{ . }}
240257
{{- end }}
241258
--max-sql-memory={{ index .Values.conf `max-sql-memory` }}
242-
{{- with .Values.conf.locality }}
259+
{{- if .Values.conf.useHostLocality.enabled }}
260+
--locality=$(/node-data/topology.sh){{ with .Values.conf.locality }},{{ . }}{{ end }}
261+
{{- else }}
262+
{{- with .Values.conf.locality }}
243263
--locality={{ . }}
264+
{{- end }}
244265
{{- end }}
245266
{{- with index .Values.conf `sql-audit-dir` }}
246267
--sql-audit-dir={{ . }}
@@ -284,6 +305,10 @@ spec:
284305
mountPath: {{ printf "/etc/cockroach/secrets/%s" . | quote }}
285306
readOnly: true
286307
{{- end }}
308+
{{- if .Values.conf.useHostLocality.enabled }}
309+
- name: node-data
310+
mountPath: /node-data
311+
{{- end }}
287312
livenessProbe:
288313
{{- if .Values.statefulset.customLivenessProbe }}
289314
{{ toYaml .Values.statefulset.customLivenessProbe | nindent 12 }}
@@ -357,6 +382,10 @@ spec:
357382
secret:
358383
secretName: {{ . | quote }}
359384
{{- end }}
385+
{{- if .Values.conf.useHostLocality.enabled }}
386+
- name: node-data
387+
emptyDir: {}
388+
{{- end }}
360389
{{- if .Values.storage.persistentVolume.enabled }}
361390
volumeClaimTemplates:
362391
- metadata:

0 commit comments

Comments
 (0)