Skip to content

Commit a00896a

Browse files
author
jmccormick2001
committed
update the pgupgrade status logic to fix a patch race condition, also update the various crv1 status to be more precise as to what is being updated in the status field
1 parent 8812ad3 commit a00896a

File tree

7 files changed

+41
-10
lines changed

7 files changed

+41
-10
lines changed

apis/cr/v1/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ type PgContainerResources struct {
5959
}
6060

6161
// JobCompletedStatus ....
62-
const JobCompletedStatus = "completed"
62+
const JobCompletedStatus = "job completed"
6363

6464
// JobSubmittedStatus ....
65-
const JobSubmittedStatus = "submitted"
65+
const JobSubmittedStatus = "job submitted"
6666

6767
// JobErrorStatus ....
68-
const JobErrorStatus = "error"
68+
const JobErrorStatus = "job error"

apis/cr/v1/task.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ const PgtaskAddPolicies = "addpolicies"
3737
const PgtaskWorkflow = "workflow"
3838
const PgtaskWorkflowCreateClusterType = "createcluster"
3939
const PgtaskWorkflowBackrestRestoreType = "pgbackrestrestore"
40-
const PgtaskWorkflowSubmittedStatus = "submitted"
41-
const PgtaskWorkflowCompletedStatus = "completed"
40+
const PgtaskWorkflowSubmittedStatus = "task submitted"
41+
const PgtaskWorkflowCompletedStatus = "task completed"
4242
const PgtaskWorkflowID = "workflowid"
4343

4444
const PgtaskWorkflowBackrestRestorePVCCreatedStatus = "restored PVC created"

apis/cr/v1/upgrade.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
)
2121

2222
// UpgradeCompletedStatus ....
23-
const UpgradeCompletedStatus = "completed"
23+
const UpgradeCompletedStatus = "upgrade completed"
2424

2525
// UpgradeSubmittedStatus ....
26-
const UpgradeSubmittedStatus = "submitted"
26+
const UpgradeSubmittedStatus = "upgrade submitted"
2727

2828
// PgupgradeResourcePlural ...
2929
const PgupgradeResourcePlural = "pgupgrades"

kubeapi/pgupgrade.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,21 @@ func Createpgupgrade(client *rest.RESTClient, upgrade *crv1.Pgupgrade, namespace
174174

175175
return err
176176
}
177+
178+
// Updatepgupgrade updates a pgupgrade
179+
func Updatepgupgrade(client *rest.RESTClient, upgrade *crv1.Pgupgrade, name, namespace string) error {
180+
181+
err := client.Put().
182+
Name(name).
183+
Namespace(namespace).
184+
Resource(crv1.PgupgradeResourcePlural).
185+
Body(upgrade).
186+
Do().
187+
Error()
188+
if err != nil {
189+
log.Error("error updating pgupgrade " + err.Error())
190+
}
191+
192+
log.Debugf("updated pgupgrade %s", upgrade.Name)
193+
return err
194+
}

operator/cluster/cluster.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,17 @@ func AddUpgradeBase(clientset *kubernetes.Clientset, client *rest.RESTClient, up
304304
if upgrade.Spec.UpgradeType == "minor" {
305305
err = strategy.MinorUpgrade(clientset, client, cl, upgrade, namespace)
306306
if err == nil {
307+
/**
307308
err = util.Patch(client, "/spec/upgradestatus", crv1.UpgradeCompletedStatus, crv1.PgupgradeResourcePlural, upgrade.Spec.Name, namespace)
309+
if err != nil {
310+
log.Error(err)
311+
log.Error("could not patch the ugpradestatus")
312+
}
313+
log.Debug("jeff updated pgupgrade to completed")
314+
*/
315+
} else {
316+
log.Error(err)
317+
log.Error("error in doing minor upgrade")
308318
}
309319
} else if upgrade.Spec.UpgradeType == "major" {
310320
err = strategy.MajorUpgrade(clientset, client, cl, upgrade, namespace)

operator/cluster/upgrade.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
log "github.com/Sirupsen/logrus"
2020
crv1 "github.com/crunchydata/postgres-operator/apis/cr/v1"
2121
"github.com/crunchydata/postgres-operator/kubeapi"
22-
"github.com/crunchydata/postgres-operator/util"
22+
//"github.com/crunchydata/postgres-operator/util"
2323
//v1batch "k8s.io/api/batch/v1"
2424
//meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
//"k8s.io/apimachinery/pkg/watch"
@@ -44,9 +44,11 @@ func AddUpgrade(clientset *kubernetes.Clientset, restclient *rest.RESTClient, up
4444
log.Error("error adding upgrade" + err.Error())
4545
} else {
4646
//update the upgrade CRD status to submitted
47-
err = util.Patch(restclient, "/spec/upgradestatus", crv1.UpgradeSubmittedStatus, "pgupgrades", upgrade.Spec.Name, namespace)
47+
upgrade.Spec.UpgradeStatus = crv1.UpgradeSubmittedStatus
48+
kubeapi.Updatepgupgrade(restclient, upgrade, upgrade.Spec.Name, namespace)
49+
// err = util.Patch(restclient, "/spec/upgradestatus", crv1.UpgradeSubmittedStatus, "pgupgrades", upgrade.Spec.Name, namespace)
4850
if err != nil {
49-
log.Error("error patching upgrade" + err.Error())
51+
log.Error("error setting upgrade status " + err.Error())
5052
}
5153
}
5254

operator/cluster/upgrade_strategy_1.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (r Strategy1) MinorUpgrade(clientset *kubernetes.Clientset, restclient *res
6464
err = util.Patch(restclient, "/spec/ccpimagetag", upgrade.Spec.CCPImageTag, crv1.PgclusterResourcePlural, cl.Spec.Name, namespace)
6565

6666
//update the upgrade CRD status to completed
67+
log.Debug("jeff patch pgupgrade %s to %s here in upgrade_strategy", upgrade.Spec.Name, crv1.UpgradeCompletedStatus)
6768
err = kubeapi.Patchpgupgrade(restclient, upgrade.Spec.Name, "/spec/upgradestatus", crv1.UpgradeCompletedStatus, namespace)
6869
if err != nil {
6970
log.Error("error in upgradestatus patch " + err.Error())

0 commit comments

Comments
 (0)