Skip to content

Commit b077601

Browse files
leonardocegbartolinisxd
authored
Improve label names for the controller deployment
Instead of just using the default provided by kube-builder, we are now relying on our custom labels, avoid clashing with other operators. Co-authored-by: Leonardo Cecchi <leonardo.cecchi@enterprisedb.com> Co-authored-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com> Co-authored-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com>
1 parent f11da7a commit b077601

11 files changed

Lines changed: 134 additions & 27 deletions

File tree

.wordlist-en-custom.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ ubi
465465
ul
466466
unencrypted
467467
unix
468+
upgradable
468469
usename
469470
usr
470471
utils

config/manager/manager.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
kind: Namespace
33
metadata:
44
labels:
5-
control-plane: controller-manager
5+
app.kubernetes.io/name: cloud-native-postgresql
66
name: system
77
---
88
apiVersion: v1
@@ -16,16 +16,16 @@ metadata:
1616
name: controller-manager
1717
namespace: system
1818
labels:
19-
control-plane: controller-manager
19+
app.kubernetes.io/name: cloud-native-postgresql
2020
spec:
2121
selector:
2222
matchLabels:
23-
control-plane: controller-manager
23+
app.kubernetes.io/name: cloud-native-postgresql
2424
replicas: 1
2525
template:
2626
metadata:
2727
labels:
28-
control-plane: controller-manager
28+
app.kubernetes.io/name: cloud-native-postgresql
2929
spec:
3030
serviceAccountName: manager
3131
securityContext:

config/prometheus/monitor.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apiVersion: monitoring.coreos.com/v1
44
kind: ServiceMonitor
55
metadata:
66
labels:
7-
control-plane: controller-manager
7+
app.kubernetes.io/name: cloud-native-postgresql
88
name: controller-manager-metrics-monitor
99
namespace: system
1010
spec:
@@ -13,4 +13,4 @@ spec:
1313
port: https
1414
selector:
1515
matchLabels:
16-
control-plane: controller-manager
16+
app.kubernetes.io/name: cloud-native-postgresql

config/rbac/auth_proxy_service.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v1
22
kind: Service
33
metadata:
44
labels:
5-
control-plane: controller-manager
5+
app.kubernetes.io/name: cloud-native-postgresql
66
name: controller-manager-metrics-service
77
namespace: system
88
spec:
@@ -11,4 +11,4 @@ spec:
1111
port: 8443
1212
targetPort: https
1313
selector:
14-
control-plane: controller-manager
14+
app.kubernetes.io/name: cloud-native-postgresql

config/webhook/service.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ spec:
99
- port: 443
1010
targetPort: 9443
1111
selector:
12-
control-plane: controller-manager
12+
app.kubernetes.io/name: cloud-native-postgresql

docs/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ nav:
1313
- before_you_start.md
1414
- use_cases.md
1515
- architecture.md
16-
- installation.md
16+
- installation_upgrade.md
1717
- quickstart.md
1818
- cloud_setup.md
1919
- bootstrap.md

docs/src/cloud_setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Below you can find specific instructions for each of the above environments.
1616
Once the steps described on this page have been completed, and your `kubectl`
1717
can connect to the desired cluster, you can install the operator and start
1818
creating PostgreSQL `Clusters` by following the instructions you find in the
19-
["Installation"](installation.md) section.
19+
["Installation"](installation_upgrade.md) section.
2020

2121
!!! Important
2222
`kubectl` is required to proceed with setup.
Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Installation
1+
# Installation and upgrades
22

33
## Installation on Kubernetes
44

@@ -94,3 +94,68 @@ selected installation method.
9494
some default options. For more information, please refer to the
9595
["Operator configuration"](operator_conf.md) section.
9696

97+
## Upgrades
98+
99+
!!! Important
100+
Please carefully read the [release notes](release_note.md)
101+
before performing an upgrade as some versions might require
102+
extraordinary measures.
103+
104+
Upgrading Cloud Native PostgreSQL operator is a two-step process:
105+
106+
1. upgrade the controller and the related Kubernetes resources
107+
2. upgrade the instance manager running in every PostgreSQL pod
108+
109+
Unless differently stated in the release notes, the first step is normally done
110+
by applying the manifest of the newer version for plain Kubernetes
111+
installations, or using the native package manager of the used distribution
112+
(please follow the instructions in the above sections).
113+
114+
The second step is automatically executed after having updated the controller,
115+
triggering a rolling update of every deployed PostgreSQL instance to use the
116+
new instance manager. If the `primaryUpdateStrategy` is set to `supervised`,
117+
users need to complete the rolling update by manually promoting a new instance
118+
through the `cnp` plugin for `kubectl`.
119+
120+
!!! Seealso "Rolling updates"
121+
This process is discussed in-depth in the [Rolling Updates](rolling_update.md) page.
122+
123+
!!! Important
124+
In case `primaryUpdateStrategy` is set to the default value of `unsupervised`,
125+
an upgrade of the operator will trigger a switchover on your PostgreSQL cluster,
126+
causing a (normally negligible) downtime.
127+
128+
### Compatibility among versions
129+
130+
We strive to maintain compatibility between different operator versions, but in
131+
some cases this might not be possible.
132+
Every version of the operator is compatible with the previous one, unless
133+
[release notes](release_notes.md) state the opposite.
134+
The release notes page indeed contains a detailed list of the changes introduced
135+
in every released version of the Cloud Native PostgreSQL Operator, and it must
136+
be read before upgrading to a newer version of the software.
137+
138+
Most versions are directly upgradable and in that case applying the newer
139+
manifest for plain Kubernetes installations or using the native package
140+
manager of the chosen distribution is enough.
141+
142+
When versions are not directly upgradable, the old version need to be
143+
removed before installing the new one. This won't affect user data but
144+
only the operator itself. Please consult the release notes for
145+
detailed information on how to upgrade to any released version.
146+
147+
#### Upgrading to version 1.4.0
148+
149+
When upgrading from version 1.3.0 to 1.4.0 you must run the following
150+
command before installing the new version of the operator:
151+
152+
```bash
153+
kubectl delete deployments \
154+
-n postgresql-operator-system \
155+
-l control-plane=controller-manager
156+
```
157+
158+
!!! Note
159+
In case you deployed the operator in a different namespace than the default
160+
(`postgresql-operator-system`), you need to use the correct namespace for
161+
the `-n` option in the above command.

docs/src/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ and install `rancher/local-path-provisioner`.
9898
Now that you have a Kubernetes or OpenShift installation up and running
9999
on your laptop, you can proceed with Cloud Native PostgreSQL installation.
100100

101-
Please refer to the ["Installation"](installation.md) section and then proceed
101+
Please refer to the ["Installation"](installation_upgrade.md) section and then proceed
102102
with the deployment of a PostgreSQL cluster.
103103

104104
## Part 3 - Deploy a PostgreSQL cluster

tests/environment.go

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,30 @@ func (env TestingEnvironment) ExecCommand(
132132
func (env TestingEnvironment) GetOperatorDeployment() (appsv1.Deployment, error) {
133133
const operatorDeploymentName = "postgresql-operator-controller-manager"
134134
deploymentList := &appsv1.DeploymentList{}
135-
err := env.Client.List(
135+
136+
if err := env.Client.List(
137+
env.Ctx, deploymentList, client.MatchingLabels{"app.kubernetes.io/name": "cloud-native-postgresql"},
138+
); err != nil {
139+
return appsv1.Deployment{}, err
140+
}
141+
// We check if we have one or more deployments
142+
switch {
143+
case len(deploymentList.Items) > 1:
144+
err := fmt.Errorf("number of operator deployments != 1")
145+
return appsv1.Deployment{}, err
146+
case len(deploymentList.Items) == 1:
147+
return deploymentList.Items[0], nil
148+
}
149+
150+
// This it's for older deployments and will not work on the new ones
151+
if err := env.Client.List(
136152
env.Ctx, deploymentList, client.MatchingFields{"metadata.name": operatorDeploymentName},
137-
)
138-
if err != nil {
153+
); err != nil {
139154
return appsv1.Deployment{}, err
140155
}
156+
141157
if len(deploymentList.Items) != 1 {
142-
err = fmt.Errorf("number of %v deployments != 1", operatorDeploymentName)
158+
err := fmt.Errorf("number of %v deployments != 1", operatorDeploymentName)
143159
return appsv1.Deployment{}, err
144160
}
145161
return deploymentList.Items[0], nil
@@ -148,14 +164,33 @@ func (env TestingEnvironment) GetOperatorDeployment() (appsv1.Deployment, error)
148164
// GetOperatorPod returns the operator pod if there is a single one running, error otherwise
149165
func (env TestingEnvironment) GetOperatorPod() (corev1.Pod, error) {
150166
podList := &corev1.PodList{}
167+
168+
// This will work for newer version of the operator, which are using
169+
// our custom label
170+
if err := env.Client.List(
171+
env.Ctx, podList, client.MatchingLabels{"app.kubernetes.io/name": "cloud-native-postgresql"}); err != nil {
172+
return corev1.Pod{}, err
173+
}
174+
switch {
175+
case len(podList.Items) > 1:
176+
err := fmt.Errorf("number of running operator pods greater than 1: %v pods running", len(podList.Items))
177+
return corev1.Pod{}, err
178+
179+
case len(podList.Items) == 1:
180+
return podList.Items[0], nil
181+
}
182+
183+
// This will work for older version of the operator, which are using
184+
// the default label from kube-builder
151185
if err := env.Client.List(
152186
env.Ctx, podList, client.MatchingLabels{"control-plane": "controller-manager"}); err != nil {
153187
return corev1.Pod{}, err
154188
}
155189
if len(podList.Items) != 1 {
156-
err := fmt.Errorf("number of running operator pods != 1: %v pods running", len(podList.Items))
190+
err := fmt.Errorf("number of running operator different than 1: %v pods running", len(podList.Items))
157191
return corev1.Pod{}, err
158192
}
193+
159194
return podList.Items[0], nil
160195
}
161196

0 commit comments

Comments
 (0)