Skip to content

Commit

Permalink
fix: apepg prestart crash in 0.9 (#1117)
Browse files Browse the repository at this point in the history
  • Loading branch information
kizuna-lek authored Oct 24, 2024
1 parent e56f9bb commit 982e119
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ metadata:
namespace: {{ .Release.Namespace }}
labels: {{ include "kblib.clusterLabels" . | nindent 4 }}
spec:
clusterVersionRef: {{ .Values.version }}
terminationPolicy: {{ .Values.extra.terminationPolicy }}
{{- include "kblib.affinity" . | indent 2 }}
clusterDefinitionRef: apecloud-postgresql # ref clusterdefinition.name
componentSpecs:
- name: postgresql
componentDefRef: postgresql # ref clusterdefinition componentDefs.name
componentDef: apecloud-postgresql14 # ref clusterdefinition componentDefs.name
{{- include "kblib.componentMonitor" . | indent 6 }}
replicas: {{ include "apecloud-postgresql-cluster.replicas" . }}
serviceAccountName: {{ include "kblib.serviceAccountName" . }}
19 changes: 18 additions & 1 deletion addons/apecloud-postgresql/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,21 @@ Generate scripts configmap
{{ $path | base }}: |-
{{- $.Files.Get $path | nindent 2 }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Define apecloud-postgresql component definition name prefix
*/}}
{{- define "apecloud-postgresql.componentDefNamePrefix" -}}
{{- printf "apecloud-postgresql-" -}}
{{- end -}}
{{/*
Define apecloud-postgresql14 component definition name
*/}}
{{- define "apecloud-postgresql.compDefApecloudPostgresql14" -}}
{{- if eq (len .Values.resourceNamePrefix) 0 -}}
apecloud-postgresql14
{{- else -}}
{{- .Values.resourceNamePrefix -}}
{{- end -}}
{{- end -}}
26 changes: 18 additions & 8 deletions addons/apecloud-postgresql/templates/clusterdefinition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,23 @@ spec:
command:
- sh
- -c
- "cp -r /bin/syncer /config /kubeblocks/"
- "cp -r /bin/syncer /tools/"
volumeMounts:
- name: data
mountPath: {{ .Values.dataMountPath }}
- name: postgresql-config
mountPath: {{ .Values.confMountPath }}
- name: scripts
mountPath: /kb-scripts
- name: kubeblocks
mountPath: /kubeblocks
- name: tools
mountPath: /tools
containers:
- name: postgresql
imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }}
securityContext:
runAsUser: 0
command:
- /kubeblocks/syncer
- --config-path
- /kubeblocks/config/components
- /tools/syncer
- --port
- "3601"
- --
Expand All @@ -95,8 +93,8 @@ spec:
mountPath: {{ .Values.confMountPath }}
- name: scripts
mountPath: /kb-scripts
- name: kubeblocks
mountPath: /kubeblocks
- name: tools
mountPath: /tools
ports:
- name: tcp-postgresql
containerPort: 5432
Expand Down Expand Up @@ -139,6 +137,8 @@ spec:
name: $(CONN_CREDENTIAL_SECRET_NAME)
key: password
optional: false
- name: KB_SERVICE_CHARACTER_TYPE
value: apecloud-postgresql
- name: POSTGRESQL_PORT_NUMBER
value: "5432"
- name: PGDATA
Expand Down Expand Up @@ -188,3 +188,13 @@ spec:
statements:
creation: CREATE USER $(USERNAME) SUPERUSER PASSWORD '$(PASSWD)';
deletion: DROP USER IF EXISTS $(USERNAME);
topologies:
- name: standalone
components:
- name: postgresql
compDef: {{ include "apecloud-postgresql.compDefApecloudPostgresql14" . }}
default: true
- name: raftGroup
components:
- name: postgresql
compDef: {{ include "apecloud-postgresql.compDefApecloudPostgresql14" . }}
182 changes: 182 additions & 0 deletions addons/apecloud-postgresql/templates/cmpd-apepg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ComponentDefinition
metadata:
name: {{ include "apecloud-postgresql.compDefApecloudPostgresql14" . }}
labels:
{{- include "apecloud-postgresql.labels" . | nindent 4 }}
spec:
provider: kubeblocks
description: ApeCloud PostgreSQL is a database that is compatible with PostgreSQL syntax and achieves high availability through the utilization of the RAFT consensus protocol.
serviceKind: postgresql
serviceVersion: {{ .Values.componentServiceVersion.apecloudPostgresql14 }}
services:
- name: default
spec:
ports:
- name: postgresql
port: 3306
targetPort: postgresql
roleSelector: leader
- name: replication
serviceName: replication
spec:
ports:
- name: raft
port: 13306
targetPort: raft
podService: true
disableAutoProvision: true
volumes:
- highWatermark: 0
name: data
needSnapshot: false
roles:
- name: leader
serviceable: true
writable: true
votable: true
- name: follower
serviceable: true
writable: false
votable: true
- name: learner
serviceable: false
writable: false
votable: false
configs:
- name: postgresql-consensusset-configuration
templateRef: apecloud-postgresql14-configuration
constraintRef: apecloud-postgresql14-cc
keys:
- postgresql.conf
namespace: {{ .Release.Namespace }}
volumeName: postgresql-config
defaultMode: 0444
scripts:
- name: apecloud-postgresql-scripts
templateRef: apecloud-postgresql-scripts
namespace: {{ .Release.Namespace }}
volumeName: scripts
defaultMode: 0555
vars:
- name: POSTGRES_USER
valueFrom:
credentialVarRef:
compDef: {{ include "apecloud-postgresql.compDefApecloudPostgresql14" . }}
name: postgres
optional: false
username: Required
- name: POSTGRES_PASSWORD
valueFrom:
credentialVarRef:
compDef: {{ include "apecloud-postgresql.compDefApecloudPostgresql14" . }}
name: postgres
optional: false
password: Required
systemAccounts:
- name: postgres
initAccount: true
passwordGenerationPolicy:
length: 10
numDigits: 5
numSymbols: 0
letterCase: MixedCases
- name: kbadmin
passwordGenerationPolicy:
length: 10
letterCase: MixedCases
numDigits: 5
numSymbols: 0
statement: CREATE USER $(USERNAME) SUPERUSER PASSWORD '$(PASSWD)';
lifecycleActions:
roleProbe:
builtinHandler: apecloud-postgresql
periodSeconds: 1
timeoutSeconds: 1
accountProvision:
customHandler:
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}
exec:
command:
- psql
args:
- -h$(KB_ACCOUNT_ENDPOINT)
- -c
- $(KB_ACCOUNT_STATEMENT)
env:
- name: PGUSER
value: $(POSTGRES_USER)
- name: PGPASSWORD
value: $(POSTGRES_PASSWORD)
runtime:
initContainers:
- command:
- sh
- -c
- cp -r /bin/syncer /tools/
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.syncer.repository }}:{{ .Values.image.syncer.tag }}
imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }}
name: init-syncer
volumeMounts:
- mountPath: /tools
name: tools
containers:
- command:
- /tools/syncer
- --port
- '3601'
- --
- docker-entrypoint.sh
- postgres
env:
- name: ALLOW_NOSSL
value: 'true'
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: PGUSER
value: $(POSTGRES_USER)
- name: PGPASSWORD
value: $(POSTGRES_PASSWORD)
- name: KB_SERVICE_CHARACTER_TYPE
value: apecloud-postgresql
- name: POSTGRESQL_PORT_NUMBER
value: '5432'
- name: PGDATA
value: {{ .Values.dataPath }}
- name: PGCONF
value: {{ .Values.confPath }}
- name: POSTGRESQL_MOUNTED_CONF_DIR
value: {{ .Values.confMountPath }}
image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: IfNotPresent
name: postgresql
ports:
- containerPort: 5432
name: tcp-postgresql
- containerPort: 15432
name: raft
securityContext:
runAsUser: 0
volumeMounts:
- mountPath: /dev/shm
name: dshm
- mountPath: {{ .Values.dataMountPath }}
name: data
- mountPath: {{ .Values.confMountPath }}
name: postgresql-config
- mountPath: /kb-scripts
name: scripts
- mountPath: /tools
name: tools
volumes:
- emptyDir:
medium: Memory
name: dshm
17 changes: 17 additions & 0 deletions addons/apecloud-postgresql/templates/cmpv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ComponentVersion
metadata:
name: apecloud-postgresql
labels:
{{- include "apecloud-postgresql.labels" . | nindent 4 }}
spec:
compatibilityRules:
- compDefs:
- {{ include "apecloud-postgresql.compDefApecloudPostgresql14" . }}
releases:
- 14.11.0
releases:
- name: 14.11.0
serviceVersion: 14.11.0
images:
postgresql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}
10 changes: 9 additions & 1 deletion addons/apecloud-postgresql/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ image:
debug: false
syncer:
repository: apecloud/syncer
tag: "0.2.0"
tag: "0.3.2"

clusterVersionOverride: ""

Expand Down Expand Up @@ -47,3 +47,11 @@ shmVolume:
## sizeLimit: 1Gi
##
sizeLimit: ""

## @param resourceNamePrefix Prefix for all resources name created by this chart, that can avoid name conflict
## if you install multiple releases of this chart.
## If specified, the cluster definition will use it as name.
resourceNamePrefix: ""
## @param componentServiceVersion define default serviceVersion of each Component
componentServiceVersion:
apecloudPostgresql14: "14.11.0"

0 comments on commit 982e119

Please sign in to comment.