Skip to content

Commit

Permalink
refactor: use statefulset deploy greptimedb
Browse files Browse the repository at this point in the history
  • Loading branch information
daviderli614 committed Oct 12, 2023
1 parent 0a53335 commit 0c65012
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 119 deletions.
20 changes: 10 additions & 10 deletions charts/greptimedb-standalone/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "greptimedb-standalone.name" -}}
{{- define "greptimedb.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

Expand All @@ -10,7 +10,7 @@ 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 "greptimedb-standalone.fullname" -}}
{{- define "greptimedb.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
Expand All @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name.
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "greptimedb-standalone.chart" -}}
{{- define "greptimedb.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "greptimedb-standalone.labels" -}}
helm.sh/chart: {{ include "greptimedb-standalone.chart" . }}
{{ include "greptimedb-standalone.selectorLabels" . }}
{{- define "greptimedb.labels" -}}
helm.sh/chart: {{ include "greptimedb.chart" . }}
{{ include "greptimedb.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand All @@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/*
Selector labels
*/}}
{{- define "greptimedb-standalone.selectorLabels" -}}
app.kubernetes.io/name: {{ include "greptimedb-standalone.name" . }}
{{- define "greptimedb.selectorLabels" -}}
app.kubernetes.io/name: {{ include "greptimedb.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "greptimedb-standalone.serviceAccountName" -}}
{{- define "greptimedb.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "greptimedb-standalone.fullname" .) .Values.serviceAccount.name }}
{{- default (include "greptimedb.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
Expand Down
86 changes: 0 additions & 86 deletions charts/greptimedb-standalone/templates/deployment.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions charts/greptimedb-standalone/templates/podmonitor.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: {{ include "greptimedb-standalone.fullname" . }}
name: {{ include "greptimedb.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
release: prometheus
Expand All @@ -15,4 +15,4 @@ spec:
- {{ .Release.Namespace }}
selector:
matchLabels:
{{- include "greptimedb-standalone.selectorLabels" . | nindent 6 }}
{{- include "greptimedb.selectorLabels" . | nindent 6 }}
6 changes: 3 additions & 3 deletions charts/greptimedb-standalone/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "greptimedb-standalone.fullname" . }}
name: {{ include "greptimedb.fullname" . }}
labels:
{{- include "greptimedb-standalone.labels" . | nindent 4 }}
{{- include "greptimedb.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
Expand All @@ -28,4 +28,4 @@ spec:
targetPort: 4004
protocol: TCP
selector:
{{- include "greptimedb-standalone.selectorLabels" . | nindent 4 }}
{{- include "greptimedb.selectorLabels" . | nindent 4 }}
4 changes: 2 additions & 2 deletions charts/greptimedb-standalone/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "greptimedb-standalone.serviceAccountName" . }}
name: {{ include "greptimedb.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "greptimedb-standalone.labels" . | nindent 4 }}
{{- include "greptimedb.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
137 changes: 137 additions & 0 deletions charts/greptimedb-standalone/templates/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "greptimedb.fullname" . }}
namespace: {{ $.Release.Namespace }}
labels:
{{- include "greptimedb.labels" . | nindent 4 }}
{{- if not (empty .Values.annotations) }}
annotations:
{{- with .Values.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
spec:
replicas: 1
updateStrategy:
rollingUpdate:
partition: 0
serviceName: {{ include "greptimedb.fullname" . }}
{{- if and (semverCompare ">= 1.23-0" .Capabilities.KubeVersion.Version) (.Values.persistence.enableStatefulSetAutoDeletePVC) (.Values.persistence.enabled) }}
persistentVolumeClaimRetentionPolicy:
whenDeleted: Delete
whenScaled: Delete
{{- end }}
selector:
matchLabels:
{{- include "greptimedb.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "greptimedb.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ include "greptimedb.serviceAccountName" . }}
{{- if .Values.image.pullSecrets }}
imagePullSecrets:
{{- range .Values.image.pullSecrets }}
- name: {{ . }}
{{- end }}
{{- end }}
{{- if .Values.securityContext }}
securityContext:
{{- toYaml .Values.securityContext | nindent 8 }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
containers:
- name: {{ include "greptimedb.fullname" . }}
image: {{ printf "%s/%s:%s" .Values.image.registry .Values.image.repository .Values.image.tag }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.command }}
command:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.args }}
args:
{{- toYaml . | nindent 10 }}
{{- end }}
ports:
- containerPort: 4000
name: http
protocol: TCP
- containerPort: 4001
name: grpc
protocol: TCP
- containerPort: 4002
name: mysql
protocol: TCP
- containerPort: 4003
name: postgres
protocol: TCP
- containerPort: 4004
name: prom
protocol: TCP
{{- with .Values.env }}
env:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.envFrom }}
envFrom:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: tmp
mountPath: /tmp
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- tpl . $ | nindent 8 }}
{{- end }}
{{- with .Values.dnsConfig }}
dnsConfig:
{{- tpl . $ | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: tmp
emptyDir: {}
{{- if .Values.persistence.enabled }}
volumeClaimTemplates:
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: storage
spec:
accessModes:
- ReadWriteOnce
{{- with .Values.persistence.storageClass }}
storageClassName: {{ if (eq "-" .) }}""{{ else }}{{ . }}{{ end }}
{{- end }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- with .Values.persistence.selector }}
selector:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- end }}
Loading

0 comments on commit 0c65012

Please sign in to comment.