Skip to content

Commit b2c49ff

Browse files
tjmoore4andrewlecuyer
authored andcommitted
Postgres Operator automated upgrade status checks
Checks were added for the various PGO cli operations to validate that the cluster in question is either current to this release of the Postgres Operator, or has been upgraded to the current version. This is to ensure that unexpected results are not achieved due to pgclusters that are out of spec. A check was also added to ensure the ConfigMap Controller only syncs configmaps on clusters that have already been upgraded.
1 parent eb5c3a4 commit b2c49ff

File tree

13 files changed

+119
-5
lines changed

13 files changed

+119
-5
lines changed

apiserver/backrestservice/backrestimpl.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,14 @@ func CreateBackup(request *msgs.CreateBackrestBackupRequest, ns, pgouser string)
125125
return resp
126126
}
127127

128+
// check if the current cluster is not upgraded to the deployed
129+
// Operator version. If not, do not allow the command to complete
130+
if cluster.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
131+
resp.Status.Code = msgs.Error
132+
resp.Status.Msg = fmt.Sprintf("%s %s", cluster.Name, msgs.UpgradeError)
133+
return resp
134+
}
135+
128136
if cluster.Labels[config.LABEL_BACKREST] != "true" {
129137
resp.Status.Code = msgs.Error
130138
resp.Status.Msg = clusterName + " does not have pgbackrest enabled"
@@ -472,7 +480,15 @@ func Restore(request *msgs.RestoreRequest, ns, pgouser string) msgs.RestoreRespo
472480
return resp
473481
}
474482

475-
//verify that the cluster we are restoring from has backrest enabled
483+
// check if the current cluster is not upgraded to the deployed
484+
// Operator version. If not, do not allow the command to complete
485+
if cluster.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
486+
resp.Status.Code = msgs.Error
487+
resp.Status.Msg = fmt.Sprintf("%s %s", cluster.Name, msgs.UpgradeError)
488+
return resp
489+
}
490+
491+
// verify that the cluster we are restoring from has backrest enabled
476492
if cluster.Labels[config.LABEL_BACKREST] != "true" {
477493
resp.Status.Code = msgs.Error
478494
resp.Status.Msg = "can't restore, cluster restoring from does not have backrest enabled"

apiserver/catservice/catimpl.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ func Cat(request *msgs.CatRequest, ns string) msgs.CatResponse {
5555
return resp
5656
}
5757

58+
// check if the current cluster is not upgraded to the deployed
59+
// Operator version. If not, do not allow the command to complete
60+
if cluster.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
61+
resp.Status.Code = msgs.Error
62+
resp.Status.Msg = cluster.Name + msgs.UpgradeError
63+
return resp
64+
}
65+
5866
err = validateArgs(request.Args)
5967
if err != nil {
6068
resp.Status.Code = msgs.Error

apiserver/cloneservice/cloneimpl.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3333
)
3434

35-
// Clone allows a user to clone a cluster into a new deployment
35+
// Clone allows a user to clone a cluster into a new deployment
3636
func Clone(request *msgs.CloneRequest, namespace, pgouser string) msgs.CloneResponse {
3737
log.Debugf("clone called with ")
3838

@@ -67,6 +67,14 @@ func Clone(request *msgs.CloneRequest, namespace, pgouser string) msgs.CloneResp
6767
return response
6868
}
6969

70+
// check if the current cluster is not upgraded to the deployed
71+
// Operator version. If not, do not allow the command to complete
72+
if sourcePgcluster.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
73+
response.Status.Code = msgs.Error
74+
response.Status.Msg = sourcePgcluster.Name + msgs.UpgradeError
75+
return response
76+
}
77+
7078
// now, let's ensure the target pgCluster does *not* exist
7179
targetPgcluster := crv1.Pgcluster{}
7280
targetPgclusterExists, _ := kubeapi.Getpgcluster(apiserver.RESTClient,

apiserver/clusterservice/clusterimpl.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ func DeleteCluster(name, selector string, deleteData, deleteBackups bool, ns, pg
7474

7575
for _, cluster := range clusterList.Items {
7676

77+
// check if the current cluster is not upgraded to the deployed
78+
// Operator version. If not, do not allow the command to complete
79+
if cluster.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
80+
response.Status.Code = msgs.Error
81+
response.Status.Msg = cluster.Name + msgs.UpgradeError
82+
return response
83+
}
84+
7785
log.Debugf("deleting cluster %s", cluster.Spec.Name)
7886
taskName := cluster.Spec.Name + "-rmdata"
7987
log.Debugf("creating taskName %s", taskName)

apiserver/clusterservice/scaleimpl.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ func ScaleCluster(name, replicaCount, storageConfig, nodeLabel,
6767
return response
6868
}
6969

70+
// check if the current cluster is not upgraded to the deployed
71+
// Operator version. If not, do not allow the command to complete
72+
if cluster.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
73+
response.Status.Code = msgs.Error
74+
response.Status.Msg = cluster.Name + msgs.UpgradeError
75+
return response
76+
}
77+
7078
spec := crv1.PgreplicaSpec{}
7179

7280
//refer to the cluster's replica storage setting by default

apiserver/failoverservice/failoverimpl.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@ func CreateFailover(request *msgs.CreateFailoverRequest, ns, pgouser string) msg
4040
resp.Status.Msg = ""
4141
resp.Results = make([]string, 0)
4242

43-
_, err = validateClusterName(request.ClusterName, ns)
43+
cluster, err := validateClusterName(request.ClusterName, ns)
4444
if err != nil {
4545
resp.Status.Code = msgs.Error
4646
resp.Status.Msg = err.Error()
4747
return resp
4848
}
4949

50+
// check if the current cluster is not upgraded to the deployed
51+
// Operator version. If not, do not allow the command to complete
52+
if cluster.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
53+
resp.Status.Code = msgs.Error
54+
resp.Status.Msg = cluster.Name + msgs.UpgradeError
55+
return resp
56+
}
57+
5058
if request.Target != "" {
5159
_, err = isValidFailoverTarget(request.Target, request.ClusterName, ns)
5260
if err != nil {
@@ -166,6 +174,7 @@ func validateClusterName(clusterName, ns string) (*crv1.Pgcluster, error) {
166174
cluster := crv1.Pgcluster{}
167175
found, err := kubeapi.Getpgcluster(apiserver.RESTClient,
168176
&cluster, clusterName, ns)
177+
169178
if !found {
170179
return &cluster, errors.New("no cluster found named " + clusterName)
171180
}

apiserver/loadservice/loadimpl.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ func Load(request *msgs.LoadRequest, ns, pgouser string) msgs.LoadResponse {
142142
resp.Status.Msg = err.Error()
143143
return resp
144144
}
145+
146+
// check if the current cluster is not upgraded to the deployed
147+
// Operator version. If not, do not allow the command to complete
148+
if cl.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
149+
resp.Status.Code = msgs.Error
150+
resp.Status.Msg = cl.Name + msgs.UpgradeError
151+
return resp
152+
}
153+
145154
clusterList.Items = append(clusterList.Items, cl)
146155
}
147156
}

apiserver/pgbouncerservice/pgbouncerimpl.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ func CreatePgbouncer(request *msgs.CreatePgbouncerRequest, ns, pgouser string) m
7979
}
8080

8181
for _, cluster := range clusterList.Items {
82+
83+
// check if the current cluster is not upgraded to the deployed
84+
// Operator version. If not, do not allow the command to complete
85+
if cluster.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
86+
resp.Status.Code = msgs.Error
87+
resp.Status.Msg = cluster.Name + msgs.UpgradeError
88+
return resp
89+
}
90+
8291
log.Debugf("adding pgbouncer to cluster [%s]", cluster.Name)
8392

8493
resources := v1.ResourceList{}

apiserver/pgdumpservice/pgdumpimpl.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ func CreatepgDump(request *msgs.CreatepgDumpBackupRequest, ns string) msgs.Creat
111111
return resp
112112
}
113113

114+
// check if the current cluster is not upgraded to the deployed
115+
// Operator version. If not, do not allow the command to complete
116+
if cluster.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
117+
resp.Status.Code = msgs.Error
118+
resp.Status.Msg = cluster.Name + msgs.UpgradeError
119+
return resp
120+
}
121+
114122
RemovePgDumpJob(clusterName+pgDumpJobExtension, ns)
115123

116124
result := crv1.Pgtask{}

apiserver/reloadservice/reloadimpl.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ func Reload(request *msgs.ReloadRequest, ns, username string) msgs.ReloadRespons
8585
return resp
8686
}
8787

88+
// check if the current cluster is not upgraded to the deployed
89+
// Operator version. If not, do not allow the command to complete
90+
if cluster.Annotations[config.ANNOTATION_IS_UPGRADED] == config.ANNOTATIONS_FALSE {
91+
resp.Status.Code = msgs.Error
92+
resp.Status.Msg = cluster.Name + msgs.UpgradeError
93+
return resp
94+
}
95+
8896
var podList *v1.PodList
8997
selector := config.LABEL_SERVICE_NAME + "=" + cluster.Spec.Name
9098
podList, err = kubeapi.GetPods(apiserver.Clientset, selector, ns)

0 commit comments

Comments
 (0)