From bab84894d69ad8173184fbc4a1af4ee81f592df4 Mon Sep 17 00:00:00 2001 From: Lek Date: Fri, 15 Nov 2024 16:54:59 +0800 Subject: [PATCH] chore: upgrade apecloud postgresql to v1.0 api (#1182) --- .../templates/cluster.yaml | 2 +- .../apecloud-postgresql/values.yaml | 2 +- .../config/pg14-config-effect-scope.yaml | 346 ++++++++++++++++-- .../reloader/update-parameter.sh | 27 ++ .../scripts-ut-spec/update_parameter_spec.sh | 40 ++ .../templates/_helpers.tpl | 293 ++++++++++++++- .../templates/clusterdefinition.yaml | 2 +- .../templates/cmpd-apepg.yaml | 200 +--------- .../apecloud-postgresql/templates/cmpv.yaml | 4 +- .../templates/configconstraint.yaml | 20 +- .../templates/configmap.yaml | 4 +- .../templates/scripts.yaml | 15 +- addons/apecloud-postgresql/values.yaml | 9 +- 13 files changed, 716 insertions(+), 248 deletions(-) create mode 100644 addons/apecloud-postgresql/reloader/update-parameter.sh create mode 100644 addons/apecloud-postgresql/scripts-ut-spec/update_parameter_spec.sh diff --git a/addons-cluster/apecloud-postgresql/templates/cluster.yaml b/addons-cluster/apecloud-postgresql/templates/cluster.yaml index 739137993..3c3b16a7a 100644 --- a/addons-cluster/apecloud-postgresql/templates/cluster.yaml +++ b/addons-cluster/apecloud-postgresql/templates/cluster.yaml @@ -10,7 +10,7 @@ spec: topology: apecloud-postgresql componentSpecs: - name: postgresql - componentDef: apecloud-postgresql14 + serviceVersion: {{ .Values.version }} {{- include "kblib.componentMonitor" . | indent 6 }} replicas: {{ include "apecloud-postgresql-cluster.replicas" . }} serviceAccountName: {{ include "kblib.serviceAccountName" . }} diff --git a/addons-cluster/apecloud-postgresql/values.yaml b/addons-cluster/apecloud-postgresql/values.yaml index bfbc6df04..307e3893a 100644 --- a/addons-cluster/apecloud-postgresql/values.yaml +++ b/addons-cluster/apecloud-postgresql/values.yaml @@ -4,7 +4,7 @@ ## @param version PostgreSQL cluster version ## -version: ac-postgresql-14.10 +version: 14.11.0 ## @param mode postgresql cluster topology mode, standalone, raftGroup ## diff --git a/addons/apecloud-postgresql/config/pg14-config-effect-scope.yaml b/addons/apecloud-postgresql/config/pg14-config-effect-scope.yaml index f01623b21..fc10edd4d 100644 --- a/addons/apecloud-postgresql/config/pg14-config-effect-scope.yaml +++ b/addons/apecloud-postgresql/config/pg14-config-effect-scope.yaml @@ -1,60 +1,332 @@ -# Patroni bootstrap parameters staticParameters: - - shared_buffers + # postmaster + - archive_mode + - autovacuum_freeze_max_age + - autovacuum_max_workers + - autovacuum_multixact_freeze_max_age + - bonjour + - bonjour_name + - cluster_name + - config_file + - data_directory + - data_sync_retry + - dynamic_shared_memory_type + - event_source + - external_pid_file + - hba_file + - hot_standby + - huge_pages + - huge_page_size + - ident_file + - ignore_invalid_pages + - jit_provider + - listen_addresses - logging_collector - - log_destination - - log_directory - - log_filename - - log_file_mode - - log_rotation_age - - log_truncate_on_rotation - - ssl - - ssl_ca_file - - ssl_crl_file - - ssl_cert_file - - ssl_key_file + - max_connections + - max_files_per_process + - max_locks_per_transaction + - max_logical_replication_workers + - max_pred_locks_per_transaction + - max_prepared_transactions + - max_replication_slots + - max_wal_senders + - max_worker_processes + - min_dynamic_shared_memory + - old_snapshot_threshold + - port + - recovery_target + - recovery_target_action + - recovery_target_inclusive + - recovery_target_lsn + - recovery_target_name + - recovery_target_time + - recovery_target_timeline + - recovery_target_xid + - shared_buffers + - shared_memory_type - shared_preload_libraries - - bg_mon.listen_address - - bg_mon.history_buckets - - pg_stat_statements.track_utility - - extwlist.extensions - - extwlist.custom_path + - superuser_reserved_connections + - track_activity_query_size + - track_commit_timestamp + - unix_socket_directories + - unix_socket_group + - unix_socket_permissions + - wal_buffers + - wal_level + - wal_log_hints -immutableParameters: +dynamicParameters: + # sighup + - archive_cleanup_command + - archive_command - archive_timeout - - backtrace_functions - - config_file - - cron.use_background_workers - - data_directory + - authentication_timeout + - autovacuum + - autovacuum_analyze_scale_factor + - autovacuum_analyze_threshold + - autovacuum_naptime + - autovacuum_vacuum_cost_delay + - autovacuum_vacuum_cost_limit + - autovacuum_vacuum_insert_scale_factor + - autovacuum_vacuum_insert_threshold + - autovacuum_vacuum_scale_factor + - autovacuum_vacuum_threshold + - autovacuum_work_mem + - bgwriter_delay + - bgwriter_flush_after + - bgwriter_lru_maxpages + - bgwriter_lru_multiplier + - checkpoint_completion_target + - checkpoint_flush_after + - checkpoint_timeout + - checkpoint_warning - db_user_namespace - - exit_on_error - fsync - full_page_writes - - hba_file - - ident_file - - ignore_invalid_pages - - listen_addresses - - lo_compat_privileges + - hot_standby_feedback + - krb_caseins_users + - krb_server_keyfile + - log_autovacuum_min_duration + - log_checkpoints + - log_destination - log_directory - log_file_mode - - logging_collector + - log_filename + - log_hostname - log_line_prefix + - log_recovery_conflict_waits + - log_rotation_age + - log_rotation_size - log_timezone - log_truncate_on_rotation - - port - - rds.max_tcp_buffers + - max_pred_locks_per_page + - max_pred_locks_per_relation + - max_slot_wal_keep_size + - max_standby_archive_delay + - max_standby_streaming_delay + - max_sync_workers_per_subscription + - max_wal_size + - min_wal_size + - pre_auth_delay + - primary_conninfo + - primary_slot_name + - promote_trigger_file + - recovery_end_command - recovery_init_sync_method + - recovery_min_apply_delay + - remove_temp_files_after_crash - restart_after_crash + - restore_command - ssl - ssl_ca_file - ssl_cert_file - ssl_ciphers + - ssl_crl_dir + - ssl_crl_file + - ssl_dh_params_file + - ssl_ecdh_curve - ssl_key_file + - ssl_max_protocol_version + - ssl_min_protocol_version + - ssl_passphrase_command + - ssl_passphrase_command_supports_reload + - ssl_prefer_server_ciphers - stats_temp_directory - - superuser_reserved_connections - - unix_socket_directories - - unix_socket_group - - unix_socket_permissions - - update_process_title + - synchronous_standby_names + - syslog_facility + - syslog_ident + - syslog_sequence_numbers + - syslog_split_messages + - trace_recovery_messages + - vacuum_defer_cleanup_age + - wal_keep_size - wal_receiver_create_temp_slot + - wal_receiver_status_interval + - wal_receiver_timeout + - wal_retrieve_retry_interval - wal_sync_method + - wal_writer_delay + - wal_writer_flush_after + # backend + - ignore_system_indexes + - post_auth_delay + # user + - application_name + - array_nulls + - backend_flush_after + - backslash_quote + - bytea_output + - check_function_bodies + - client_connection_check_interval + - client_encoding + - client_min_messages + - commit_siblings + - constraint_exclusion + - cpu_index_tuple_cost + - cpu_operator_cost + - cpu_tuple_cost + - cursor_tuple_fraction + - DateStyle + - debug_pretty_print + - debug_print_parse + - debug_print_plan + - debug_print_rewritten + - default_statistics_target + - default_table_access_method + - default_tablespace + - default_text_search_config + - default_toast_compression + - default_transaction_deferrable + - default_transaction_isolation + - default_transaction_read_only + - effective_cache_size + - effective_io_concurrency + - enable_async_append + - enable_bitmapscan + - enable_gathermerge + - enable_hashagg + - enable_hashjoin + - enable_incremental_sort + - enable_indexonlyscan + - enable_indexscan + - enable_material + - enable_memoize + - enable_mergejoin + - enable_nestloop + - enable_parallel_append + - enable_parallel_hash + - enable_partition_pruning + - enable_partitionwise_aggregate + - enable_partitionwise_join + - enable_seqscan + - enable_sort + - enable_tidscan + - escape_string_warning + - exit_on_error + - extra_float_digits + - force_parallel_mode + - from_collapse_limit + - geqo + - geqo_effort + - geqo_generations + - geqo_pool_size + - geqo_seed + - geqo_selection_bias + - geqo_threshold + - gin_fuzzy_search_limit + - gin_pending_list_limit + - hash_mem_multiplier + - idle_in_transaction_session_timeout + - idle_session_timeout + - IntervalStyle + - jit + - jit_above_cost + - jit_expressions + - jit_inline_above_cost + - jit_optimize_above_cost + - jit_tuple_deforming + - join_collapse_limit + - lc_monetary + - lc_numeric + - lc_time + - local_preload_libraries + - lock_timeout + - logical_decoding_work_mem + - log_parameter_max_length_on_error + - maintenance_io_concurrency + - maintenance_work_mem + - max_parallel_maintenance_workers + - max_parallel_workers + - max_parallel_workers_per_gather + - min_parallel_index_scan_size + - min_parallel_table_scan_size + - parallel_leader_participation + - parallel_setup_cost + - parallel_tuple_cost + - password_encryption + - plan_cache_mode + - quote_all_identifiers + - random_page_cost + - restrict_nonsystem_relation_kind + - row_security + - search_path + - seq_page_cost + - standard_conforming_strings + - statement_timeout + - synchronize_seqscans + - synchronous_commit + - tcp_keepalives_count + - tcp_keepalives_idle + - tcp_keepalives_interval + - tcp_user_timeout + - temp_buffers + - temp_tablespaces + - TimeZone + - timezone_abbreviations + - trace_notify + - trace_sort + - transaction_deferrable + - transaction_isolation + - transaction_read_only + - transform_null_equals + - vacuum_cost_delay + - vacuum_cost_limit + - vacuum_cost_page_dirty + - vacuum_cost_page_hit + - vacuum_cost_page_miss + - vacuum_failsafe_age + - vacuum_freeze_min_age + - vacuum_freeze_table_age + - vacuum_multixact_failsafe_age + - vacuum_multixact_freeze_min_age + - vacuum_multixact_freeze_table_age + - wal_sender_timeout + - wal_skip_threshold + - work_mem + - xmlbinary + - xmloption + # superuser + - allow_in_place_tablespaces + - allow_system_table_mods + - backtrace_functions + - commit_delay + - compute_query_id + - deadlock_timeout + - debug_discard_caches + - dynamic_library_path + - ignore_checksum_failure + - jit_dump_bitcode + - lc_messages + - lo_compat_privileges + - log_duration + - log_error_verbosity + - log_executor_stats + - log_lock_waits + - log_min_duration_sample + - log_min_duration_statement + - log_min_error_statement + - log_min_messages + - log_parameter_max_length + - log_parser_stats + - log_planner_stats + - log_replication_commands + - log_statement + - log_statement_sample_rate + - log_statement_stats + - log_temp_files + - log_transaction_sample_rate + - max_stack_depth + - session_preload_libraries + - session_replication_role + - temp_file_limit + - track_activities + - track_counts + - track_functions + - track_io_timing + - track_wal_io_timing + - update_process_title + - wal_compression + - wal_consistency_checking + - wal_init_zero + - wal_recycle + - zero_damaged_pages diff --git a/addons/apecloud-postgresql/reloader/update-parameter.sh b/addons/apecloud-postgresql/reloader/update-parameter.sh new file mode 100644 index 000000000..f81f63f9e --- /dev/null +++ b/addons/apecloud-postgresql/reloader/update-parameter.sh @@ -0,0 +1,27 @@ +#!/bin/sh +set -e + +do_reload() { + if [ -z "$1" ]; then + echo "missing param name" >&2 + return 1 + fi + if [ -z "$2" ]; then + echo "missing value" >&2 + return 1 + fi + + paramName="$1" + paramValue="$2" + + PGPASSWORD=${POSTGRES_PASSWORD} psql -h localhost -U "${POSTGRES_USER}" -c "alter system set ${paramName}='${paramValue}'" + PGPASSWORD=${POSTGRES_PASSWORD} psql -h localhost -U "${POSTGRES_USER}" -c "select pg_reload_conf()" +} + +# if test by shell spec include, just return 0 +if [ "${__SOURCED__:+x}" ]; then + return 0 +fi + +do_reload "$@" + diff --git a/addons/apecloud-postgresql/scripts-ut-spec/update_parameter_spec.sh b/addons/apecloud-postgresql/scripts-ut-spec/update_parameter_spec.sh new file mode 100644 index 000000000..429982de0 --- /dev/null +++ b/addons/apecloud-postgresql/scripts-ut-spec/update_parameter_spec.sh @@ -0,0 +1,40 @@ +# shellcheck shell=sh + +Describe 'update_pg_params.sh' + Include ../reloader/update-parameter.sh + + # Mock psql command + setup() { + export POSTGRES_PASSWORD='test_pass' + export POSTGRES_USER='test_user' + } + + BeforeEach 'setup' + + Describe 'do_reload()' + # Mock psql command + Mock psql + # Just echo the command for verification + echo "psql called with: $*" + End + + It 'calls psql with correct parameters' + When call do_reload "max_connections" "100" + The output should include "alter system set max_connections='100'" + The output should include "select pg_reload_conf()" + The output should include "-h localhost -U test_user" + End + + It 'fails when param name is missing' + When call do_reload + The status should be failure + The error should include "missing param name" + End + + It 'fails when param value is missing' + When call do_reload "max_connections" + The status should be failure + The error should include "missing value" + End + End +End \ No newline at end of file diff --git a/addons/apecloud-postgresql/templates/_helpers.tpl b/addons/apecloud-postgresql/templates/_helpers.tpl index e2cf2e3c2..51556fe25 100644 --- a/addons/apecloud-postgresql/templates/_helpers.tpl +++ b/addons/apecloud-postgresql/templates/_helpers.tpl @@ -1,3 +1,10 @@ +{{/* +Common annotations +*/}} +{{- define "apecloud-postgresql.annotations" -}} +helm.sh/resource-policy: keep +{{- end }} + {{/* Expand the name of the chart. */}} @@ -42,20 +49,290 @@ Generate scripts configmap {{- end }} {{- end }} + +{{/* +Define apecloud postgresql 14.X component definition regular expression name prefix +*/}} +{{- define "apecloud-postgresql-14.cmpdRegexpPattern" -}} +^apecloud-postgresql-14.* +{{- end -}} + +{{/* +Define apecloud postgresql 14 component configuration template name +*/}} +{{- define "apecloud-postgresql-14.configurationTemplate" -}} +apecloud-postgresql-14-configuration-{{ .Chart.Version }} +{{- end -}} + +{{/* +Define apecloud postgresql 14 component config constraint name +*/}} +{{- define "apecloud-postgresql-14.configConstraint" -}} +apecloud-postgresql-14-cc-{{ .Chart.Version }} +{{- end -}} + {{/* -Define apecloud-postgresql component definition name prefix +Define apecloud-postgresql component definition regular expression name prefix */}} -{{- define "apecloud-postgresql.componentDefNamePrefix" -}} -{{- printf "apecloud-postgresql-" -}} +{{- define "apecloud-postgresql.cmpdRegexpPattern" -}} +^apecloud-postgresql-\d+ {{- end -}} {{/* -Define apecloud-postgresql14 component definition name +Define apecloud-postgresql 14.X component definition name */}} -{{- define "apecloud-postgresql.compDefApecloudPostgresql14" -}} -{{- if eq (len .Values.resourceNamePrefix) 0 -}} -apecloud-postgresql14 +{{- define "apecloud-postgresql-14.cmpdName" -}} +{{- if eq (len .Values.cmpdVersionPrefix.apecloudPostgresql.major14.minorAll ) 0 -}} +apecloud-postgresql-14-{{ .Chart.Version }} {{- else -}} -{{- .Values.resourceNamePrefix -}} +{{- printf "%s" .Values.cmpdVersionPrefix.apecloudPostgresql.major14.minorAll -}}-{{ .Chart.Version }} +{{- end -}} {{- end -}} + +{{/* +Generate scripts configmap +*/}} +{{- define "apecloud-postgresql.extend.reload.scripts" -}} +{{- range $path, $_ := $.Files.Glob "reloader/**" }} +{{ $path | base }}: |- +{{- $.Files.Get $path | nindent 2 }} +{{- end }} +{{- end }} + +{{/* +Define postgresql scripts configMap template name +*/}} +{{- define "apecloud-postgresql.scriptsTemplate" -}} +apecloud-postgresql-scripts +{{- end -}} + +{{/* +Define postgresql scripts configMap template name +*/}} +{{- define "apecloud-postgresql.reloader.scripts" -}} +apecloud-postgresql-reload-tools-script +{{- end -}} + + +{{- define "apecloud-postgresql.spec.common" -}} +provider: kubeblocks +description: {{ .Chart.Description }} +serviceKind: postgresql +services: + - name: default + spec: + ports: + - name: postgresql + port: 5432 + targetPort: postgresql + roleSelector: leader + - name: replication + serviceName: replication + spec: + ports: + - name: raft + port: 15432 + 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 +vars: + - name: POSTGRES_USER + valueFrom: + credentialVarRef: + name: postgres + optional: false + username: Required + - name: POSTGRES_PASSWORD + valueFrom: + credentialVarRef: + name: postgres + optional: false + password: Required + # env for syncer to initialize dcs + # TODO: modify these env for syncer + - name: MY_CLUSTER_NAME + valueFrom: + clusterVarRef: + clusterName: Required + - name: MY_COMP_NAME + valueFrom: + componentVarRef: + optional: false + shortName: Required + - name: MY_NAMESPACE + valueFrom: + clusterVarRef: + namespace: 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 ${KB_ACCOUNT_NAME} SUPERUSER PASSWORD '${KB_ACCOUNT_PASSWORD}'; +lifecycleActions: + roleProbe: + periodSeconds: 1 + timeoutSeconds: 1 + exec: + container: postgresql + command: + - /tools/dbctl + - --config-path + - /tools/config/dbctl/components + - apecloud-postgresql + - getrole + memberLeave: + exec: + container: postgresql + command: + - /tools/dbctl + - --config-path + - /tools/config/dbctl/components + - apecloud-postgresql + - leavemember + accountProvision: + exec: + container: postgresql + command: + - bash + - -c + - | + eval statement=\"${KB_ACCOUNT_STATEMENT}\" + psql -h 127.0.0.1 -c "${statement}" + env: + - name: PGUSER + value: $(POSTGRES_USER) + - name: PGPASSWORD + value: $(POSTGRES_PASSWORD) + targetPodSelector: Role + matchingKey: primary +{{- end -}} + +{{- define "apecloud-postgresql.spec.runtime.common" -}} +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 + - command: + - cp + - -r + - /bin/dbctl + - /config + - /tools/ + image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.dbctl.repository }}:{{ .Values.image.dbctl.tag }} + imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} + name: init-dbctl + 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: POSTGRESQL_PORT_NUMBER + value: '5432' + - name: PGDATA + value: {{ .Values.dataPath }} + - name: PGCONF + value: {{ .Values.confPath }} + - name: KB_SERVICE_CHARACTER_TYPE + value: apecloud-postgresql + - name: POSTGRESQL_MOUNTED_CONF_DIR + value: {{ .Values.confMountPath }} + - name: MY_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: MY_POD_UID + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.uid + - name: MY_POD_IP + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: status.podIP + 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 {{- end -}} \ No newline at end of file diff --git a/addons/apecloud-postgresql/templates/clusterdefinition.yaml b/addons/apecloud-postgresql/templates/clusterdefinition.yaml index 774441e82..a13441dfc 100644 --- a/addons/apecloud-postgresql/templates/clusterdefinition.yaml +++ b/addons/apecloud-postgresql/templates/clusterdefinition.yaml @@ -9,5 +9,5 @@ spec: - name: apecloud-postgresql components: - name: postgresql - compDef: {{ include "apecloud-postgresql.compDefApecloudPostgresql14" . }} + compDef: {{ include "apecloud-postgresql.cmpdRegexpPattern" . }} default: true diff --git a/addons/apecloud-postgresql/templates/cmpd-apepg.yaml b/addons/apecloud-postgresql/templates/cmpd-apepg.yaml index 12a35cda1..02c28157a 100644 --- a/addons/apecloud-postgresql/templates/cmpd-apepg.yaml +++ b/addons/apecloud-postgresql/templates/cmpd-apepg.yaml @@ -1,52 +1,18 @@ apiVersion: apps.kubeblocks.io/v1 kind: ComponentDefinition metadata: - name: {{ include "apecloud-postgresql.compDefApecloudPostgresql14" . }} + name: {{ include "apecloud-postgresql-14.cmpdName" . }} labels: {{- include "apecloud-postgresql.labels" . | nindent 4 }} + annotations: + {{- include "apecloud-postgresql.annotations" . | 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 + {{- include "apecloud-postgresql.spec.common" . | nindent 2 }} 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 + templateRef: {{ include "apecloud-postgresql-14.configurationTemplate" . }} + constraintRef: {{ include "apecloud-postgresql-14.configConstraint" . }} keys: - postgresql.conf namespace: {{ .Release.Namespace }} @@ -54,158 +20,8 @@ spec: defaultMode: 0444 scripts: - name: apecloud-postgresql-scripts - templateRef: apecloud-postgresql-scripts + templateRef: {{ include "apecloud-postgresql.scriptsTemplate" . }} 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 ${KB_ACCOUNT_NAME} SUPERUSER PASSWORD '${KB_ACCOUNT_PASSWORD}'; - lifecycleActions: - roleProbe: - periodSeconds: 1 - timeoutSeconds: 1 - exec: - container: postgresql - command: - - /tools/dbctl - - --config-path - - /tools/config/dbctl/components - - apecloud-postgresql - - getrole - memberLeave: - exec: - container: postgresql - command: - - /tools/dbctl - - --config-path - - /tools/config/dbctl/components - - apecloud-postgresql - - leavemember - accountProvision: - exec: - container: postgresql - command: - - bash - - -c - - | - eval statement=\"${KB_ACCOUNT_STATEMENT}\" - psql -h 127.0.0.1 -c "${statement}" - env: - - name: PGUSER - value: $(POSTGRES_USER) - - name: PGPASSWORD - value: $(POSTGRES_PASSWORD) - targetPodSelector: Role - matchingKey: primary - 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 - - command: - - cp - - -r - - /bin/dbctl - - /config - - /tools/ - image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.dbctl.repository }}:{{ .Values.image.dbctl.tag }} - imagePullPolicy: {{ default "IfNotPresent" .Values.image.pullPolicy }} - name: init-dbctl - 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: POSTGRESQL_PORT_NUMBER - value: '5432' - - name: PGDATA - value: {{ .Values.dataPath }} - - name: PGCONF - value: {{ .Values.confPath }} - - name: KB_SERVICE_CHARACTER_TYPE - value: apecloud-postgresql - - 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 + {{- include "apecloud-postgresql.spec.runtime.common" . | nindent 2 }} diff --git a/addons/apecloud-postgresql/templates/cmpv.yaml b/addons/apecloud-postgresql/templates/cmpv.yaml index 43438896f..d32e65ca5 100644 --- a/addons/apecloud-postgresql/templates/cmpv.yaml +++ b/addons/apecloud-postgresql/templates/cmpv.yaml @@ -7,11 +7,11 @@ metadata: spec: compatibilityRules: - compDefs: - - {{ include "apecloud-postgresql.compDefApecloudPostgresql14" . }} + - {{ include "apecloud-postgresql-14.cmpdRegexpPattern" . }} 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 }} + postgresql: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:14.11-0.7.3 diff --git a/addons/apecloud-postgresql/templates/configconstraint.yaml b/addons/apecloud-postgresql/templates/configconstraint.yaml index 746d9f8ae..cc8a945d2 100644 --- a/addons/apecloud-postgresql/templates/configconstraint.yaml +++ b/addons/apecloud-postgresql/templates/configconstraint.yaml @@ -2,11 +2,29 @@ apiVersion: apps.kubeblocks.io/v1beta1 kind: ConfigConstraint metadata: - name: apecloud-postgresql14-cc + name: {{ include "apecloud-postgresql-14.configConstraint" . }} labels: {{- include "apecloud-postgresql.labels" . | nindent 4 }} + annotations: + {{- include "apecloud-postgresql.annotations" . | nindent 4 }} spec: + reloadAction: + shellTrigger: + sync: true + command: + - "update-parameter.sh" + scriptConfig: + scriptConfigMapRef: {{ include "apecloud-postgresql.reloader.scripts" . }} + namespace: {{ .Release.Namespace }} + toolsSetup: + mountPoint: /kb_tools + toolConfigs: + - name: kb-tools + image: {{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.repository }}:{{ .Values.image.tag }} + asContainerImage: true + mergeReloadAndRestart: false + reloadStaticParamsBeforeRestart: true # ConfigurationSchema that impose restrictions on engine parameter's rule parametersSchema: # top level mysql configuration type diff --git a/addons/apecloud-postgresql/templates/configmap.yaml b/addons/apecloud-postgresql/templates/configmap.yaml index ef4460129..99be5e83d 100644 --- a/addons/apecloud-postgresql/templates/configmap.yaml +++ b/addons/apecloud-postgresql/templates/configmap.yaml @@ -1,9 +1,11 @@ apiVersion: v1 kind: ConfigMap metadata: - name: apecloud-postgresql14-configuration + name: {{ include "apecloud-postgresql-14.configurationTemplate" . }} labels: {{- include "apecloud-postgresql.labels" . | nindent 4 }} + annotations: + {{- include "apecloud-postgresql.annotations" . | nindent 4 }} data: postgresql.conf: |- {{- .Files.Get "config/pg14-config.tpl" | nindent 4 }} diff --git a/addons/apecloud-postgresql/templates/scripts.yaml b/addons/apecloud-postgresql/templates/scripts.yaml index 120dc44b2..bd91ca41c 100644 --- a/addons/apecloud-postgresql/templates/scripts.yaml +++ b/addons/apecloud-postgresql/templates/scripts.yaml @@ -1,8 +1,19 @@ apiVersion: v1 kind: ConfigMap metadata: - name: apecloud-postgresql-scripts + name: {{ include "apecloud-postgresql.scriptsTemplate" . }} labels: {{- include "apecloud-postgresql.labels" . | nindent 4 }} data: - {{- include "apecloud-postgresql.extend.scripts" . | nindent 2 }} \ No newline at end of file + {{- include "apecloud-postgresql.extend.scripts" . | nindent 2 }} + + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "apecloud-postgresql.reloader.scripts" . }} + labels: + {{- include "apecloud-postgresql.labels" . | nindent 4 }} +data: + {{- include "apecloud-postgresql.extend.reload.scripts" . | nindent 2 }} \ No newline at end of file diff --git a/addons/apecloud-postgresql/values.yaml b/addons/apecloud-postgresql/values.yaml index d4039406b..a521b445f 100644 --- a/addons/apecloud-postgresql/values.yaml +++ b/addons/apecloud-postgresql/values.yaml @@ -12,12 +12,12 @@ image: debug: false syncer: repository: apecloud/syncer - tag: "0.3.2" + tag: "0.3.6" # refer: https://github.com/apecloud/dbctl/blob/main/docker/Dockerfile dbctl: repository: apecloud/dbctl - tag: "0.1.5" + tag: "0.1.6" dataMountPath: /postgresql/volume_data confMountPath: /postgresql/mount_conf @@ -59,3 +59,8 @@ resourceNamePrefix: "" ## @param componentServiceVersion define default serviceVersion of each Component componentServiceVersion: apecloudPostgresql14: "14.11.0" + +cmpdVersionPrefix: + apecloudPostgresql: + major14: + minorAll: "apecloud-postgresql-14"