Skip to content

Commit 80cff40

Browse files
committed
Proper Detection of Previously Processed pgcluster
The pgcluster controller has been updated to properly detect whether or not a specific pgcluster custom resource was previously processed via the controller's 'onAdd' function. Specifically, the 'onAdd' function will now no longer place a pgcluster in a 'processed' status and attempt to call 'AddClusterBase' if it determines that the a previous call to 'AddClusterBase' completed successfully. This is indicated by either a value of 'completed' in the /spec/status' field of the pgcluster (which indicates that a previous call to 'AddClusterBase' successfully created the resources needed to bootstrap the PG cluster), or a value of 'pgcluster Initialized' in the '/status/state' field (which indicates that the cluster has been fully initialized). In addition, the check for an existing Kubernetes Deployment matching the name of the pgcluster, as well as the check to determine whether or not a pgcluster custom resource is in a 'processed' status prior to enqueuing it from the pgcluster controller's 'onAdd' function, have been removed, since both are no longer valid methods for determining whether or not to process a pgcluster. For instance, a Deployment matching the pgcluster name (i.e. the original primary for the cluster) might no longer exist if it was since scaled down and removed, while the 'processed' status does not properly indicate whether or not the various Kubernetes resources (e.g. Deployments) for the initial primary utilized to bootstrap the cluster have been created, nor does it properly indicate whether or not the PG cluster has been fully initialized. Issue: [ch9574]
1 parent aaeaf4e commit 80cff40

File tree

2 files changed

+10
-30
lines changed

2 files changed

+10
-30
lines changed

controller/pgcluster/pgclustercontroller.go

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,11 @@ type Controller struct {
4848

4949
// onAdd is called when a pgcluster is added
5050
func (c *Controller) onAdd(obj interface{}) {
51-
cluster := obj.(*crv1.Pgcluster)
52-
log.Debugf("[pgcluster Controller] ns %s onAdd %s", cluster.ObjectMeta.Namespace, cluster.ObjectMeta.SelfLink)
53-
54-
//handle the case when the operator restarts and don't
55-
//process already processed pgclusters
56-
if cluster.Status.State == crv1.PgclusterStateProcessed {
57-
log.Debug("pgcluster " + cluster.ObjectMeta.Name + " already processed")
58-
return
59-
}
60-
6151
key, err := cache.MetaNamespaceKeyFunc(obj)
6252
if err == nil {
6353
log.Debugf("cluster putting key in queue %s", key)
6454
c.Queue.Add(key)
6555
}
66-
6756
}
6857

6958
// RunWorker is a long-running function that will continually call the
@@ -106,25 +95,23 @@ func (c *Controller) processNextItem() bool {
10695
// parallel.
10796
defer c.Queue.Done(key)
10897

109-
// Invoke the method containing the business logic
110-
// in this case, the de-dupe logic is to test whether a cluster
111-
// deployment exists , if so, then we don't create another
112-
_, found, err := kubeapi.GetDeployment(c.PgclusterClientset, keyResourceName, keyNamespace)
113-
114-
if found {
115-
log.Debugf("cluster add - dep already found, not creating again")
116-
c.Queue.Forget(key)
117-
return true
118-
}
119-
12098
//get the pgcluster
12199
cluster := crv1.Pgcluster{}
122-
found, err = kubeapi.Getpgcluster(c.PgclusterClient, &cluster, keyResourceName, keyNamespace)
100+
found, err := kubeapi.Getpgcluster(c.PgclusterClient, &cluster, keyResourceName, keyNamespace)
123101
if !found {
124102
log.Debugf("cluster add - pgcluster not found, this is invalid")
125103
c.Queue.Forget(key) // NB(cbandy): This should probably be a retry.
126104
return true
127105
}
106+
log.Debugf("[pgcluster Controller] ns %s onAdd %s", cluster.ObjectMeta.Namespace, cluster.ObjectMeta.SelfLink)
107+
108+
if cluster.Spec.Status == crv1.CompletedStatus ||
109+
cluster.Status.State == crv1.PgclusterStateInitialized {
110+
log.Debugf("pgcluster Contoller: onAdd event received for cluster %s but "+
111+
"will not process because it either has a 'completed' status or is currently in an "+
112+
"'initialized' state", cluster.GetName())
113+
return true
114+
}
128115

129116
addIdentifier(&cluster)
130117

operator/cluster/cluster.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ const (
6363
func AddClusterBase(clientset *kubernetes.Clientset, client *rest.RESTClient, cl *crv1.Pgcluster, namespace string) {
6464
var err error
6565

66-
if cl.Spec.Status == crv1.CompletedStatus {
67-
errorMsg := "crv1 pgcluster " + cl.Spec.ClusterName + " is already marked complete, will not recreate"
68-
log.Warn(errorMsg)
69-
publishClusterCreateFailure(cl, errorMsg)
70-
return
71-
}
72-
7366
dataVolume, walVolume, tablespaceVolumes, err := pvc.CreateMissingPostgreSQLVolumes(
7467
clientset, cl, namespace, cl.Annotations[config.ANNOTATION_CURRENT_PRIMARY], cl.Spec.PrimaryStorage)
7568
if err != nil {

0 commit comments

Comments
 (0)