Skip to content

Commit 74df255

Browse files
committed
Add upgrade controller to Helm install chart
Issue: [sc-14201]
1 parent 629b3b2 commit 74df255

12 files changed

+1042
-29
lines changed

helm/install/.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://github.com/github/linguist/issues/4905
2+
# https://github.com/github/linguist/issues/5092#issuecomment-730262298
3+
/templates/*.tpl linguist-language=handlebars

helm/install/.helmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.git*

helm/install/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ name: pgo
33
description: Installer for PGO, the open source Postgres Operator from Crunchy Data
44

55
type: application
6-
version: 0.2.5
6+
version: 0.3.0
77
appVersion: 5.1.0

helm/install/crds/postgres-operator.crunchydata.com_pgupgrades.yaml

Lines changed: 850 additions & 0 deletions
Large diffs are not rendered by default.

helm/install/templates/_helpers.tpl

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,26 @@ Create chart name and version as used by the chart label.
88
{{/*
99
Crunchy labels
1010
*/}}
11-
{{- define "install.crunchyLabels" -}}
11+
{{- define "install.clusterLabels" -}}
1212
postgres-operator.crunchydata.com/control-plane: {{ .Chart.Name }}
1313
{{- end }}
14+
{{- define "install.upgradeLabels" -}}
15+
postgres-operator.crunchydata.com/control-plane: {{ .Chart.Name }}-upgrade
16+
{{- end }}
1417

1518
{{/*
1619
Common labels
1720
*/}}
1821
{{- define "install.labels" -}}
1922
helm.sh/chart: {{ include "install.chart" . }}
20-
{{ include "install.selectorLabels" . }}
23+
app.kubernetes.io/name: {{ .Chart.Name }}
24+
app.kubernetes.io/instance: {{ .Release.Name }}
2125
{{- if .Chart.AppVersion }}
2226
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
2327
{{- end }}
2428
app.kubernetes.io/managed-by: {{ .Release.Service }}
2529
{{- end }}
2630

27-
{{/*
28-
Selector labels
29-
*/}}
30-
{{- define "install.selectorLabels" -}}
31-
app.kubernetes.io/name: {{ .Chart.Name }}
32-
app.kubernetes.io/instance: {{ .Release.Name }}
33-
{{ include "install.crunchyLabels" .}}
34-
{{- end }}
35-
3631
{{/*
3732
Create the name of the service account to use
3833
*/}}
@@ -77,3 +72,23 @@ Role
7772
ClusterRole
7873
{{- end }}
7974
{{- end }}
75+
76+
{{- define "install.imagePullSecrets" -}}
77+
{{/* Earlier versions required the full structure of PodSpec.ImagePullSecrets */}}
78+
{{- if .Values.imagePullSecrets }}
79+
imagePullSecrets:
80+
{{ toYaml .Values.imagePullSecrets }}
81+
{{- else if .Values.imagePullSecretNames }}
82+
imagePullSecrets:
83+
{{- range .Values.imagePullSecretNames }}
84+
- name: {{ . | quote }}
85+
{{- end }}{{/* range */}}
86+
{{- end }}{{/* if */}}
87+
{{- end }}{{/* define */}}
88+
89+
{{- define "install.relatedImages" -}}
90+
{{- range $id, $object := .Values.relatedImages }}
91+
- name: RELATED_IMAGE_{{ $id | upper }}
92+
value: {{ $object.image | quote }}
93+
{{- end }}
94+
{{- end }}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: {{ .Chart.Name }}-upgrade
6+
labels:
7+
{{- include "install.labels" . | nindent 4 }}
8+
{{- include "install.upgradeLabels" . | nindent 4 }}
9+
spec:
10+
replicas: 1
11+
strategy: { type: Recreate }
12+
selector:
13+
matchLabels:
14+
{{- include "install.upgradeLabels" . | nindent 6 }}
15+
template:
16+
metadata:
17+
labels:
18+
{{- include "install.upgradeLabels" . | nindent 8 }}
19+
spec:
20+
{{- include "install.imagePullSecrets" . | indent 6 }}
21+
serviceAccountName: {{ include "install.serviceAccountName" . }}-upgrade
22+
containers:
23+
- name: operator
24+
image: {{ required ".Values.controllerImages.upgrade is required" .Values.controllerImages.upgrade | quote }}
25+
env:
26+
- name: CRUNCHY_DEBUG
27+
value: {{ .Values.debug | ne false | quote }}
28+
{{- if .Values.singleNamespace }}
29+
- name: PGO_TARGET_NAMESPACE
30+
valueFrom: { fieldRef: { apiVersion: v1, fieldPath: metadata.namespace } }
31+
{{- end }}
32+
{{- if .Values.workers }}
33+
- name: PGO_WORKERS
34+
value: {{ .Values.workers | quote }}
35+
{{- end }}
36+
{{- include "install.relatedImages" . | indent 8 }}
37+
securityContext:
38+
allowPrivilegeEscalation: false
39+
readOnlyRootFilesystem: true
40+
runAsNonRoot: true

helm/install/templates/manager.yaml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
1+
---
12
apiVersion: apps/v1
23
kind: Deployment
34
metadata:
45
name: {{ .Chart.Name }}
56
labels:
67
{{- include "install.labels" . | nindent 4 }}
8+
{{- include "install.clusterLabels" . | nindent 4 }}
79
spec:
810
replicas: 1
911
strategy: { type: Recreate }
1012
selector:
1113
matchLabels:
12-
{{- include "install.crunchyLabels" . | nindent 6 }}
14+
{{- include "install.clusterLabels" . | nindent 6 }}
1315
template:
1416
metadata:
1517
labels:
16-
{{- include "install.crunchyLabels" . | nindent 8 }}
18+
{{- include "install.clusterLabels" . | nindent 8 }}
1719
spec:
20+
{{- include "install.imagePullSecrets" . | indent 6 }}
21+
serviceAccountName: {{ include "install.serviceAccountName" . }}
1822
containers:
1923
- name: operator
2024
image: {{ required ".Values.controllerImages.cluster is required" .Values.controllerImages.cluster | quote }}
2125
env:
22-
- name: PGO_NAMESPACE
23-
valueFrom:
24-
fieldRef:
25-
fieldPath: metadata.namespace
2626
- name: CRUNCHY_DEBUG
27-
value: {{ if eq .Values.debug false }}"false"{{- else }}"true"{{- end }}
28-
{{- range $image_name, $image_val := .Values.relatedImages }}
29-
- name: RELATED_IMAGE_{{ $image_name | upper }}
30-
value: "{{ $image_val.image }}"
31-
{{- end }}
27+
value: {{ .Values.debug | ne false | quote }}
28+
- name: PGO_NAMESPACE
29+
valueFrom: { fieldRef: { apiVersion: v1, fieldPath: metadata.namespace } }
3230
{{- if .Values.singleNamespace }}
3331
- name: PGO_TARGET_NAMESPACE
3432
valueFrom: { fieldRef: { apiVersion: v1, fieldPath: metadata.namespace } }
@@ -37,12 +35,12 @@ spec:
3735
- name: PGO_WORKERS
3836
value: {{ .Values.workers | quote }}
3937
{{- end }}
40-
{{- if (default false .Values.disable_check_for_upgrades) }}
38+
{{- include "install.relatedImages" . | indent 8 }}
39+
{{- if .Values.disable_check_for_upgrades }}
4140
- name: CHECK_FOR_UPGRADES
4241
value: "false"
4342
{{- end }}
4443
securityContext:
4544
allowPrivilegeEscalation: false
4645
readOnlyRootFilesystem: true
4746
runAsNonRoot: true
48-
serviceAccount: {{ include "install.serviceAccountName" . }}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: {{ include "install.roleKind" . }}
4+
metadata:
5+
name: {{ include "install.roleName" . }}-upgrade
6+
labels:
7+
{{- include "install.labels" . | nindent 4 }}
8+
{{- include "install.upgradeLabels" . | nindent 4 }}
9+
rules:
10+
- apiGroups:
11+
- ""
12+
resources:
13+
- endpoints
14+
verbs:
15+
- delete
16+
- get
17+
- list
18+
- watch
19+
- apiGroups:
20+
- apps
21+
resources:
22+
- statefulsets
23+
verbs:
24+
- list
25+
- watch
26+
- apiGroups:
27+
- batch
28+
resources:
29+
- jobs
30+
verbs:
31+
- create
32+
- delete
33+
- list
34+
- patch
35+
- watch
36+
- apiGroups:
37+
- postgres-operator.crunchydata.com
38+
resources:
39+
- pgupgrades
40+
verbs:
41+
- get
42+
- list
43+
- watch
44+
- apiGroups:
45+
- postgres-operator.crunchydata.com
46+
resources:
47+
- pgupgrades/finalizers
48+
verbs:
49+
- patch
50+
- update
51+
- apiGroups:
52+
- postgres-operator.crunchydata.com
53+
resources:
54+
- pgupgrades/status
55+
verbs:
56+
- get
57+
- patch
58+
- apiGroups:
59+
- postgres-operator.crunchydata.com
60+
resources:
61+
- postgresclusters
62+
verbs:
63+
- get
64+
- list
65+
- watch
66+
- apiGroups:
67+
- postgres-operator.crunchydata.com
68+
resources:
69+
- postgresclusters/status
70+
verbs:
71+
- patch

helm/install/templates/role.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
---
12
apiVersion: rbac.authorization.k8s.io/v1
23
kind: {{ include "install.roleKind" . }}
34
metadata:
45
name: {{ include "install.roleName" . }}
56
labels:
67
{{- include "install.labels" . | nindent 4 }}
8+
{{- include "install.clusterLabels" . | nindent 4 }}
79
rules:
810
- apiGroups:
911
- ''

helm/install/templates/role_binding.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
---
12
apiVersion: rbac.authorization.k8s.io/v1
23
kind: {{ include "install.roleBindingKind" . }}
34
metadata:
45
name: {{ include "install.roleBindingName" . }}
56
labels:
67
{{- include "install.labels" . | nindent 4 }}
8+
{{- include "install.clusterLabels" . | nindent 4 }}
79
roleRef:
810
apiGroup: rbac.authorization.k8s.io
911
kind: {{ include "install.roleKind" . }}
@@ -12,3 +14,19 @@ subjects:
1214
- kind: ServiceAccount
1315
name: {{ include "install.serviceAccountName" . }}
1416
namespace: {{ .Release.Namespace }}
17+
---
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
kind: {{ include "install.roleBindingKind" . }}
20+
metadata:
21+
name: {{ include "install.roleBindingName" . }}-upgrade
22+
labels:
23+
{{- include "install.labels" . | nindent 4 }}
24+
{{- include "install.upgradeLabels" . | nindent 4 }}
25+
roleRef:
26+
apiGroup: rbac.authorization.k8s.io
27+
kind: {{ include "install.roleKind" . }}
28+
name: {{ include "install.roleName" . }}-upgrade
29+
subjects:
30+
- kind: ServiceAccount
31+
name: {{ include "install.serviceAccountName" . }}-upgrade
32+
namespace: {{ .Release.Namespace }}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
---
12
apiVersion: v1
23
kind: ServiceAccount
34
metadata:
45
name: {{ include "install.serviceAccountName" . }}
56
labels:
67
{{- include "install.labels" . | nindent 4 }}
8+
{{- include "install.clusterLabels" . | nindent 4 }}
9+
---
10+
apiVersion: v1
11+
kind: ServiceAccount
12+
metadata:
13+
name: {{ include "install.serviceAccountName" . }}-upgrade
14+
labels:
15+
{{- include "install.labels" . | nindent 4 }}
16+
{{- include "install.upgradeLabels" . | nindent 4 }}

helm/install/values.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
---
2-
# controllerImages are used to run the PostgresCluster controller.
1+
# controllerImages are used to run the PostgresCluster and PGUpgrade controllers.
32
controllerImages:
43
cluster: registry.developers.crunchydata.com/crunchydata/postgres-operator:ubi8-5.1.0-0
4+
upgrade: registry.developers.crunchydata.com/crunchydata/postgres-operator-upgrade:ubi8-5.1.0-0
55

6-
# relatedImages are used when an image is omitted from the PostgresCluster spec.
6+
# relatedImages are used when an image is omitted from PostgresCluster or PGUpgrade specs.
77
relatedImages:
88
postgres_14:
99
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi8-14.2-1
@@ -21,12 +21,17 @@ relatedImages:
2121
image: registry.developers.crunchydata.com/crunchydata/crunchy-pgbouncer:ubi8-1.16-2
2222
pgexporter:
2323
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres-exporter:ubi8-5.1.0-0
24+
pgupgrade:
25+
image: registry.developers.crunchydata.com/crunchydata/crunchy-upgrade:ubi8-5.1.0-0
2426

2527
# singleNamespace controls where PGO watches for PostgresClusters. When false,
2628
# PGO watches for and responds to PostgresClusters in all namespaces. When true,
2729
# PGO watches only the namespace in which it is installed.
2830
singleNamespace: false
2931

3032
# debug allows you to enable or disable the "debug" level of logging.
31-
# Defaults to the value below.
3233
debug: true
34+
35+
# imagePullSecretNames is a list of secret names to use for pulling controller images.
36+
# More info: https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod
37+
imagePullSecretNames: []

0 commit comments

Comments
 (0)