Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:pika-master-slave-cluster in kb #2903

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tools/kubeblocks_helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ kubectl port-forward svc/pika-cluster-codis-proxy 19000
# start new terminal
redis-cli -p 19000 info
```
### uninstall pika cluster
```bash
helm uninstall pika-cluster
helm uninstall pika
```

## Scale pika cluster

Expand All @@ -46,3 +51,29 @@ helm upgrade pika-cluster ./pika-cluster

### Scale in
scale in is not supported now.

## Install pika Master/Slave group by kubeblocks

### Install pika CD and pika Master/Slave
First,use helm install pika-master-slave-group componentdefinition and pika-master-slave cluster
```bash
cd ./tools/kubeblocks-helm/
helm install pika-master-slave ./pika-master-slave
helm install pika-master-slave-cluster ./pika-master-slave-cluster
```
Wait for pika-master-slave-pika-{index} pods until the status all to be `Running`.
```bash
kubectl get pods --watch
````
### connect to pika master-slave cluster
```bash
kubectl port-forward svc/pika-master-slave-cluster-pika 9221
#start new terminal
redis-cli -p 9221
```

### uninstall pika master-slave-cluster
```bash
helm uninstall pika-master-slave-cluster
helm uninstall pika-master-slave
```
23 changes: 23 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave-cluster/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
22 changes: 22 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave-cluster/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v2
name: pika-master-slave
description: A Pika Master-Slave Group Helm chart for KubeBlocks.

type: application

version: 0.9.0

appVersion: "3.5.3"

home: https://github.com/OpenAtomFoundation/pika
keywords:
- pika
- redis
- database
- nosql
- replication
- codis

maintainers:
- name: pika
url: https://github.com/OpenAtomFoundation/pika/tools/kubeblocks_helm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "pika-cluster.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "pika-cluster.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "pika-cluster.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "pika-cluster.labels" -}}
helm.sh/chart: {{ include "pika-cluster.chart" . }}
{{ include "pika-cluster.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "pika-cluster.selectorLabels" -}}
app.kubernetes.io/name: {{ include "pika-cluster.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "clustername" -}}
{{ include "pika-cluster.fullname" .}}
{{- end}}

{{/*
Create the name of the service account to use
*/}}
{{- define "pika-cluster.serviceAccountName" -}}
{{- default (printf "kb-%s" (include "clustername" .)) .Values.serviceAccount.name }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: apps.kubeblocks.io/v1alpha1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api version 应该有 beta1 了,可以用新的

kind: Cluster
metadata:
name: {{ include "clustername" . }}
namespace: {{ .Release.Namespace }}
labels: {{ include "pika-cluster.labels" . | nindent 4 }}
spec:
terminationPolicy: {{ .Values.terminationPolicy }}
affinity:
{{- with .Values.topologyKeys }}
topologyKeys: {{ . | toYaml | nindent 6 }}
{{- end }}
Comment on lines +10 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix syntax error and incorrect indentation in the affinity section

There is a syntax error and incorrect indentation in the affinity section at lines 10-12. The {{- with .Values.topologyKeys }} directive is improperly indented, causing YAML parsing issues as indicated by static analysis.

Apply the following diff to correct the indentation and fix the syntax error:

   affinity:
-    {{- with .Values.topologyKeys }}
-    topologyKeys: {{ . | toYaml | nindent 6 }}
-    {{- end }}
+  {{- with .Values.topologyKeys }}
+    topologyKeys: {{ . | toYaml | nindent 8 }}
+  {{- end }}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- with .Values.topologyKeys }}
topologyKeys: {{ . | toYaml | nindent 6 }}
{{- end }}
affinity:
{{- with .Values.topologyKeys }}
topologyKeys: {{ . | toYaml | nindent 8 }}
{{- end }}
Tools
yamllint

[warning] 11-11: wrong indentation: expected 2 but found 4

(indentation)


[error] 10-10: syntax error: expected the node content, but found '-'

(syntax)

{{- with $.Values.tolerations }}
tolerations: {{ . | toYaml | nindent 4 }}
{{- end }}
Comment on lines +13 to +15
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indentation issue in the tolerations section

The tolerations section at lines 13-15 has incorrect indentation, which could cause YAML parsing errors. The {{- with $.Values.tolerations }} block should be correctly aligned under spec.

Apply the following diff to correct the indentation:

-  {{- with $.Values.tolerations }}
-  tolerations: {{ . | toYaml | nindent 4 }}
-  {{- end }}
+{{- with $.Values.tolerations }}
+  tolerations: {{ . | toYaml | nindent 4 }}
+{{- end }}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- with $.Values.tolerations }}
tolerations: {{ . | toYaml | nindent 4 }}
{{- end }}
{{- with $.Values.tolerations }}
tolerations: {{ . | toYaml | nindent 4 }}
{{- end }}

componentSpecs:
- name: pika
componentDef: pika # Ref componentdefinition.name
enabledLogs: {{ $.Values.enabledLogs | toJson | indent 4 }}
replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure default value for replicas works as intended

At line 20, the expression for replicas may not provide the correct default when $.Values.slaveCount is undefined. The current default 2 is applied after the addition, which might not be the intended logic.

Consider updating the expression to apply the default to $.Values.slaveCount before the addition:

-      replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }}
+      replicas: {{ add (int (default 1 $.Values.slaveCount)) 1 }}

This ensures that if slaveCount is not set, it defaults to 1, resulting in replicas: 2.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }}
replicas: {{ add (int (default 1 $.Values.slaveCount)) 1 }}

serviceAccountName: {{ include "pika-cluster.serviceAccountName" $ }}
{{- 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 # ref componentDefinition.containers.volumeMounts.name
spec:
storageClassName: {{ .storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .size }}
{{- end }}
{{- end }}
Comment on lines +31 to +43
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct indentation in the volumeClaimTemplates section

The volumeClaimTemplates section at lines 31-43 may have incorrect indentation, which could cause YAML parsing errors. The Helm template directives and YAML keys need proper alignment.

Apply the following diff to correct the indentation:

       {{- if $.Values.persistence.enabled }}
-      volumeClaimTemplates:
+        volumeClaimTemplates:
           {{- with $.Values.persistence.pikaData }}
-          - name: data # ref componentDefinition.containers.volumeMounts.name
+            - name: data # ref componentDefinition.containers.volumeMounts.name
               spec:
                 storageClassName: {{ .storageClassName }}
                 accessModes:
                   - ReadWriteOnce
                 resources:
                   requests:
                     storage: {{ .size }}
           {{- end }}
       {{- end }}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- if $.Values.persistence.enabled }}
volumeClaimTemplates:
{{- with $.Values.persistence.pikaData }}
- name: data # ref componentDefinition.containers.volumeMounts.name
spec:
storageClassName: {{ .storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .size }}
{{- end }}
{{- end }}
{{- if $.Values.persistence.enabled }}
volumeClaimTemplates:
{{- with $.Values.persistence.pikaData }}
- name: data # ref componentDefinition.containers.volumeMounts.name
spec:
storageClassName: {{ .storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .size }}
{{- end }}
{{- end }}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: kb-{{ include "clustername" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "pika-cluster.labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
resources:
- events
verbs:
- create
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: kb-{{ include "clustername" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "pika-cluster.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: kb-{{ include "clustername" . }}
subjects:
- kind: ServiceAccount
name: {{ include "pika-cluster.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "pika-cluster.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "pika-cluster.labels" . | nindent 4 }}
52 changes: 52 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave-cluster/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Default values for pika.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

nameOverride: ""
fullnameOverride: ""

slaveCount: 1

terminationPolicy: Delete

clusterVersionOverride: ""

monitor:
enabled: false

switchPolicy:
type: Noop

resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
pikaGroup:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

命名问题

limits:
cpu: 500m
memory: 3Gi
requests:
cpu: 500m
memory: 1Gi

persistence:
enabled: true
pikaData:
storageClassName:
size: 10Gi

topologyKeys:
- kubernetes.io/hostname

## @param tolerations
## ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
##
tolerations: [ ]

#enabledLogs:
# - running

# The RBAC permission used by cluster component pod, now include event.create
serviceAccount:
name: ""
23 changes: 23 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
21 changes: 21 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: pika
description: A Pika Master Slave Group definition Helm chart for Kubernetes

type: application

version: 0.9.0

appVersion: "3.5.3"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用3.5.5吧


home: https://github.com/OpenAtomFoundation/pika
keywords:
- pika
- redis
- database
- nosql
- replication

maintainers:
- name: pika
url: https://github.com/OpenAtomFoundation/pika/tools/kubeblocks_helm
Loading
Loading