From 45b73eafe01961039b1533d28695a7e71714afca Mon Sep 17 00:00:00 2001 From: Y-Rookie Date: Thu, 9 Nov 2023 17:34:27 +0800 Subject: [PATCH 1/6] add kubeblock component post start demo --- .../pika/templates/clusterdefinition.yaml | 7 +++++++ tools/kubeblocks_helm/pika/templates/script.yaml | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml b/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml index a81a82bdbb..4433e81510 100644 --- a/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml +++ b/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml @@ -32,6 +32,13 @@ spec: namespace: {{ .Release.Namespace }} volumeName: script defaultMode: 0555 + postStartSpec: + cmdExecutorConfig: + image: {{ .Values.image.pika.registry | default "docker.io" }}/{{ .Values.image.pika.repository }}:{{ .Values.image.pika.tag }} + command: + - /script/pika-group-post-start.sh + scriptSpecSelectors: + - name: pika-script podSpec: containers: - name: pika diff --git a/tools/kubeblocks_helm/pika/templates/script.yaml b/tools/kubeblocks_helm/pika/templates/script.yaml index d550ace041..aeb893a54b 100644 --- a/tools/kubeblocks_helm/pika/templates/script.yaml +++ b/tools/kubeblocks_helm/pika/templates/script.yaml @@ -7,3 +7,13 @@ metadata: data: admin.sh: |- {{- .Files.Get "script/admin.sh" | nindent 4 }} + pika-group-post-start.sh: |- + #! /bin/bash + set -x + + echo "add your post start script logic here" + envParams=$(env) + echo "add envs can be used in script:" + echo $envParams + + sleep 60 \ No newline at end of file From a954f09560c2349945a7d86c0663a1424c65c6d9 Mon Sep 17 00:00:00 2001 From: Y-Rookie Date: Wed, 21 Feb 2024 17:15:24 +0800 Subject: [PATCH 2/6] convert pika kubeblocks helm chart to new component definition api (cherry picked from commit 60535d635f8236482c95084fd1db24a9c363f982) --- .../pika-cluster/templates/_helpers.tpl | 34 ++++++ .../pika-cluster/templates/cluster.yaml | 32 ++++- .../kubeblocks_helm/pika-cluster/values.yaml | 6 + .../componentdefinition-codis-dashboard.yaml | 81 ++++++++++++ .../componentdefinition-codis-fe.yaml | 60 +++++++++ .../componentdefinition-codis-proxy.yaml | 92 ++++++++++++++ .../componentdefinition-pika-etcd.yaml | 115 ++++++++++++++++++ .../componentdefinition-pika-group.yaml | 66 ++++++++++ 8 files changed, 481 insertions(+), 5 deletions(-) create mode 100644 tools/kubeblocks_helm/pika/templates/componentdefinition-codis-dashboard.yaml create mode 100644 tools/kubeblocks_helm/pika/templates/componentdefinition-codis-fe.yaml create mode 100644 tools/kubeblocks_helm/pika/templates/componentdefinition-codis-proxy.yaml create mode 100644 tools/kubeblocks_helm/pika/templates/componentdefinition-pika-etcd.yaml create mode 100644 tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml diff --git a/tools/kubeblocks_helm/pika-cluster/templates/_helpers.tpl b/tools/kubeblocks_helm/pika-cluster/templates/_helpers.tpl index e45b48dcdc..596d81881d 100644 --- a/tools/kubeblocks_helm/pika-cluster/templates/_helpers.tpl +++ b/tools/kubeblocks_helm/pika-cluster/templates/_helpers.tpl @@ -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 }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml index ce0c3a6c3e..5b3b42934d 100644 --- a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml +++ b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml @@ -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 @@ -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 }} @@ -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: @@ -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: @@ -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: diff --git a/tools/kubeblocks_helm/pika-cluster/values.yaml b/tools/kubeblocks_helm/pika-cluster/values.yaml index 031aca4f0f..a6f21bc767 100644 --- a/tools/kubeblocks_helm/pika-cluster/values.yaml +++ b/tools/kubeblocks_helm/pika-cluster/values.yaml @@ -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: "" diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-dashboard.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-dashboard.yaml new file mode 100644 index 0000000000..230d1a3b7e --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-dashboard.yaml @@ -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" ] \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-fe.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-fe.yaml new file mode 100644 index 0000000000..0c48a03684 --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-fe.yaml @@ -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" \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-proxy.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-proxy.yaml new file mode 100644 index 0000000000..b429ef829c --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-proxy.yaml @@ -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" \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-etcd.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-etcd.yaml new file mode 100644 index 0000000000..67a68e84c8 --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-etcd.yaml @@ -0,0 +1,115 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentDefinition +metadata: + name: pika-etcd + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + provider: pika + description: A pika etcd component definition + serviceKind: pika-etcd + serviceVersion: 3.5.1 + services: + - name: etcd + serviceName: etcd + spec: + ports: + - name: client + port: 2379 + targetPort: client + - name: peer + port: 2380 + targetPort: peer + updateStrategy: Serial + runtime: + initContainers: + - name: volume-permissions + image: busybox:1.28 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -ec + - | + chown -R 1001:1001 /bitnami/etcd + securityContext: + runAsUser: 0 + volumeMounts: + - name: data + mountPath: /bitnami/etcd + containers: + - name: etcd + image: {{ include "etcd.image" . }} + imagePullPolicy: "IfNotPresent" + securityContext: + runAsNonRoot: false + runAsUser: 1001 + allowPrivilegeEscalation: false + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + volumeMounts: + - mountPath: /bitnami/etcd + name: data + ports: + - name: client + containerPort: 2379 + - name: peer + containerPort: 2380 + env: + - name: BITNAMI_DEBUG + value: "true" + - name: MY_POD_IP + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: status.podIP + - name: MY_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: MY_STS_NAME + value: $(KB_CLUSTER_COMP_NAME) + - name: ETCDCTL_API + value: "3" + - name: ETCD_ON_K8S + value: "yes" + - name: ETCD_START_FROM_SNAPSHOT + value: "no" + - name: ETCD_DISASTER_RECOVERY + value: "no" + - name: ETCD_NAME + value: $(MY_POD_NAME) + - name: ETCD_DATA_DIR + value: /bitnami/etcd/data + - name: ETCD_LOG_LEVEL + value: info + - name: ALLOW_NONE_AUTHENTICATION + value: "yes" + - name: ETCD_INITIAL_CLUSTER_TOKEN + value: "$(KB_CLUSTER_NAME)" + - name: ETCD_INITIAL_CLUSTER_STATE + value: "new" + - name: ETCD_INITIAL_CLUSTER + value: "{{ include "etcd.initialCluster" .}}" + - name: ETCD_CLUSTER_DOMAIN + value: "{{ include "etcd.clusterDomain" .}}" + - name: ETCD_AUTO_COMPACTION_MODE + value: "periodic" + - name: ETCD_AUTO_COMPACTION_RETENTION + value: "1h" + - name: ETCD_ADVERTISE_CLIENT_URLS + value: "{{ include "etcd.advertiseClientURLs" .}}" + - name: ETCD_LISTEN_CLIENT_URLS + value: http://0.0.0.0:2379 + - name: ETCD_INITIAL_ADVERTISE_PEER_URLS + value: http://$(KB_POD_FQDN){{ .Values.clusterDomain }}:2380 + - name: ETCD_LISTEN_PEER_URLS + value: http://0.0.0.0:2380 + - name: ETCD_QUOTA_BACKEND_BYTES + value: "4294967296" + - name: ETCD_HEARTBEAT_INTERVAL + value: "500" + - name: ETCD_ELECTION_TIMEOUT + value: "2500" + - name: ETCD_ENABLE_V2 + value: "true" \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml new file mode 100644 index 0000000000..e2b80af6a7 --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml @@ -0,0 +1,66 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentDefinition +metadata: + name: pika-group + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + provider: pika + description: A pika group component definition + serviceKind: pika-group + serviceVersion: 3.5.1 + services: + - name: pika + serviceName: pika + spec: + ports: + - name: pika + port: 9221 + targetPort: pika + updateStrategy: Serial + configs: + - name: pika-config + templateRef: pika-conf-template + namespace: {{ .Release.Namespace }} + volumeName: config + scripts: + - name: pika-script + templateRef: pika-script-template + namespace: {{ .Release.Namespace }} + volumeName: script + defaultMode: 0555 + lifecycleActions: + postProvision: + customHandler: + image: {{ .Values.image.pika.registry | default "docker.io" }}/{{ .Values.image.pika.repository }}:{{ .Values.image.pika.tag }} + exec: + command: + - /script/pika-group-post-start.sh + preCondition: ComponentReady + runtime: + containers: + - name: pika + image: {{ include "pika.image" . }} + imagePullPolicy: {{ include "pika.imagePullPolicy" . }} + ports: + - name: pika + containerPort: 9221 + volumeMounts: + - name: config + mountPath: /etc/pika + command: + - "/pika/bin/pika" + args: + - "-c" + - "/etc/pika/pika.conf" + - name: codis-admin + image: {{ include "codis.image" . }} + imagePullPolicy: {{ include "codis.imagePullPolicy" . }} + volumeMounts: + - name: script + mountPath: /script + command: + - "/bin/bash" + args: + - "-c" + - "/script/admin.sh --register-server;tail -f /dev/null" \ No newline at end of file From a733ea401f54e9202c67ff54d708afdac065c411 Mon Sep 17 00:00:00 2001 From: Y-Rookie Date: Wed, 21 Feb 2024 17:36:03 +0800 Subject: [PATCH 3/6] modify cluster yaml --- tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml index 5b3b42934d..14ce46b1b6 100644 --- a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml +++ b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml @@ -19,10 +19,10 @@ spec: {{- include "pika-group.shardingSpec" . | indent 6 }} {{- end }} componentSpecs: - {{- if not .Values.useLegacyCompDef }} + {{- if .Values.useLegacyCompDef }} {{- range $i := until (int .Values.replicaCount) }} - 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 }} From 78c2c6ef102a2602133f856dc49bd126d5cbe04b Mon Sep 17 00:00:00 2001 From: Y-Rookie Date: Wed, 21 Feb 2024 18:32:21 +0800 Subject: [PATCH 4/6] remove dirty code --- tools/kubeblocks_helm/pika/templates/script.yaml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/tools/kubeblocks_helm/pika/templates/script.yaml b/tools/kubeblocks_helm/pika/templates/script.yaml index aeb893a54b..fe1625d769 100644 --- a/tools/kubeblocks_helm/pika/templates/script.yaml +++ b/tools/kubeblocks_helm/pika/templates/script.yaml @@ -6,14 +6,4 @@ metadata: {{- include "pika.labels" . | nindent 4 }} data: admin.sh: |- - {{- .Files.Get "script/admin.sh" | nindent 4 }} - pika-group-post-start.sh: |- - #! /bin/bash - set -x - - echo "add your post start script logic here" - envParams=$(env) - echo "add envs can be used in script:" - echo $envParams - - sleep 60 \ No newline at end of file + {{- .Files.Get "script/admin.sh" | nindent 4 }} \ No newline at end of file From 238d46eccd421a73a94747b10ff598c201d092c0 Mon Sep 17 00:00:00 2001 From: Y-Rookie Date: Wed, 21 Feb 2024 18:46:13 +0800 Subject: [PATCH 5/6] refine pika cluster yaml --- .../pika-cluster/templates/_helpers.tpl | 34 ------------------- .../pika-cluster/templates/cluster.yaml | 30 +++++++++++++++- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/tools/kubeblocks_helm/pika-cluster/templates/_helpers.tpl b/tools/kubeblocks_helm/pika-cluster/templates/_helpers.tpl index 19ea43ddef..314d556c11 100644 --- a/tools/kubeblocks_helm/pika-cluster/templates/_helpers.tpl +++ b/tools/kubeblocks_helm/pika-cluster/templates/_helpers.tpl @@ -59,38 +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 }} - -{{/* -Define pika group with shardingSpec -*/}} -{{- define "pika-group.shardingSpec" }} -- 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 }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml index ea8d679c92..aa4ad160d8 100644 --- a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml +++ b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml @@ -14,9 +14,37 @@ 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: - {{- include "pika-group.shardingSpec" . | indent 6 }} + - 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 }} From 5c27606ac148d33f1eadaf1d17024f0a439888fe Mon Sep 17 00:00:00 2001 From: Y-Rookie Date: Wed, 21 Feb 2024 19:21:08 +0800 Subject: [PATCH 6/6] add PIKA_CODIS_DASHBOARD_SVC_NAME var reference --- tools/kubeblocks_helm/pika/script/admin.sh | 3 +++ .../pika/templates/componentdefinition-pika-group.yaml | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/tools/kubeblocks_helm/pika/script/admin.sh b/tools/kubeblocks_helm/pika/script/admin.sh index 78730d687b..f2ce0143fd 100755 --- a/tools/kubeblocks_helm/pika/script/admin.sh +++ b/tools/kubeblocks_helm/pika/script/admin.sh @@ -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} diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml index 3b53ccd91f..f67df7cc44 100644 --- a/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml @@ -40,6 +40,15 @@ spec: - "-c" - "/script/admin.sh --rebalance" preCondition: ComponentReady + vars: + ## reference to the pika-codis-dashboard service + - name: PIKA_CODIS_DASHBOARD_SVC_NAME + valueFrom: + serviceVarRef: + compDef: pika-codis-dashboard + name: dashboard + optional: true + host: Optional runtime: containers: - name: pika