From e700c04ed31fdb43b2fa1864fb6b60e63a1903ad Mon Sep 17 00:00:00 2001 From: Tao Li Date: Wed, 27 Nov 2024 11:03:13 +0800 Subject: [PATCH] use global value for operator repository Signed-off-by: Tao Li --- README.md | 52 ++++++------------- .../templates/_helpers.tpl | 26 ++++++++++ .../templates/deployment.yaml | 6 +-- .../values.yaml | 7 ++- .../templates/_helpers.tpl | 9 ++++ .../templates/deployment.yaml | 6 +-- .../values.yaml | 31 +++++------ 7 files changed, 79 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 85ca444..4aefb30 100644 --- a/README.md +++ b/README.md @@ -94,10 +94,9 @@ Like PG4K install, both the operator and the operand images required by PG4K-PGD may be pulled from the `k8s_enterprise` or `k8s_standard` repositories at `docker.enterprisedb.com`, please obtaining an EDB subscription token before setup. -The `edb-postgres-distributed-for-kubernetes` chart will by default install PG4K -operator defined by sub-chart in the same namespace, the PG4K operator installed -in the sub-chart is PG4K LTS release operator, which is upgraded along with the -parent chart version release. +The `edb-postgres-distributed-for-kubernetes` chart will install the operator for +both PG4K-PGD and PG4K in the same namespace. The PG4K operator used for PG4K-PGD +is well-tested and belongs to latest long term support release of PG4K. The `edb-postgres-distributed-for-kubernetes` chart also install the cert-manager operators as dependency. You can avoid this if necessary. See the sub-section @@ -145,7 +144,7 @@ helm chart are working: ### Deploying the PG4K-PGD operators and cert-manager individually The chart `edb-postgres-distributed-for-kubernetes` is set by default to -also install PG4K and cert-manager operators, which it depends on. +also install cert-manager operators, which it depends on. When following this route, all operators will be installed in the same namespace. This is in contrast with other installation paths, where the operators reside in dedicated namespaces. @@ -154,7 +153,7 @@ Installing all dependencies in the same namespace is a design limitation of Helm, but we can get around it by installing dependencies with separate invocations of `helm`. -If you would like to install the cert-manager in separate namespaces, please +If you would like to install the cert-manager in a separate namespaces, please follow the below steps. #### 1. Setup cert-manager @@ -184,23 +183,10 @@ In case you choose this option, remember to also specify `--set cert-manager.enabled=false` during the installation of the PG4K-PGD helm chart in the next section. -#### 2. Setup PG4K - -By default, a PG4K operator with LTS release is installed alongside with PG4K-PGD -deploy. You can follow [PG4K helm chart](#deployment-of-the-edb-postgres-for-kubernetes-operator-pg4k) -to deploy the PG4K operator in its own namespace. But it is highly recommended to use -the PG4K operator installed as dependency of PG4K-PGD chart, which contains the well tested PG4K -operator version. - -In case you choose to use existing PG4K operator, remember to also specify -`--set edb-postgres-for-kubernetes-lts.enabled=false` during the installation of the PG4K-PGD -helm chart in the next section. - -#### 3. Setup PG4K-PGD +#### 2. Setup PG4K-PGD Once the above deployments are ready, you can deploy the PG4K-PGD helm chart. taking care -to set `edb-postgres-for-kubernetes-lts.enabled` to false if you PG4K already deployed, -and set `cert-manager.enabled` to false if cert-manager is installed separately. +to set `cert-manager.enabled` to false if cert-manager is installed separately. **Note:** in the following example, the flags setting the credentials were elided to put the focus on the `enabled=false` condition. The flags may still be @@ -213,11 +199,10 @@ helm upgrade --dependency-update \ --create-namespace \ edb/edb-postgres-distributed-for-kubernetes \ --set cert-manager.enabled=false - --set edb-postgres-for-kubernetes-lts.enabled=false ``` -You can see the three separate namespaces, the same that would be created if -installing manually without Helm charts. +You can see two seperate namespaces where cert-manager is installed in `cert-manager` +namespaces. ``` sh $ kubectl get ns @@ -225,7 +210,6 @@ NAME STATUS AGE … cert-manager Active 24m pgd-operator-system Active 55s -postgresql-operator-system Active 5m33s ``` ### Controlling the image repositories @@ -238,14 +222,13 @@ subscription plan. This needs to be done in several places in the command-line invocation. The following example uses the `k8s_standard_pgd` registry in -`docker.enterprisedb.com`. -Note the multiple `--set` options, for the `image.repository`, -`PGD_IMAGE_NAME` and `PGD_PROXY_IMAGE_NAME` in addition to the -`edb-postgres-for-kubernetes-lts.image.repository` where the PGD operator -is pulled from. There are 4 in total -- `image.repository` where the PG4K-PGD operator image is pulled from. -- `edb-postgres-for-kubernetes-lts.image.repository` where the PG4K operator image is pulled from. -- `PGD_IMAGE_NAME` and `PGD_PROXY_IMAGE_NAME` where the PGD and PGD Proxy image are pulled from. +`docker.enterprisedb.com`. Following is the description of multiple +set options. +- `image.repository` where the PG4K-PGD and PG4K operator image is pulled from, this is the repository without imageName, the default +operator image name is defined in the value file. +- `PGD_IMAGE_NAME` where the PGD image are pulled from. +- `PGD_PROXY_IMAGE_NAME` where PGD Proxy image are pulled from, usually +the same with `PGD_IMAGE_NAME`. Assuming that you have your necessary credentials, please fill in the USERNAME and PASSWORD below. @@ -258,8 +241,7 @@ helm upgrade --dependency-update \ edb/edb-postgres-distributed-for-kubernetes \ --set image.imageCredentials.username=${USERNAME} \ --set image.imageCredentials.password=${PASSWORD} \ - --set image.repository=docker.enterprisedb.com/k8s_standard_pgd/pg4k-pgd \ - --set edb-postgres-for-kubernetes-lts.image.repository=docker.enterprisedb.com/k8s_standard_pgd/edb-postgres-for-kubernetes \ + --set image.repository=docker.enterprisedb.com/k8s_standard_pgd \ --set config.data.PGD_IMAGE_NAME=docker.enterprisedb.com/k8s_standard_pgd/postgresql-pgd:15.6-5.5.1-1 \ --set config.data.PGD_PROXY_IMAGE_NAME=docker.enterprisedb.com/k8s_standard_pgd/edb-pgd-proxy:5.5.0 ``` diff --git a/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/templates/_helpers.tpl b/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/templates/_helpers.tpl index 5ec2d8c..4bef72d 100644 --- a/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/templates/_helpers.tpl +++ b/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/templates/_helpers.tpl @@ -72,6 +72,32 @@ Create the imagePullSecret {{- end }} {{- end }} +{{/* +Create the pg4k operator image name +*/}} +{{- define "edb-postgres-for-kubernetes-lts.operatorImageName" }} +{{- if not .Values.global }} +{{- if .Values.image.repository }} +{{- printf "%s/%s:%s" .Values.image.repository .Values.image.imageName | default "edb-postgres-for-kubernetes" .Values.image.tag | default .Chart.AppVersion }} +{{- end }} +{{- else }} +{{- if .Values.global.repository }} +{{- printf "%s/%s:%s" .Values.global.repository .Values.global.imageName | default "edb-postgres-for-kubernetes" .Values.image.tag | default .Chart.AppVersion }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create image pullPolicy +*/}} +{{- define "edb-postgres-for-kubernetes-lts.operatorImagePullPolicy" -}} +{{- if not .Values.global }} +{{- printf .Values.image.pullPolicy }} +{{- else }} +{{- printf .Values.global.imagePullPolicy }} +{{- end }} +{{- end }} + {{/* Define the common set of rules that can be applied either with namespace scope or clusterwide diff --git a/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/templates/deployment.yaml b/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/templates/deployment.yaml index 4c8be70..737fe14 100644 --- a/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/templates/deployment.yaml +++ b/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/templates/deployment.yaml @@ -70,7 +70,7 @@ spec: - /manager env: - name: OPERATOR_IMAGE_NAME - value: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + value: "{{- include "edb-postgres-for-kubernetes-lts.operatorImageName" . }}" - name: OPERATOR_NAMESPACE valueFrom: fieldRef: @@ -84,8 +84,8 @@ spec: - name: WATCH_NAMESPACE value: "{{ .Release.Namespace }}" {{- end }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} + image: "{{- include "edb-postgres-for-kubernetes-lts.operatorImageName" . }}" + imagePullPolicy: "{{- include "edb-postgres-for-kubernetes-lts.operatorImagePullPolicy" . }}" livenessProbe: httpGet: path: /readyz diff --git a/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/values.yaml b/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/values.yaml index d7c9472..d5cec73 100644 --- a/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/values.yaml +++ b/charts/edb-postgres-distributed-for-kubernetes/charts/edb-postgres-for-kubernetes-lts/values.yaml @@ -19,10 +19,12 @@ replicaCount: 1 image: - repository: docker.enterprisedb.com/k8s_enterprise/edb-postgres-for-kubernetes - pullPolicy: IfNotPresent + repository: docker.enterprisedb.com/k8s_enterprise + # The name of the operator image to be pulled from repository + imageName: edb-postgres-for-kubernetes # -- Overrides the image tag whose default is the chart appVersion. tag: "" + pullPolicy: IfNotPresent # Credentials configuration imageCredentials: # -- Specifies if an imagePullSecret should be created @@ -41,6 +43,7 @@ fullnameOverride: "" hostNetwork: false dnsPolicy: "" +installCRDs: true crds: # -- Specifies whether the CRDs should be created when installing the chart. create: true diff --git a/charts/edb-postgres-distributed-for-kubernetes/templates/_helpers.tpl b/charts/edb-postgres-distributed-for-kubernetes/templates/_helpers.tpl index 4fb1e7a..1e0a99c 100644 --- a/charts/edb-postgres-distributed-for-kubernetes/templates/_helpers.tpl +++ b/charts/edb-postgres-distributed-for-kubernetes/templates/_helpers.tpl @@ -30,6 +30,15 @@ Create chart name and version as used by the chart label. {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- end }} +{{/* +Create the pg4k-pgd operator image name +*/}} +{{- define "edb-postgres-distributed-for-kubernetes.operatorImageName" }} +{{- if .Values.global.repository }} +{{- printf "%s/%s:%s" .Values.global.repository .Values.global.imageName | default "pg4k-pgd" .Values.global.imageTag | default .Chart.AppVersion }} +{{- end }} +{{- end }} + {{/* Common labels */}} diff --git a/charts/edb-postgres-distributed-for-kubernetes/templates/deployment.yaml b/charts/edb-postgres-distributed-for-kubernetes/templates/deployment.yaml index 46c5688..4cdf24b 100644 --- a/charts/edb-postgres-distributed-for-kubernetes/templates/deployment.yaml +++ b/charts/edb-postgres-distributed-for-kubernetes/templates/deployment.yaml @@ -65,13 +65,13 @@ spec: - /manager env: - name: OPERATOR_IMAGE_NAME - value: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + value: "{{- include "edb-postgres-distributed-for-kubernetes.operatorImageName" . }}" - name: OPERATOR_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} + image: "{{- include "edb-postgres-distributed-for-kubernetes.operatorImageName" . }}" + imagePullPolicy: {{ .Values.global.imagePullPolicy }} livenessProbe: httpGet: path: /readyz diff --git a/charts/edb-postgres-distributed-for-kubernetes/values.yaml b/charts/edb-postgres-distributed-for-kubernetes/values.yaml index 24727d7..27c4fae 100644 --- a/charts/edb-postgres-distributed-for-kubernetes/values.yaml +++ b/charts/edb-postgres-distributed-for-kubernetes/values.yaml @@ -18,13 +18,20 @@ replicaCount: 1 -image: - # Additional Registries - # repository: docker.enterprisedb.com/k8s_standard_pgd/pg4k-pgd - repository: docker.enterprisedb.com/k8s_enterprise_pgd/pg4k-pgd - pullPolicy: IfNotPresent +# -- Global values +global: + # -- Specifies the repository where the operator image to be downloaded from + # repository: docker.enterprisedb.com/k8s_standard_pgd + repository: docker.enterprisedb.com/k8s_enterprise_pgd + # -- Specifies the name of the operator image to be pulled from repository + imageName: pg4k-pgd + # -- Specifies the tag of the operator image to be pulled from repository # -- Overrides the image tag whose default is the chart appVersion. - tag: "" + imageTag: "" + imagePullPolicy: IfNotPresent + + +image: # Credentials configuration imageCredentials: # -- Specifies if an imagePullSecret should be created @@ -36,6 +43,7 @@ image: imagePullSecrets: - name: edb-pull-secret + nameOverride: "" fullnameOverride: "" @@ -158,16 +166,9 @@ cert-manager: enabled: true installCRDs: true -# edb-postgres-for-kubernetes-lts +# edb-postgres-for-kubernetes-lts subcharts +# Values defined here will overwrite the global values edb-postgres-for-kubernetes-lts: enabled: true - image: - repository: docker.enterprisedb.com/k8s_enterprise_pgd/edb-postgres-for-kubernetes - imagePullSecrets: - - name: edb-pull-secret - config: - data: - PULL_SECRET_NAME: edb-pull-secret crds: - # -- Specifies whether the CRDs should be created when installing the chart. create: true