Skip to content

Commit

Permalink
postgresql addon definition support multiverion sync with chart version
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie committed Sep 6, 2024
1 parent 9b3699b commit b34366e
Show file tree
Hide file tree
Showing 19 changed files with 189 additions and 64 deletions.
139 changes: 129 additions & 10 deletions addons/postgresql/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,44 +60,163 @@ Generate scripts configmap
{{- end }}
{{- end }}

{{/*
Define postgresql cluster definition name
*/}}
{{- define "postgresql.clusterDefinition" -}}
postgresql
{{- end -}}

{{/*
Define postgresql component version name
*/}}
{{- define "postgresql.componentVersion" -}}
postgresql
{{- end -}}

{{/*
Define postgresql component definition name prefix
*/}}
{{- define "postgresql.componentDefNamePrefix" -}}
{{- printf "postgresql-" -}}
{{- end -}}

{{/*
Define postgresql 12 component definition name prefix
*/}}
{{- define "postgresql12.componentDefNamePrefix" -}}
{{- printf "postgresql-12-" -}}
{{- end -}}

{{/*
Define postgresql 14 component definition name prefix
*/}}
{{- define "postgresql14.componentDefNamePrefix" -}}
{{- printf "postgresql-14-" -}}
{{- end -}}

{{/*
Define postgresql 15 component definition name prefix
*/}}
{{- define "postgresql15.componentDefNamePrefix" -}}
{{- printf "postgresql-15-" -}}
{{- end -}}

{{/*
Define postgresql12 component definition name
*/}}
{{- define "postgresql.compDefPostgresql12" -}}
{{- define "postgresql12.compDefName" -}}
{{- if eq (len .Values.componentDefinitionVersion.postgresql12) 0 -}}
postgresql-12
postgresql-12-{{ .Chart.Version }}
{{- else -}}
{{ include "postgresql.componentDefNamePrefix" . }}{{ .Values.componentDefinitionVersion.postgresql12 }}
{{ include "postgresql.componentDefNamePrefix" . }}{{ .Values.componentDefinitionVersion.postgresql12 }}-{{ .Chart.Version }}
{{- end -}}
{{- end -}}

{{/*
Define postgresql14 component definition name
Define postgresql14 component definition name with Chart.Version suffix
*/}}
{{- define "postgresql.compDefPostgresql14" -}}
{{- define "postgresql14.compDefName" -}}
{{- if eq (len .Values.componentDefinitionVersion.postgresql14) 0 -}}
postgresql-14
postgresql-14-{{ .Chart.Version }}
{{- else -}}
{{ include "postgresql.componentDefNamePrefix" . }}{{ .Values.componentDefinitionVersion.postgresql14 }}
{{ include "postgresql.componentDefNamePrefix" . }}{{ .Values.componentDefinitionVersion.postgresql14 }}-{{ .Chart.Version }}
{{- end -}}
{{- end -}}

{{/*
Define postgresql15 component definition name
*/}}
{{- define "postgresql.compDefPostgresql15" -}}
{{- define "postgresql15.compDefName" -}}
{{- if eq (len .Values.componentDefinitionVersion.postgresql15) 0 -}}
postgresql-15
postgresql-15-{{ .Chart.Version }}
{{- else -}}
{{ include "postgresql.componentDefNamePrefix" . }}{{ .Values.componentDefinitionVersion.postgresql15 }}
{{ include "postgresql.componentDefNamePrefix" . }}{{ .Values.componentDefinitionVersion.postgresql15 }}-{{ .Chart.Version }}
{{- end -}}
{{- end -}}

{{/*
Define postgresql12 component configuration template name
*/}}
{{- define "postgresql12.configurationTemplate" -}}
postgresql12-configuration-{{ .Chart.Version }}
{{- end -}}

{{/*
Define postgresql14 component configuration template name
*/}}
{{- define "postgresql14.configurationTemplate" -}}
postgresql14-configuration-{{ .Chart.Version }}
{{- end -}}

{{/*
Define postgresql15 component configuration template name
*/}}
{{- define "postgresql15.configurationTemplate" -}}
postgresql15-configuration-{{ .Chart.Version }}
{{- end -}}

{{/*
Define postgresql12 component config constraint name
*/}}
{{- define "postgresql12.configConstraint" -}}
postgresql12-cc-{{ .Chart.Version }}
{{- end -}}

{{/*
Define postgresql14 component config constraint name
*/}}
{{- define "postgresql14.configConstraint" -}}
postgresql14-cc-{{ .Chart.Version }}
{{- end -}}

{{/*
Define postgresql15 component config constraint name
*/}}
{{- define "postgresql15.configConstraint" -}}
postgresql15-cc-{{ .Chart.Version }}
{{- end -}}

{{/*
Define postgresql12 component metrice configuration name
*/}}
{{- define "postgresql12.metricsConfiguration" -}}
postgresql12-custom-metrics-{{ .Chart.Version }}
{{- end -}}

{{/*
Define postgresql14 component metrice configuration name
*/}}
{{- define "postgresql14.metricsConfiguration" -}}
postgresql14-custom-metrics-{{ .Chart.Version }}
{{- end -}}

{{/*
Define postgresql15 component metrice configuration name
*/}}
{{- define "postgresql15.metricsConfiguration" -}}
postgresql15-custom-metrics-{{ .Chart.Version }}
{{- end -}}

{{/*
Define postgresql scripts configMap template name
*/}}
{{- define "postgresql.scriptsTemplate" -}}
postgresql-scripts-{{ .Chart.Version }}
{{- end -}}

{{/*
Define postgresql patroni reload scripts template name
*/}}
{{- define "postgresql.patroniReloadScriptsTemplate" -}}
patroni-reload-scripts-{{ .Chart.Version }}
{{- end -}}

{{/*
Define pgbouncer configuration template name
*/}}
{{- define "pgbouncer.configurationTemplate" -}}
pgbouncer-configuration-{{ .Chart.Version }}
{{- end -}}

{{/*
Expand Down
14 changes: 10 additions & 4 deletions addons/postgresql/templates/backuppolicytemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ metadata:
}
spec:
backupPolicies:
- componentDefs: [postgresql-14, postgresql-12]
- componentDefs:
- {{ include "postgresql12.compDefName" . }}
- {{ include "postgresql14.compDefName" . }}
- {{ include "postgresql15.compDefName" . }}
target:
role: secondary
fallbackRole: primary
Expand All @@ -33,11 +36,14 @@ spec:
- key: IMAGE_TAG
valueFrom:
componentDef:
- names: [postgresql-12]
- names:
- {{ include "postgresql12.compDefName" . }}
mappingValue: "12.15.0-pgvector-v0.6.1"
- names: [postgresql-14]
- names:
- {{ include "postgresql14.compDefName" . }}
mappingValue: "14.8.0-pgvector-v0.6.1"
- names: [postgresql-15]
- names:
- {{ include "postgresql15.compDefName" . }}
mappingValue: "15.7.0"
targetVolumes:
volumeMounts:
Expand Down
2 changes: 1 addition & 1 deletion addons/postgresql/templates/clusterdefinition.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ClusterDefinition
metadata:
name: postgresql
name: {{ include "postgresql.clusterDefinition" . }}
labels:
{{- include "postgresql.labels" . | nindent 4 }}
spec:
Expand Down
22 changes: 11 additions & 11 deletions addons/postgresql/templates/componentdefinition-12.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ComponentDefinition
metadata:
name: {{ include "postgresql.compDefPostgresql12" . }}
name: {{ include "postgresql12.compDefName" . }}
labels:
{{- include "postgresql.labels" . | nindent 4 }}
spec:
Expand Down Expand Up @@ -48,8 +48,8 @@ spec:
scrapePath: /metrics
configs:
- name: postgresql-configuration
templateRef: postgresql12-configuration
constraintRef: postgresql12-cc
templateRef: {{ include "postgresql12.configurationTemplate" . }}
constraintRef: {{ include "postgresql12.configConstraint" . }}
keys:
- postgresql.conf
namespace: {{ .Release.Namespace }}
Expand All @@ -65,7 +65,7 @@ spec:
volumeName: pgbouncer-config
defaultMode: 0777
- name: postgresql-custom-metrics
templateRef: postgresql12-custom-metrics
templateRef: {{ include "postgresql12.metricsConfiguration" . }}
namespace: {{ .Release.Namespace }}
volumeName: postgresql-custom-metrics
defaultMode: 0444
Expand All @@ -88,14 +88,14 @@ spec:
- name: POSTGRES_COMPONENT_NAME
valueFrom:
componentVarRef:
compDef: {{ include "postgresql.compDefPostgresql12" . }}
compDef: {{ include "postgresql12.compDefName" . }}
optional: false
componentName: Required
## the component short name of postgres, it's the short name of postgres component without clusterName prefix
- name: POSTGRES_COMPONENT_SHORT_NAME
valueFrom:
componentVarRef:
compDef: {{ include "postgresql.compDefPostgresql12" . }}
compDef: {{ include "postgresql12.compDefName" . }}
optional: false
shortName: Required
## the etcd version if postgres patroni use etcd as DCS
Expand All @@ -111,36 +111,36 @@ spec:
- name: POSTGRES_USER
valueFrom:
credentialVarRef:
compDef: {{ include "postgresql.compDefPostgresql12" . }}
compDef: {{ include "postgresql12.compDefName" . }}
name: postgres
optional: false
username: Required
- name: POSTGRES_PASSWORD
valueFrom:
credentialVarRef:
compDef: {{ include "postgresql.compDefPostgresql12" . }}
compDef: {{ include "postgresql12.compDefName" . }}
name: postgres
optional: false
password: Required
## the postgres pod name list for each pod, the value format is "pod1,pod2,..."
- name: POSTGRES_POD_NAME_LIST
valueFrom:
componentVarRef:
compDef: {{ include "postgresql.compDefPostgresql12" . }}
compDef: {{ include "postgresql12.compDefName" . }}
optional: false
podNames: Required
## the postgres pod fqdn list for each pod, the value format is "pod1FQDN,pod2FQDN,..."
- name: POSTGRES_POD_FQDN_LIST
valueFrom:
componentVarRef:
compDef: {{ include "postgresql.compDefPostgresql12" . }}
compDef: {{ include "postgresql12.compDefName" . }}
optional: false
podFQDNs: Required
## the postgres primary pod name which is dynamically selected, caution to use it
- name: POSTGRES_PRIMARY_POD_NAME
valueFrom:
componentVarRef:
compDef: {{ include "postgresql.compDefPostgresql12" . }}
compDef: {{ include "postgresql12.compDefName" . }}
optional: true
podNamesForRole:
role: primary
Expand Down
22 changes: 11 additions & 11 deletions addons/postgresql/templates/componentdefinition-14.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ComponentDefinition
metadata:
name: {{ include "postgresql.compDefPostgresql14" . }}
name: {{ include "postgresql14.compDefName" . }}
labels:
{{- include "postgresql.labels" . | nindent 4 }}
spec:
Expand Down Expand Up @@ -48,8 +48,8 @@ spec:
scrapePath: /metrics
configs:
- name: postgresql-configuration
templateRef: postgresql14-configuration
constraintRef: postgresql14-cc
templateRef: {{ include "postgresql14.configurationTemplate" . }}
constraintRef: {{ include "postgresql14.configConstraint" . }}
keys:
- postgresql.conf
namespace: {{ .Release.Namespace }}
Expand All @@ -65,7 +65,7 @@ spec:
volumeName: pgbouncer-config
defaultMode: 0777
- name: postgresql-custom-metrics
templateRef: postgresql14-custom-metrics
templateRef: {{ include "postgresql14.metricsConfiguration" . }}
namespace: {{ .Release.Namespace }}
volumeName: postgresql-custom-metrics
defaultMode: 0444
Expand All @@ -88,14 +88,14 @@ spec:
- name: POSTGRES_COMPONENT_NAME
valueFrom:
componentVarRef:
compDef: {{ include "postgresql.compDefPostgresql14" . }}
compDef: {{ include "postgresql14.compDefName" . }}
optional: false
componentName: Required
## the component short name of postgres, it's the short name of postgres component without clusterName prefix
- name: POSTGRES_COMPONENT_SHORT_NAME
valueFrom:
componentVarRef:
compDef: {{ include "postgresql.compDefPostgresql14" . }}
compDef: {{ include "postgresql14.compDefName" . }}
optional: false
shortName: Required
## the etcd version if postgres patroni use etcd as DCS
Expand All @@ -111,36 +111,36 @@ spec:
- name: POSTGRES_USER
valueFrom:
credentialVarRef:
compDef: {{ include "postgresql.compDefPostgresql14" . }}
compDef: {{ include "postgresql14.compDefName" . }}
name: postgres
optional: false
username: Required
- name: POSTGRES_PASSWORD
valueFrom:
credentialVarRef:
compDef: {{ include "postgresql.compDefPostgresql14" . }}
compDef: {{ include "postgresql14.compDefName" . }}
name: postgres
optional: false
password: Required
## the postgres pod name list for each pod, the value format is "pod1,pod2,..."
- name: POSTGRES_POD_NAME_LIST
valueFrom:
componentVarRef:
compDef: {{ include "postgresql.compDefPostgresql14" . }}
compDef: {{ include "postgresql14.compDefName" . }}
optional: false
podNames: Required
## the postgres pod fqdn list for each pod, the value format is "pod1FQDN,pod2FQDN,..."
- name: POSTGRES_POD_FQDN_LIST
valueFrom:
componentVarRef:
compDef: {{ include "postgresql.compDefPostgresql14" . }}
compDef: {{ include "postgresql14.compDefName" . }}
optional: false
podFQDNs: Required
## the postgres primary pod name which is dynamically selected, caution to use it
- name: POSTGRES_PRIMARY_POD_NAME
valueFrom:
componentVarRef:
compDef: {{ include "postgresql.compDefPostgresql14" . }}
compDef: {{ include "postgresql14.compDefName" . }}
optional: true
podNamesForRole:
role: primary
Expand Down
Loading

0 comments on commit b34366e

Please sign in to comment.