Skip to content

Commit

Permalink
feat: pika supports kubeblocks component definition api (OpenAtomFoun…
Browse files Browse the repository at this point in the history
…dation#2411)

* add kubeblock component post start demo

* convert pika kubeblocks helm chart to new component definition api

(cherry picked from commit 60535d6)

* modify cluster yaml

* remove dirty code

* refine pika cluster yaml

* add PIKA_CODIS_DASHBOARD_SVC_NAME var reference
  • Loading branch information
Y-Rookie authored Feb 29, 2024
1 parent 86051ea commit f8b5283
Show file tree
Hide file tree
Showing 10 changed files with 495 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tools/kubeblocks_helm/pika-cluster/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ Create the name of the service account to use
*/}}
{{- define "pika-cluster.serviceAccountName" -}}
{{- default (printf "kb-%s" (include "clustername" .)) .Values.serviceAccount.name }}
{{- end }}
{{- end }}
62 changes: 56 additions & 6 deletions tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,43 @@ spec:
{{- with $.Values.tolerations }}
tolerations: {{ . | toYaml | nindent 4 }}
{{- end }}
## define pika group with shardingSpecs API which is supported in KubeBlocks v0.8.2
{{- if not .Values.useLegacyCompDef }}
shardingSpecs:
- name: group
shards: {{ .Values.groupCount }}
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 }}
componentSpecs:
{{- if .Values.useLegacyCompDef }}
{{- range $i := until (int .Values.groupCount) }}
- name: pika-group-{{ add ($i) 1 }} # user-defined
componentDefRef: pika-group # ref clusterDefinition componentDefs.name
componentDefRef: pika-group # ref clusterDefinition.componentDefs[x].name
monitor: {{ $.Values.monitor.enabled | default false }}
enabledLogs: {{ $.Values.enabledLogs | toJson | indent 4 }}
replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }}
Expand Down Expand Up @@ -46,9 +79,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 +116,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 +132,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 +148,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
3 changes: 3 additions & 0 deletions tools/kubeblocks_helm/pika/script/admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ set_group_id() {
# set codis dashboard
set_codis_dashboard() {
CODIS_DASHBOARD="${KB_CLUSTER_NAME}-codis-dashboard"
if [ ! -z "$PIKA_CODIS_DASHBOARD_SVC_NAME" ]; then
CODIS_DASHBOARD=$PIKA_CODIS_DASHBOARD_SVC_NAME
fi
echo "CODIS_DASHBOARD: "${CODIS_DASHBOARD}
CODIS_ADMIN="/codis/bin/codis-admin --dashboard=${CODIS_DASHBOARD}:18080"
echo "CODIS_ADMIN: "${CODIS_ADMIN}
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 f8b5283

Please sign in to comment.