Skip to content

Commit 947f87f

Browse files
author
Jeff McCormick
committed
fix pgo show backup when PVC_NAME is not set in config
1 parent 54cedf7 commit 947f87f

File tree

6 files changed

+43
-16
lines changed

6 files changed

+43
-16
lines changed

client/cmd/backup.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,19 @@ func showBackup(args []string) {
5151
return
5252
}
5353
for _, pod := range pods.Items {
54-
showItem(pod.Name, "crunchy-pvc")
54+
showItem(pod.Name)
5555
}
5656

5757
} else {
58-
showItem(arg, "crunchy-pvc")
58+
showItem(arg)
5959

6060
}
6161

6262
}
6363

6464
}
65-
func showItem(name string, pvcName string) {
65+
func showItem(name string ) {
66+
var pvcName string
6667
//print the pgbackups TPR
6768
result := tpr.PgBackup{}
6869
err := Tprclient.Get().
@@ -72,12 +73,24 @@ func showItem(name string, pvcName string) {
7273
Do().
7374
Into(&result)
7475
if err == nil {
75-
fmt.Printf("\npgbackup %s\n", name+" was found ")
76+
if result.Spec.PVC_NAME == "" {
77+
pvcName = name + "-backup-pvc"
78+
} else {
79+
pvcName = result.Spec.PVC_NAME
80+
}
81+
fmt.Printf("\npgbackup %s\n", name+" was found PVC_NAME is " + pvcName)
7682
} else if errors.IsNotFound(err) {
77-
fmt.Printf("\npgbackup %s\n", name+" was not found ")
83+
configPVC := viper.GetString("DB.PVC_NAME")
84+
if configPVC == "" {
85+
pvcName = name + "-backup-pvc"
86+
} else {
87+
pvcName = configPVC
88+
}
89+
fmt.Printf("\npgbackup %s\n", name+" was not found assuming PVC_NAME is " + pvcName)
7890
} else {
7991
log.Errorf("\npgbackup %s\n", name+" lookup error ")
8092
log.Error(err.Error())
93+
return
8194
}
8295

8396
//print the backup jobs if any exists
@@ -197,7 +210,9 @@ func getBackupParams(name string) (*tpr.PgBackup, error) {
197210

198211
spec := tpr.PgBackupSpec{}
199212
spec.Name = name
200-
spec.PVC_NAME = "crunchy-pvc"
213+
spec.PVC_NAME = viper.GetString("PVC_NAME")
214+
spec.PVC_ACCESS_MODE = viper.GetString("DB.PVC_ACCESS_MODE")
215+
spec.PVC_SIZE = viper.GetString("DB.PVC_SIZE")
201216
spec.CCP_IMAGE_TAG = viper.GetString("DB.CCP_IMAGE_TAG")
202217
spec.BACKUP_HOST = "basic"
203218
spec.BACKUP_USER = "master"
@@ -214,8 +229,6 @@ func getBackupParams(name string) (*tpr.PgBackup, error) {
214229
Into(&db)
215230
if err == nil {
216231
fmt.Println(name + " is a database")
217-
spec.PVC_NAME = db.Spec.PVC_NAME
218-
spec.CCP_IMAGE_TAG = db.Spec.CCP_IMAGE_TAG
219232
spec.BACKUP_HOST = db.Spec.Name
220233
spec.BACKUP_USER = db.Spec.PG_MASTER_USER
221234
spec.BACKUP_PASS = db.Spec.PG_MASTER_PASSWORD
@@ -231,8 +244,6 @@ func getBackupParams(name string) (*tpr.PgBackup, error) {
231244
Into(&cluster)
232245
if err == nil {
233246
fmt.Println(name + " is a cluster")
234-
spec.PVC_NAME = cluster.Spec.PVC_NAME
235-
spec.CCP_IMAGE_TAG = cluster.Spec.CCP_IMAGE_TAG
236247
spec.BACKUP_HOST = cluster.Spec.Name
237248
spec.BACKUP_USER = cluster.Spec.PG_MASTER_USER
238249
spec.BACKUP_PASS = cluster.Spec.PG_MASTER_PASSWORD

client/cmd/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func getDatabaseParams(name string) *tpr.PgDatabase {
136136
str = viper.GetString("DB.PVC_NAME")
137137
if str != "" {
138138
spec.PVC_NAME = str
139-
}
139+
}
140140
str = viper.GetString("DB.PVC_SIZE")
141141
if str != "" {
142142
spec.PVC_SIZE = str

docs/user-guide.asciidoc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ pgo delete cluster mycluster
132132
....
133133

134134
*Note*, when you delete a database or cluster, the operator
135-
will delete the unique PVC that pertains to the database if one
136-
exists. This is the case when you specify a PVC to be created
137-
for a database instead of using a shared PVC configuration.
135+
will NOT delete any associated PVCs used by the cluster or database.
138136

139137

140138
== Viewing PVC Information

operator/backup/backup.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"time"
2525

2626
"github.com/crunchydata/postgres-operator/tpr"
27+
"github.com/crunchydata/postgres-operator/operator/pvc"
2728

2829
"k8s.io/client-go/kubernetes"
2930

@@ -113,9 +114,22 @@ func Process(clientset *kubernetes.Clientset, client *rest.RESTClient, stopchan
113114
}
114115

115116
func addBackup(clientset *kubernetes.Clientset, client *rest.RESTClient, job *tpr.PgBackup) {
117+
var err error
116118
log.Info("creating PgBackup object")
117119
log.Info("created with Name=" + job.Spec.Name)
118120

121+
//create the PVC if necessary
122+
if job.Spec.PVC_NAME == "" {
123+
job.Spec.PVC_NAME = job.Spec.Name + "-backup-pvc"
124+
err = pvc.Create(clientset, job.Spec.PVC_NAME, job.Spec.PVC_ACCESS_MODE, job.Spec.PVC_SIZE)
125+
if err != nil {
126+
log.Error(err.Error())
127+
return
128+
}
129+
log.Info("created backup PVC =" + job.Spec.PVC_NAME)
130+
131+
}
132+
119133
//create the job -
120134
jobFields := JobTemplateFields{
121135
Name: job.Spec.Name,
@@ -128,7 +142,7 @@ func addBackup(clientset *kubernetes.Clientset, client *rest.RESTClient, job *tp
128142
}
129143

130144
var doc2 bytes.Buffer
131-
err := JobTemplate.Execute(&doc2, jobFields)
145+
err = JobTemplate.Execute(&doc2, jobFields)
132146
if err != nil {
133147
log.Error(err.Error())
134148
return

operator/database/database_strategy_1.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
log "github.com/Sirupsen/logrus"
2222
"text/template"
2323

24-
"github.com/crunchydata/postgres-operator/operator/pvc"
24+
//"github.com/crunchydata/postgres-operator/operator/pvc"
2525
"github.com/crunchydata/postgres-operator/operator/util"
2626
"github.com/crunchydata/postgres-operator/tpr"
2727

@@ -150,11 +150,13 @@ func (r DatabaseStrategy1) DeleteDatabase(clientset *kubernetes.Clientset, clien
150150
}
151151
log.Info("deleted pod " + db.Spec.Name)
152152

153+
/**
153154
err = pvc.Delete(clientset, db.Spec.Name+"-pvc")
154155
if err != nil {
155156
log.Error("error deleting pvc " + err.Error())
156157
return err
157158
}
159+
*/
158160
return err
159161

160162
}

tpr/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ func (el *PgClusterList) UnmarshalJSON(data []byte) error {
177177
type PgBackupSpec struct {
178178
Name string `json:"name"`
179179
PVC_NAME string `json:"pvcname"`
180+
PVC_ACCESS_MODE string `json:"pvcaccessmode"`
181+
PVC_SIZE string `json:"pvcsize"`
180182
CCP_IMAGE_TAG string `json:"ccpimagetag"`
181183
BACKUP_HOST string `json:"backuphost"`
182184
BACKUP_USER string `json:"backupuser"`

0 commit comments

Comments
 (0)