Skip to content

Commit

Permalink
convert pika kubeblocks helm chart to new component definition api
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie committed Feb 21, 2024
1 parent 45b73ea commit 60535d6
Show file tree
Hide file tree
Showing 8 changed files with 481 additions and 5 deletions.
34 changes: 34 additions & 0 deletions tools/kubeblocks_helm/pika-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,37 @@ Create the name of the service account to use
{{- define "pika-cluster.serviceAccountName" -}}
{{- default (printf "kb-%s" (include "clustername" .)) .Values.serviceAccount.name }}
{{- end }}

{{/*
Define pika group with shardingSpec
*/}}
{{- define "pika-group.shardingSpec" }}
- name: group
shards: {{ .Values.replicaCount }}
template:
name: pika
componentDef: pika-group
replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }}
{{- with $.Values.resources.pikaGroup }}
resources:
limits:
cpu: {{ .limits.cpu | quote }}
memory: {{ .limits.memory | quote }}
requests:
cpu: {{ .requests.cpu | quote }}
memory: {{ .requests.memory | quote }}
{{- end }}
{{- if $.Values.persistence.enabled }}
volumeClaimTemplates:
{{- with $.Values.persistence.pikaData }}
- name: data
spec:
storageClassName: {{ .storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .size }}
{{- end }}
{{- end }}
{{- end }}
32 changes: 27 additions & 5 deletions tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ spec:
{{- with $.Values.tolerations }}
tolerations: {{ . | toYaml | nindent 4 }}
{{- end }}
{{- if not .Values.useLegacyCompDef }}
shardingSpecs:
{{- include "pika-group.shardingSpec" . | indent 6 }}
{{- end }}
componentSpecs:
{{- if not .Values.useLegacyCompDef }}
{{- range $i := until (int .Values.replicaCount) }}
- name: pika-group-{{ add ($i) 1 }} # user-defined
componentDefRef: pika-group # ref clusterDefinition componentDefs.name
Expand Down Expand Up @@ -46,9 +51,14 @@ spec:
storage: {{ .size }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
- name: etcd # user-defined
componentDefRef: etcd # ref clusterdefinition components.name
{{- if .Values.useLegacyCompDef }}
componentDefRef: etcd # ref clusterDefinition.componentDefs[x].name
{{- else }}
componentDef: pika-etcd # ref componentDefinition name
{{- end }}
monitor: {{ .Values.monitor.enabled | default false }}
replicas: {{ .Values.etcdReplicaCount| default 3 }}
{{- with .Values.resources.etcd }}
Expand Down Expand Up @@ -78,7 +88,11 @@ spec:
{{- end }}
{{- end }}
- name: codis-proxy
componentDefRef: codis-proxy # ref clusterDefinition componentDefs.name
{{- if .Values.useLegacyCompDef }}
componentDefRef: codis-proxy # ref clusterDefinition.componentDefs[x].name
{{- else }}
componentDef: pika-codis-proxy # ref componentDefinition name
{{- end }}
replicas: {{ .Values.codisProxyReplicaCount | default 2 }}
{{- with .Values.resources.codisProxy }}
resources:
Expand All @@ -90,7 +104,11 @@ spec:
memory: {{ .requests.memory | quote }}
{{- end }}
- name: codis-fe
componentDefRef: codis-fe # ref clusterDefinition componentDefs.name
{{- if .Values.useLegacyCompDef }}
componentDefRef: codis-fe # ref clusterDefinition.componentDefs[x].name
{{- else }}
componentDef: pika-codis-fe # ref componentDefinition name
{{- end }}
replicas: {{ .Values.codisFeReplicaCount | default 1 }}
{{- with .Values.resources.codisFe }}
resources:
Expand All @@ -102,7 +120,11 @@ spec:
memory: {{ .requests.memory | quote }}
{{- end }}
- name: codis-dashboard
componentDefRef: codis-dashboard # ref clusterDefinition componentDefs.name
{{- if .Values.useLegacyCompDef }}
componentDefRef: codis-dashboard # ref clusterDefinition.componentDefs[x].name
{{- else }}
componentDef: pika-codis-dashboard # ref componentDefinition name
{{- end }}
replicas: 1
{{- with .Values.resources.codisFe }}
resources:
Expand Down
6 changes: 6 additions & 0 deletions tools/kubeblocks_helm/pika-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

# Default values for pika-cluster.
# 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

nameOverride: ""
fullnameOverride: ""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ComponentDefinition
metadata:
name: pika-codis-dashboard
labels:
{{- include "pika.labels" . | nindent 4 }}
spec:
provider: pika
description: A pika codis dashboard component definition
serviceKind: pika-codis-dashboard
serviceVersion: 3.5.1
services:
- name: dashboard
serviceName: dashboard
spec:
ports:
- name: dashboard
targetPort: dashboard
port: 18080
updateStrategy: Serial
configs:
- name: codis-dashboard-config
templateRef: pika-conf-template
namespace: {{ .Release.Namespace }}
volumeName: config
runtime:
initContainers:
- name: wait-etcd
env:
- name: ETCD_ADDR
value: "{{ include "etcd.clusterDomain" .}}"
image: busybox:1.28
command:
- 'sh'
- '-c'
- "until nc -z ${ETCD_ADDR} 2379; do echo waiting for etcd; sleep 2; done;"
containers:
- name: codis-dashboard
image: {{ include "codis.image" . }}
imagePullPolicy: IfNotPresent
ports:
- containerPort: 18080
name: dashboard
volumeMounts:
- name: config
mountPath: /etc/codis
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: ETCD_ADDR
value: "{{ include "etcd.clusterDomain" .}}:2379"
- name: PRODUCT_NAME
value: "$(KB_CLUSTER_NAME)"
command:
- "/codis/bin/codis-dashboard"
args:
- "-c"
- "/etc/codis/dashboard.toml"
- "--host-admin"
- "$(POD_IP):18080"
- "--etcd"
- "$(ETCD_ADDR)"
- "--product_name"
- "$(PRODUCT_NAME)"
- "--pidfile"
- "log/dashboard.pid"
- "--remove-lock"
- "--log-level=DEBUG"
lifecycle:
postStart:
exec:
command: [ "/bin/bash", "-c", "/codis/bin/codis-admin --dashboard-list --etcd=${ETCD_ADDR}" ]
preStop:
exec:
command: [ "/bin/sh", "-c", "PID=$(cat log/dashboard.pid) && kill $PID && while ps -p 1 > /dev/null; do sleep 1; done" ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ComponentDefinition
metadata:
name: pika-codis-fe
labels:
{{- include "pika.labels" . | nindent 4 }}
spec:
provider: pika
description: A pika codis frontend component definition
serviceKind: pika-codis-fe
serviceVersion: 3.5.1
services:
- name: fe
serviceName: fe
spec:
ports:
- name: fe
targetPort: fe
port: 8080
updateStrategy: Parallel
runtime:
initContainers:
- name: wait-etcd
env:
- name: ETCD_ADDR
value: "{{ include "etcd.clusterDomain" .}}"
- name: DASHBOARD_ADDR
value: "$(KB_CLUSTER_NAME)-codis-dashboard"
image: busybox:1.28
command:
- 'sh'
- '-c'
- "until nc -z ${ETCD_ADDR} 2379; do echo waiting for etcd; sleep 2; done;"
- "until nc -z ${DASHBOARD_ADDR} 18080; do echo waiting for etcd; sleep 2; done;"
containers:
- name: codis-fe
image: {{ include "codis.image" . }}
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
name: fe
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: ETCD_ADDR
value: "{{ include "etcd.clusterDomain" .}}:2379"
command:
- "/codis/bin/codis-fe"
args:
- "--etcd"
- "$(ETCD_ADDR)"
- "--listen=0.0.0.0:8080"
- "--assets=/codis/bin/assets"
- "--log-level=DEBUG"
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ComponentDefinition
metadata:
name: pika-codis-proxy
labels:
{{- include "pika.labels" . | nindent 4 }}
spec:
provider: pika
description: A pika codis proxy component definition
serviceKind: pika-codis-proxy
serviceVersion: 3.5.1
services:
- name: proxy
serviceName: proxy
spec:
ports:
- name: proxy
targetPort: proxy
port: 11080
- name: admin
targetPort: admin
port: 19000
updateStrategy: Serial
configs:
- name: codis-proxy-config
templateRef: pika-conf-template
namespace: {{ .Release.Namespace }}
volumeName: config
runtime:
initContainers:
- name: wait-etcd
env:
- name: ETCD_ADDR
value: "{{ include "etcd.clusterDomain" .}}"
- name: DASHBOARD_ADDR
value: "$(KB_CLUSTER_NAME)-codis-dashboard"
image: busybox:1.28
command:
- 'sh'
- '-c'
- "until nc -z ${ETCD_ADDR} 2379; do echo waiting for etcd; sleep 2; done;"
- "until nc -z ${DASHBOARD_ADDR} 18080; do echo waiting for etcd; sleep 2; done;"
containers:
- name: codis-proxy
image: {{ include "codis.image" . }}
imagePullPolicy: IfNotPresent
ports:
- containerPort: 11080
name: proxy
- containerPort: 19000
name: admin
volumeMounts:
- name: config
mountPath: /etc/codis
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: ETCD_ADDR
value: "{{ include "etcd.clusterDomain" .}}:2379"
- name: DASHBOARD_ADDR
value: "$(KB_CLUSTER_NAME)-codis-dashboard:18080"
- name: PRODUCT_NAME
value: "$(KB_CLUSTER_NAME)"
command:
- "/codis/bin/codis-proxy"
args:
- "-c"
- "/etc/codis/proxy.toml"
- "--host-admin"
- "$(POD_IP):11080"
- "--host-proxy"
- "$(POD_IP):19000"
- "--etcd"
- "$(ETCD_ADDR)"
- "--product_name"
- "$(PRODUCT_NAME)"
- "--pidfile"
- "log/proxy.pid"
- "--log-level=DEBUG"
lifecycle:
preStop:
exec:
command:
- "/bin/sh"
- "-c"
- "/codis/bin/codis-admin --dashboard=${DASHBOARD_ADDR} --remove-proxy --addr=${POD_IP}:11080 1>/dev/null 2>&1"
Loading

0 comments on commit 60535d6

Please sign in to comment.