Skip to content

Commit

Permalink
feat: support deploying pika_exporter components using kubeblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengyu committed Mar 8, 2024
1 parent a753d90 commit f6cbfd2
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 1 deletion.
16 changes: 16 additions & 0 deletions tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ spec:
storage: {{ .size }}
{{- end }}
{{- end }}
- name: pika-exporter
{{- if .Values.useLegacyCompDef }}
componentDefRef: pika-exporter # ref clusterDefinition.componentDefs[x].name
{{- else }}
componentDef: pika-exporter # ref componentDefinition name
{{- end }}
replicas: 1
{{- with .Values.resources.pikaExporter }}
resources:
limits:
cpu: {{ .limits.cpu | quote }}
memory: {{ .limits.memory | quote }}
requests:
cpu: {{ .requests.cpu | quote }}
memory: {{ .requests.memory | quote }}
{{- end }}
- name: codis-proxy
{{- if .Values.useLegacyCompDef }}
componentDefRef: codis-proxy # ref clusterDefinition.componentDefs[x].name
Expand Down
9 changes: 8 additions & 1 deletion tools/kubeblocks_helm/pika-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
# if useLegacyCompDef is false ,cluster will be rendered by component definition rather than componentDefRef in cluster definition
useLegacyCompDef: false
useLegacyCompDef: true

nameOverride: ""
fullnameOverride: ""
Expand Down Expand Up @@ -52,6 +52,13 @@ resources:
requests:
cpu: 500m
memory: 1Gi
pikaExporter:
limits:
cpu: 500m
memory: 3Gi
requests:
cpu: 500m
memory: 1Gi
codisProxy:
limits:
cpu: 500m
Expand Down
12 changes: 12 additions & 0 deletions tools/kubeblocks_helm/pika/config/exporter-info.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
server = true
data = true
clients = true
stats = true
cpu = true
replication = true
keyspace = true
cache = true

execcount = false
commandstats = false
rocksdb = false
12 changes: 12 additions & 0 deletions tools/kubeblocks_helm/pika/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ Define image
{{ .Values.image.pika.pullPolicy | default "IfNotPresent" }}
{{- end }}

{{/*
Define Pika Exporter image
*/}}

{{- define "pikaExporter.image" -}}
{{ .Values.image.pikaExporter.registry | default "docker.io" }}/{{ .Values.image.pikaExporter.repository }}:{{ .Values.image.pikaExporter.tag }}
{{- end }}

{{- define "pikaExporter.imagePullPolicy" -}}
{{ .Values.image.pikaExporter.pullPolicy | default "IfNotPresent" }}
{{- end }}

{{/*
Define codis image
*/}}
Expand Down
43 changes: 43 additions & 0 deletions tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,49 @@ spec:
value: "2500"
- name: ETCD_ENABLE_V2
value: "true"
- name: pika-exporter
workloadType: Stateless
characterType: pika
service:
ports:
- name: expoter
targetPort: expoter
port: 9121
configSpecs:
- name: pika-config
templateRef: pika-conf-template
namespace: {{ .Release.Namespace }}
volumeName: config
podSpec:
initContainers:
- name: wait-codis-dashboard
env:
- name: DASHBOARD_ADDR
value: "$(KB_CLUSTER_NAME)-codis-dashboard"
image: busybox:1.28
command:
- 'sh'
- '-c'
- "until nc -z ${DASHBOARD_ADDR} 18080; do echo waiting for codis dashboard; sleep 2; done;"
containers:
- name: pika-exporter
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9121
name: exporter
volumeMounts:
- name: config
mountPath: /etc/pika
env:
- name: DASHBOARD_ADDR
value: "$(KB_CLUSTER_NAME)-codis-dashboard"
command:
- "/pika/bin/pika_exporter"
args:
- "-config"
- "/etc/pika/info.toml"
- "-codis.addr"
- "http://$(DASHBOARD_ADDR):18080/topom"
- name: codis-proxy
workloadType: Stateful
characterType: pika
Expand Down
6 changes: 6 additions & 0 deletions tools/kubeblocks_helm/pika/templates/clusterversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ spec:
- name: etcd
image: {{ include "etcd.image" . }}
imagePullPolicy: {{ include "etcd.imagePullPolicy" . }}
- componentDefRef: pika-exporter
versionsContext:
containers:
- name: pika-exporter
image: {{ include "pikaExporter.image" . }}
imagePullPolicy: {{ include "pikaExporter.imagePullPolicy" . }}
- componentDefRef: codis-proxy
versionsContext:
containers:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ComponentDefinition
metadata:
name: pika-exporter
labels:
{{- include "pika.labels" . | nindent 4 }}
spec:
provider: pika
description: A pika exporter component definition
serviceKind: pika-exporter
serviceVersion: {{ .Chart.AppVersion }}
services:
- name: expoter
serviceName: expoter
spec:
ports:
- name: expoter
port: 9121
targetPort: expoter
updateStrategy: Serial
configs:
- name: pika-config
templateRef: pika-conf-template
volumeName: config
vars:
## reference to the pika-codis-dashboard service
- name: DASHBOARD_ADDR
valueFrom:
serviceVarRef:
compDef: pika-codis-dashboard
name: dashboard
optional: true
host: Optional
runtime:
initContainers:
- name: wait-codis-dashboard
image: busybox:1.28
command:
- 'sh'
- '-c'
- "until nc -z ${DASHBOARD_ADDR} 18080; do echo waiting for codis dashboard; sleep 2; done;"
containers:
- name: pika-exporter
image: {{ include "pikaExporter.image" . }}
imagePullPolicy: {{ include "pikaExporter.imagePullPolicy" . }}
ports:
- name: expoter
containerPort: 9121
volumeMounts:
- name: config
mountPath: /etc/pika
command:
- "/pika/bin/pika_exporter"
args:
- "-config"
- "/etc/pika/info.toml"
- "-codis.addr"
- "http://$(DASHBOARD_ADDR):18080/topom"
2 changes: 2 additions & 0 deletions tools/kubeblocks_helm/pika/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ data:
{{- .Files.Get "config/codis-dashboard.tpl" | nindent 4 }}
proxy.toml: |-
{{- .Files.Get "config/codis-proxy.tpl" | nindent 4 }}
info.toml: |-
{{- .Files.Get "config/exporter-info.tpl" | nindent 4 }}

0 comments on commit f6cbfd2

Please sign in to comment.