Skip to content

Commit 110ad00

Browse files
author
Jeff McCormick
committed
add logic to not create backups or clusters on restart of operator
1 parent 9e0ff6d commit 110ad00

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

operator/backup/backup.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ func Process(clientset *kubernetes.Clientset, client *rest.RESTClient, stopchan
113113

114114
func addBackup(clientset *kubernetes.Clientset, client *rest.RESTClient, job *tpr.PgBackup, namespace string) {
115115
var err error
116+
117+
if job.Spec.BACKUP_STATUS == tpr.UPGRADE_COMPLETED_STATUS {
118+
log.Warn("pgbackup " + job.Spec.Name + " already completed, not recreating it")
119+
return
120+
}
121+
116122
log.Info("creating PgBackup object" + " in namespace " + namespace)
117123
log.Info("created with Name=" + job.Spec.Name + " in namespace " + namespace)
118124

operator/cluster/cluster.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,20 @@ func Process(clientset *kubernetes.Clientset, client *rest.RESTClient, stopchan
9595
deleteCluster(clientset, client, cluster, namespace)
9696
}
9797

98+
/**
9899
updateHandler := func(old interface{}, obj interface{}) {
99100
cluster := obj.(*tpr.PgCluster)
100101
eventchan <- cluster
102+
log.Info("updateHandler called")
101103
}
104+
*/
102105

103106
_, controller := cache.NewInformer(
104107
source,
105108
&tpr.PgCluster{},
106109
time.Second*10,
107110
cache.ResourceEventHandlerFuncs{
108111
AddFunc: createAddHandler,
109-
UpdateFunc: updateHandler,
110112
DeleteFunc: createDeleteHandler,
111113
})
112114

@@ -126,6 +128,11 @@ func Process(clientset *kubernetes.Clientset, client *rest.RESTClient, stopchan
126128
func addCluster(clientset *kubernetes.Clientset, client *rest.RESTClient, cl *tpr.PgCluster, namespace string) {
127129
var err error
128130

131+
if cl.Spec.STATUS == tpr.UPGRADE_COMPLETED_STATUS {
132+
log.Warn("tpr pgcluster " + cl.Spec.ClusterName + " is already marked complete, will not recreate")
133+
return
134+
}
135+
129136
//create the PVC for the master if required
130137
if cl.Spec.PVC_NAME == "" {
131138
cl.Spec.PVC_NAME = cl.Spec.Name + "-pvc"
@@ -174,6 +181,11 @@ func addCluster(clientset *kubernetes.Clientset, client *rest.RESTClient, cl *tp
174181

175182
strategy.AddCluster(clientset, client, cl, namespace)
176183

184+
err = util.Patch(client, "/spec/status", tpr.UPGRADE_COMPLETED_STATUS, "pgclusters", cl.Spec.Name, namespace)
185+
if err != nil {
186+
log.Error("error in status patch " + err.Error())
187+
}
188+
177189
}
178190

179191
func setFullVersion(tprclient *rest.RESTClient, cl *tpr.PgCluster, namespace string) {

operator/cluster/cluster_strategy_1.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (r ClusterStrategy1) AddCluster(clientset *kubernetes.Clientset, client *re
125125
Port: cl.Spec.Port,
126126
CCP_IMAGE_TAG: cl.Spec.CCP_IMAGE_TAG,
127127
PVC_NAME: cl.Spec.PVC_NAME,
128-
OPERATOR_LABELS: util.GetLabels(cl.Spec.Name, cl.Spec.ClusterName, false),
128+
OPERATOR_LABELS: util.GetLabels(cl.Spec.Name, cl.Spec.ClusterName, false, false),
129129
BACKUP_PVC_NAME: util.CreateBackupPVCSnippet(cl.Spec.BACKUP_PVC_NAME),
130130
BACKUP_PATH: cl.Spec.BACKUP_PATH,
131131
PGDATA_PATH_OVERRIDE: cl.Spec.Name,
@@ -172,7 +172,7 @@ func (r ClusterStrategy1) AddCluster(clientset *kubernetes.Clientset, client *re
172172
PG_MASTER_HOST: cl.Spec.PG_MASTER_HOST,
173173
PG_DATABASE: cl.Spec.PG_DATABASE,
174174
REPLICAS: cl.Spec.REPLICAS,
175-
OPERATOR_LABELS: util.GetLabels(cl.Spec.Name, cl.Spec.ClusterName, false),
175+
OPERATOR_LABELS: util.GetLabels(cl.Spec.Name, cl.Spec.ClusterName, false, true),
176176
SECURITY_CONTEXT: util.CreateSecContext(cl.Spec.FS_GROUP, cl.Spec.SUPPLEMENTAL_GROUPS),
177177
PGROOT_SECRET_NAME: cl.Spec.PGROOT_SECRET_NAME,
178178
PGMASTER_SECRET_NAME: cl.Spec.PGMASTER_SECRET_NAME,
@@ -352,7 +352,7 @@ func (r ClusterStrategy1) PrepareClone(clientset *kubernetes.Clientset, tprclien
352352
PVC_NAME: cl.Spec.PVC_NAME,
353353
PG_MASTER_HOST: cl.Spec.PG_MASTER_HOST,
354354
PG_DATABASE: cl.Spec.PG_DATABASE,
355-
OPERATOR_LABELS: util.GetLabels(cloneName, cloneName, true),
355+
OPERATOR_LABELS: util.GetLabels(cloneName, cloneName, true, false),
356356
REPLICAS: "1",
357357
SECURITY_CONTEXT: util.CreateSecContext(cl.Spec.FS_GROUP, cl.Spec.SUPPLEMENTAL_GROUPS),
358358
PGROOT_SECRET_NAME: cl.Spec.PGROOT_SECRET_NAME,

operator/util/util.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,14 @@ func ScaleDeployment(clientset *kubernetes.Clientset, deploymentName, namespace
173173
return err
174174
}
175175

176-
func GetLabels(name, clustername string, clone bool) string {
176+
func GetLabels(name, clustername string, clone, replica bool) string {
177177
var output string
178178
if clone {
179179
output += fmt.Sprintf("\"clone\": \"%s\",\n", "true")
180180
}
181+
if replica {
182+
output += fmt.Sprintf("\"replica\": \"%s\",\n", "true")
183+
}
181184
output += fmt.Sprintf("\"name\": \"%s\",\n", name)
182185
output += fmt.Sprintf("\"pg-cluster\": \"%s\"\n", clustername)
183186
return output

tpr/cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type PgClusterSpec struct {
5151
PGUSER_SECRET_NAME string `json:"pgusersecretname"`
5252
PGROOT_SECRET_NAME string `json:"pgrootsecretname"`
5353
PGMASTER_SECRET_NAME string `json:"pgmastersecretname"`
54+
STATUS string `json:"status"`
5455
}
5556

5657
type PgCluster struct {

0 commit comments

Comments
 (0)