Skip to content

Commit f463907

Browse files
author
Jeff McCormick
committed
fix various pgo output formatting issues and bug in pgo show pvc output
1 parent fea1ff7 commit f463907

File tree

9 files changed

+71
-17
lines changed

9 files changed

+71
-17
lines changed

client/cmd/cluster.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,19 @@ func showCluster(args []string) {
3636
return
3737
}
3838

39+
if len(clusterList.Items) == 0 {
40+
fmt.Println("no clusters found")
41+
return
42+
}
43+
44+
itemFound := false
45+
3946
//each arg represents a cluster name or the special 'all' value
4047
for _, arg := range args {
4148
for _, cluster := range clusterList.Items {
4249
fmt.Println("")
4350
if arg == "all" || cluster.Spec.Name == arg {
51+
itemFound = true
4452
if PostgresVersion == "" || (PostgresVersion != "" && cluster.Spec.POSTGRES_FULL_VERSION == PostgresVersion) {
4553
fmt.Println("cluster : " + cluster.Spec.Name + " (" + cluster.Spec.POSTGRES_FULL_VERSION + ")")
4654
log.Debug("listing cluster " + arg)
@@ -58,6 +66,10 @@ func showCluster(args []string) {
5866
}
5967
}
6068
}
69+
if !itemFound {
70+
fmt.Println(arg + " was not found")
71+
}
72+
itemFound = false
6173
}
6274

6375
}

client/cmd/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pgo create cluster
3535
.`,
3636
Run: func(cmd *cobra.Command, args []string) {
3737
log.Debug("create called")
38-
if len(args) == 0 {
38+
if len(args) == 0 || args[0] != "cluster" {
3939
fmt.Println(`You must specify the type of resource to create. Valid resource types include:
4040
* cluster`)
4141
}

client/cmd/pvc.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
"fmt"
2222
log "github.com/Sirupsen/logrus"
23+
"github.com/crunchydata/postgres-operator/operator/util"
2324
"github.com/spf13/viper"
2425
"io"
2526
"io/ioutil"
@@ -51,13 +52,13 @@ func printPVC(pvcName string) {
5152
fmt.Printf("\nPVC %s\n", pvcName+" is not found")
5253
fmt.Println(err.Error())
5354
} else {
54-
fmt.Printf("\nPVC %s\n", pvc.Name+" is found")
55-
printPVCListing(pvc.Name)
55+
log.Debug("\nPVC %s\n", pvc.Name+" is found")
56+
PrintPVCListing(pvc.Name)
5657
}
5758

5859
}
5960

60-
func printPVCListing(pvcName string) {
61+
func PrintPVCListing(pvcName string) {
6162
var POD_PATH = viper.GetString("PGO.LSPVC_TEMPLATE")
6263
var PodTemplate *template.Template
6364
var err error
@@ -91,10 +92,19 @@ func printPVCListing(pvcName string) {
9192
}
9293
PodTemplate = template.Must(template.New("pod template").Parse(string(buf)))
9394

95+
pvcRoot := "/"
96+
if PVCRoot != "" {
97+
log.Debug("using " + PVCRoot + " as the PVC listing root")
98+
pvcRoot = PVCRoot
99+
fmt.Println(pvcName + "/" + pvcRoot)
100+
} else {
101+
fmt.Println(pvcName)
102+
}
103+
94104
podFields := PodTemplateFields{
95105
Name: podName,
96106
CO_IMAGE_TAG: viper.GetString("PGO.CO_IMAGE_TAG"),
97-
BACKUP_ROOT: "/",
107+
BACKUP_ROOT: pvcRoot,
98108
PVC_NAME: pvcName,
99109
}
100110

@@ -122,8 +132,13 @@ func printPVCListing(pvcName string) {
122132
}
123133
log.Debug("created pod " + resultPod.Name)
124134

125-
//sleep a bit for the pod to finish, replace later with watch or better
126-
time.Sleep(3000 * time.Millisecond)
135+
timeout := time.Duration(6 * time.Second)
136+
lo := v1.ListOptions{LabelSelector: "name=lspvc,pvcname=" + pvcName}
137+
podPhase := v1.PodSucceeded
138+
err = util.WaitUntilPod(Clientset, lo, podPhase, timeout, Namespace)
139+
if err != nil {
140+
log.Error("error waiting on lspvc pod to complete" + err.Error())
141+
}
127142

128143
//get lspvc pod output
129144
logOptions := v1.PodLogOptions{}

client/cmd/show.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const TREE_TRUNK = "└── "
2626
var PostgresVersion string
2727
var ShowPVC bool
2828
var ShowSecrets bool
29+
var PVCRoot string
2930

3031
// ShowCmd represents the show command
3132
var ShowCmd = &cobra.Command{
@@ -84,6 +85,7 @@ func init() {
8485

8586
ShowClusterCmd.Flags().BoolVarP(&ShowSecrets, "show-secrets", "s", false, "Show secrets ")
8687
ShowClusterCmd.Flags().StringVarP(&PostgresVersion, "version", "v", "", "The postgres version to filter on")
88+
ShowPVCCmd.Flags().StringVarP(&PVCRoot, "pvc-root", "r", "", "The PVC directory to list")
8789

8890
ShowBackupCmd.Flags().BoolVarP(&ShowPVC, "show-pvc", "p", false, "Show backup archive PVC listing ")
8991

client/cmd/upgrade.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,16 @@ func createUpgrade(args []string) {
174174
Do().
175175
Into(&result)
176176
if err == nil {
177-
fmt.Println("pgupgrade " + arg + " was found so we will not create it")
177+
log.Debug("pgupgrade " + arg + " was found so we will not create it")
178178
break
179179
} else if kerrors.IsNotFound(err) {
180-
fmt.Println("pgupgrade " + arg + " not found so we will create it")
180+
log.Debug("pgupgrade " + arg + " not found so we will create it")
181181
} else {
182182
log.Error("error getting pgupgrade " + arg)
183183
log.Error(err.Error())
184184
break
185185
}
186+
186187
// Create an instance of our TPR
187188
newInstance, err = getUpgradeParams(arg)
188189
if err == nil {
@@ -193,8 +194,9 @@ func createUpgrade(args []string) {
193194
Do().Into(&result)
194195
if err != nil {
195196
log.Error("error in creating PgUpgrade TPR instance", err.Error())
197+
} else {
198+
fmt.Println("created PgUpgrade " + arg)
196199
}
197-
fmt.Println("created PgUpgrade " + arg)
198200
}
199201

200202
}

examples/.pgo.lspvc-template.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"metadata": {
55
"name": "{{.Name}}",
66
"labels": {
7-
"name": "lspvc"
7+
"name": "lspvc",
8+
"pvcname": "{{.PVC_NAME}}"
89
}
910
},
1011
"spec": {

examples/operator/create-pv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1717

1818
echo "create the test PV and PVC using the HostPath dir"
19-
for i in {16..20}
19+
for i in {1..60}
2020
do
2121
echo "creating PV crunchy-pv-$i"
2222
export COUNTER=$i

operator/cluster/cluster.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/crunchydata/postgres-operator/tpr"
2828

2929
"k8s.io/client-go/kubernetes"
30+
kerrors "k8s.io/client-go/pkg/api/errors"
3031
"k8s.io/client-go/pkg/fields"
3132
"k8s.io/client-go/rest"
3233
"k8s.io/client-go/tools/cache"
@@ -209,6 +210,27 @@ func deleteCluster(clientset *kubernetes.Clientset, client *rest.RESTClient, cl
209210
}
210211
strategy.DeleteCluster(clientset, client, cl, namespace)
211212
util.DeleteDatabaseSecrets(clientset, cl.Spec.Name, namespace)
213+
//remove the backup PVC if exists
214+
pvcName := cl.Spec.Name + "-backup-pvc-empty"
215+
err := pvc.Delete(clientset, pvcName, namespace)
216+
if err != nil {
217+
log.Error("error deleting pvc " + pvcName)
218+
}
219+
//delete any upgrade for this cluster
220+
err = client.Delete().
221+
Resource("pgupgrades").
222+
Namespace(namespace).
223+
Name(cl.Spec.Name).
224+
Do().
225+
Error()
226+
if err == nil {
227+
log.Info("deleted pgupgrade " + cl.Spec.Name)
228+
} else if kerrors.IsNotFound(err) {
229+
log.Info("will not delete pgupgrade, not found for " + cl.Spec.Name)
230+
} else {
231+
log.Error("error deleting pgupgrade " + cl.Spec.Name)
232+
log.Error(err.Error())
233+
}
212234

213235
}
214236

operator/util/waituntil.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ func WaitUntilPod(clientset *kubernetes.Clientset, lo v1.ListOptions, podPhase v
3939

4040
conditions := []watch.ConditionFunc{
4141
func(event watch.Event) (bool, error) {
42-
log.Info("watch Modified called")
42+
log.Debug("watch Modified called")
4343
gotpod2 := event.Object.(*v1.Pod)
44-
log.Info("pod2 phase=" + gotpod2.Status.Phase)
44+
log.Debug("pod2 phase=" + gotpod2.Status.Phase)
4545
if gotpod2.Status.Phase == podPhase {
4646
return true, nil
4747
}
@@ -50,7 +50,7 @@ func WaitUntilPod(clientset *kubernetes.Clientset, lo v1.ListOptions, podPhase v
5050
},
5151
}
5252

53-
log.Info("before watch.Until")
53+
log.Debug("before watch.Until")
5454

5555
var lastEvent *watch.Event
5656
lastEvent, err = watch.Until(timeout, fw, conditions...)
@@ -62,7 +62,7 @@ func WaitUntilPod(clientset *kubernetes.Clientset, lo v1.ListOptions, podPhase v
6262
log.Error("expected event")
6363
return err
6464
}
65-
log.Info("after watch.Until")
65+
log.Debug("after watch.Until")
6666
return err
6767

6868
}
@@ -83,7 +83,7 @@ func WaitUntilPodIsDeleted(clientset *kubernetes.Clientset, podname string, time
8383
conditions := []watch.ConditionFunc{
8484
func(event watch.Event) (bool, error) {
8585
if event.Type == watch.Deleted {
86-
log.Info("pod delete event received in WaitUntilPodIsDeleted")
86+
log.Debug("pod delete event received in WaitUntilPodIsDeleted")
8787
return true, nil
8888
}
8989
return false, nil

0 commit comments

Comments
 (0)