diff --git a/addons-cluster/apecloud-postgresql-cluster/templates/cluster.yaml b/addons-cluster/apecloud-postgresql-cluster/templates/cluster.yaml index eacd44741..2cd28b7e2 100644 --- a/addons-cluster/apecloud-postgresql-cluster/templates/cluster.yaml +++ b/addons-cluster/apecloud-postgresql-cluster/templates/cluster.yaml @@ -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" . }} \ No newline at end of file diff --git a/addons/apecloud-postgresql/templates/_helpers.tpl b/addons/apecloud-postgresql/templates/_helpers.tpl index f3f16f940..906e7f627 100644 --- a/addons/apecloud-postgresql/templates/_helpers.tpl +++ b/addons/apecloud-postgresql/templates/_helpers.tpl @@ -40,4 +40,21 @@ Generate scripts configmap {{ $path | base }}: |- {{- $.Files.Get $path | nindent 2 }} {{- end }} -{{- end }} \ No newline at end of file +{{- 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 -}} \ No newline at end of file diff --git a/addons/apecloud-postgresql/templates/clusterdefinition.yaml b/addons/apecloud-postgresql/templates/clusterdefinition.yaml index d4106d44f..dd74018b3 100644 --- a/addons/apecloud-postgresql/templates/clusterdefinition.yaml +++ b/addons/apecloud-postgresql/templates/clusterdefinition.yaml @@ -62,7 +62,7 @@ spec: command: - sh - -c - - "cp -r /bin/syncer /config /kubeblocks/" + - "cp -r /bin/syncer /tools/" volumeMounts: - name: data mountPath: {{ .Values.dataMountPath }} @@ -70,17 +70,15 @@ spec: 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" - -- @@ -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 @@ -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 @@ -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" . }} \ No newline at end of file diff --git a/addons/apecloud-postgresql/templates/cmpd-apepg.yaml b/addons/apecloud-postgresql/templates/cmpd-apepg.yaml new file mode 100644 index 000000000..6880a349c --- /dev/null +++ b/addons/apecloud-postgresql/templates/cmpd-apepg.yaml @@ -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 \ No newline at end of file diff --git a/addons/apecloud-postgresql/templates/cmpv.yaml b/addons/apecloud-postgresql/templates/cmpv.yaml new file mode 100644 index 000000000..f47e0f266 --- /dev/null +++ b/addons/apecloud-postgresql/templates/cmpv.yaml @@ -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 }} \ No newline at end of file diff --git a/addons/apecloud-postgresql/values.yaml b/addons/apecloud-postgresql/values.yaml index 1e80bc57f..f30906fe8 100644 --- a/addons/apecloud-postgresql/values.yaml +++ b/addons/apecloud-postgresql/values.yaml @@ -12,7 +12,7 @@ image: debug: false syncer: repository: apecloud/syncer - tag: "0.2.0" + tag: "0.3.2" clusterVersionOverride: "" @@ -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" \ No newline at end of file