Skip to content

Commit e0a885c

Browse files
committed
Rolling update for changes to PostgresInstanceSetSpec
We deploy PostgreSQL instances as individual StatefulSets so that: - a Kubernetes controller keeps the Pods running, - each Pod has a stable DNS name, and - each Pod can be stopped and started independently This commit leverages that last property to orchestrate rolling updates of instance specifications while considering each Pod's availability and role as primary or replica of the PostresCluster. To that end, a new Instance type combines the PostgresInstanceSetSpec, StatefulSet, and Pod objects of each logical instance to make it easy to consider them together. It has methods like IsPrimary and IsAvailable that can be useful outside of the rolling update logic. A new "instances" section is added to PostgresClusterStatus that shows the progress of rolling updates. Its "replicas", "readyReplicas", and "updatedReplicas" fields have the same semantics as fields with those names in appsv1.DeploymentStatus and appsv1.StatefulSetStatus. Issue: [ch10193] Issue: [ch11299]
1 parent c9d4dda commit e0a885c

File tree

11 files changed

+1041
-12
lines changed

11 files changed

+1041
-12
lines changed

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,32 @@ spec:
21952195
x-kubernetes-list-map-keys:
21962196
- type
21972197
x-kubernetes-list-type: map
2198+
instances:
2199+
description: Current state of PostgreSQL instances.
2200+
items:
2201+
properties:
2202+
name:
2203+
type: string
2204+
readyReplicas:
2205+
description: Total number of ready pods.
2206+
format: int32
2207+
type: integer
2208+
replicas:
2209+
description: Total number of non-terminated pods.
2210+
format: int32
2211+
type: integer
2212+
updatedReplicas:
2213+
description: Total number of non-terminated pods that have the
2214+
desired specification.
2215+
format: int32
2216+
type: integer
2217+
required:
2218+
- name
2219+
type: object
2220+
type: array
2221+
x-kubernetes-list-map-keys:
2222+
- name
2223+
x-kubernetes-list-type: map
21982224
observedGeneration:
21992225
description: observedGeneration represents the .metadata.generation
22002226
on which the status was based.

config/rbac/cluster/role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ rules:
4848
resources:
4949
- pods
5050
verbs:
51+
- delete
5152
- get
5253
- list
5354
- patch

config/rbac/namespace/role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ rules:
4848
resources:
4949
- pods
5050
verbs:
51+
- delete
5152
- get
5253
- list
5354
- patch

internal/controller/postgrescluster/controller.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ func (r *Reconciler) Reconcile(
147147
clusterReplicationSecret *v1.Secret
148148
clusterPodService *v1.Service
149149
instanceServiceAccount *v1.ServiceAccount
150+
instances *observedInstances
150151
patroniLeaderService *v1.Service
151152
primaryCertificate *v1.SecretProjection
152153
pgUser *v1.Secret
@@ -188,6 +189,9 @@ func (r *Reconciler) Reconcile(
188189
pgParameters.Mandatory.Add("archive_command",
189190
"pgbackrest --stanza="+pgbackrest.DefaultStanzaName+" archive-push %p")
190191

192+
if err == nil {
193+
instances, err = r.observeInstances(ctx, cluster)
194+
}
191195
if err == nil {
192196
err = r.reconcilePatroniStatus(ctx, cluster)
193197
}
@@ -229,7 +233,7 @@ func (r *Reconciler) Reconcile(
229233
if err == nil {
230234
instancesNames, err = r.reconcileInstanceSets(
231235
ctx, cluster, clusterConfigMap, clusterReplicationSecret,
232-
rootCA, clusterPodService, instanceServiceAccount,
236+
rootCA, clusterPodService, instanceServiceAccount, instances,
233237
patroniLeaderService, primaryCertificate)
234238
}
235239

internal/controller/postgrescluster/controller_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,7 @@ spec:
488488
"RevisionHistoryLimit": PointTo(BeEquivalentTo(0)),
489489
"ServiceName": Equal("carlos-pods"),
490490
"UpdateStrategy": Equal(appsv1.StatefulSetUpdateStrategy{
491-
Type: appsv1.RollingUpdateStatefulSetStrategyType,
492-
RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{
493-
Partition: new(int32),
494-
},
491+
Type: appsv1.OnDeleteStatefulSetStrategyType,
495492
}),
496493
}))
497494
})

0 commit comments

Comments
 (0)