Skip to content

Commit 7194f98

Browse files
author
jmccormick2001
committed
update pgo show pvc to support --all flag
1 parent f1f08f1 commit 7194f98

File tree

7 files changed

+56
-25
lines changed

7 files changed

+56
-25
lines changed

apiserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func main() {
9292
//here
9393
r.HandleFunc("/policiesdelete/{name}", policyservice.DeletePolicyHandler).Methods("GET")
9494
r.HandleFunc("/workflow/{id}", workflowservice.ShowWorkflowHandler).Methods("GET")
95-
r.HandleFunc("/pvc/{pvcname}", pvcservice.ShowPVCHandler).Methods("GET")
95+
r.HandleFunc("/showpvc", pvcservice.ShowPVCHandler).Methods("POST")
9696
r.HandleFunc("/policies/apply", policyservice.ApplyPolicyHandler).Methods("POST")
9797
r.HandleFunc("/label", labelservice.LabelHandler).Methods("POST")
9898
r.HandleFunc("/labeldelete", labelservice.DeleteLabelHandler).Methods("POST")

apiserver/pvcservice/pvcimpl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type containerResourcesTemplateFields struct {
5959
}
6060

6161
// ShowPVC ...
62-
func ShowPVC(nodeLabel, pvcName, PVCRoot, ns string) ([]string, error) {
62+
func ShowPVC(allflag, nodeLabel, pvcName, PVCRoot, ns string) ([]string, error) {
6363
pvcList := make([]string, 1)
6464

6565
if nodeLabel != "" {
@@ -69,7 +69,7 @@ func ShowPVC(nodeLabel, pvcName, PVCRoot, ns string) ([]string, error) {
6969
}
7070
}
7171

72-
if pvcName == "all" {
72+
if allflag == "true" {
7373
selector := config.LABEL_PGREMOVE + "=true"
7474

7575
pvcs, err := kubeapi.GetPVCs(apiserver.Clientset, selector, ns)

apiserver/pvcservice/pvcservice.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"encoding/json"
2020
"github.com/crunchydata/postgres-operator/apiserver"
2121
msgs "github.com/crunchydata/postgres-operator/apiservermsgs"
22-
"github.com/gorilla/mux"
2322
log "github.com/sirupsen/logrus"
2423
"net/http"
2524
)
@@ -30,12 +29,14 @@ func ShowPVCHandler(w http.ResponseWriter, r *http.Request) {
3029
var err error
3130
var username, ns string
3231

33-
vars := mux.Vars(r)
34-
pvcname := vars["pvcname"]
35-
pvcroot := r.URL.Query().Get("pvcroot")
36-
clientVersion := r.URL.Query().Get("version")
37-
nodeLabel := r.URL.Query().Get("nodelabel")
38-
namespace := r.URL.Query().Get("namespace")
32+
var request msgs.ShowPVCRequest
33+
_ = json.NewDecoder(r.Body).Decode(&request)
34+
35+
pvcname := request.PVCName
36+
pvcroot := request.PVCRoot
37+
clientVersion := request.ClientVersion
38+
nodeLabel := request.NodeLabel
39+
namespace := request.Namespace
3940

4041
log.Debugf("ShowPVCHandler parameters pvcroot [%s], version [%s] namespace [%s] pvcname [%s] nodeLabel [%]", pvcroot, clientVersion, namespace, pvcname, nodeLabel)
4142

@@ -72,7 +73,7 @@ func ShowPVCHandler(w http.ResponseWriter, r *http.Request) {
7273
return
7374
}
7475

75-
resp.Results, err = ShowPVC(nodeLabel, pvcname, pvcroot, ns)
76+
resp.Results, err = ShowPVC(request.Allflag, nodeLabel, pvcname, pvcroot, ns)
7677
if err != nil {
7778
resp.Status.Code = msgs.Error
7879
resp.Status.Msg = err.Error()

apiservermsgs/pvcmsgs.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ limitations under the License.
1717

1818
import ()
1919

20+
// ShowPVCRequest ...
21+
type ShowPVCRequest struct {
22+
PVCName string
23+
NodeLabel string
24+
PVCRoot string
25+
Selector string
26+
ClientVersion string
27+
Namespace string
28+
Allflag string
29+
}
30+
2031
// ShowPVCResponse ...
2132
type ShowPVCResponse struct {
2233
Results []string

pgo/api/pvc.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,32 @@ package api
1616
*/
1717

1818
import (
19+
"bytes"
1920
"encoding/json"
2021
"fmt"
2122
msgs "github.com/crunchydata/postgres-operator/apiservermsgs"
2223
log "github.com/sirupsen/logrus"
2324
"net/http"
2425
)
2526

26-
func ShowPVC(httpclient *http.Client, pvcName, pvcRoot string, SessionCredentials *msgs.BasicAuthCredentials, nodeLabel, ns string) (msgs.ShowPVCResponse, error) {
27+
func ShowPVC(httpclient *http.Client, request *msgs.ShowPVCRequest, SessionCredentials *msgs.BasicAuthCredentials) (msgs.ShowPVCResponse, error) {
2728

2829
var response msgs.ShowPVCResponse
2930

30-
url := SessionCredentials.APIServerURL + "/pvc/" + pvcName + "?pvcroot=" + pvcRoot + "&nodelabel=" + nodeLabel + "&version=" + msgs.PGO_VERSION + "&namespace=" + ns
31+
url := SessionCredentials.APIServerURL + "/showpvc"
3132
log.Debugf("ShowPVC called...[%s]", url)
3233

33-
action := "GET"
34-
req, err := http.NewRequest(action, url, nil)
34+
jsonValue, _ := json.Marshal(request)
35+
log.Debugf("ShowPVC called...[%s]", url)
36+
37+
action := "POST"
38+
req, err := http.NewRequest(action, url, bytes.NewBuffer(jsonValue))
3539
if err != nil {
3640
return response, err
3741
}
38-
42+
req.Header.Set("Content-Type", "application/json")
3943
req.SetBasicAuth(SessionCredentials.Username, SessionCredentials.Password)
44+
4045
resp, err := httpclient.Do(req)
4146
if err != nil {
4247
fmt.Println("Error: Do: ", err)

pgo/cmd/pvc.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,40 @@ import (
2121
"github.com/crunchydata/postgres-operator/pgo/api"
2222
log "github.com/sirupsen/logrus"
2323
"os"
24+
"strconv"
2425
)
2526

2627
func showPVC(args []string, ns string) {
2728
log.Debugf("showPVC called %v", args)
2829

29-
if args[0] == "all" {
30+
// ShowPVCRequest ...
31+
r := msgs.ShowPVCRequest{}
32+
r.Namespace = ns
33+
r.Allflag = strconv.FormatBool(AllFlag)
34+
r.ClientVersion = msgs.PGO_VERSION
35+
r.NodeLabel = NodeLabel
36+
r.PVCRoot = PVCRoot
37+
38+
if AllFlag {
3039
//special case to just list all the PVCs
31-
printPVC(args[0], "", NodeLabel, ns)
40+
r.PVCName = ""
41+
r.PVCRoot = ""
42+
printPVC(&r)
3243
} else {
3344
//args are a list of pvc names...for this case show details
3445
for _, arg := range args {
46+
r.PVCName = arg
3547
log.Debugf("show pvc called for %s", arg)
36-
printPVC(arg, PVCRoot, NodeLabel, ns)
48+
printPVC(&r)
3749

3850
}
3951
}
4052

4153
}
4254

43-
func printPVC(pvcName, pvcRoot, nodeLabel, ns string) {
55+
func printPVC(r *msgs.ShowPVCRequest) {
4456

45-
response, err := api.ShowPVC(httpclient, pvcName, pvcRoot, &SessionCredentials, nodeLabel, ns)
57+
response, err := api.ShowPVC(httpclient, r, &SessionCredentials)
4658

4759
if err != nil {
4860
fmt.Println("Error: " + err.Error())
@@ -60,12 +72,12 @@ func printPVC(pvcName, pvcRoot, nodeLabel, ns string) {
6072
}
6173
log.Debugf("response = %v", response)
6274

63-
if pvcName == "all" {
75+
if AllFlag {
6476
fmt.Println("All Operator Labeled PVCs")
6577
}
6678

6779
for k, v := range response.Results {
68-
if pvcName == "all" {
80+
if AllFlag {
6981
if v != "" {
7082
fmt.Printf("%s%s\n", TreeTrunk, v)
7183
}

pgo/cmd/show.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func init() {
112112
ShowClusterCmd.Flags().BoolVar(&AllFlag, "all", false, "show all resources.")
113113
ShowPolicyCmd.Flags().BoolVar(&AllFlag, "all", false, "show all resources.")
114114
ShowPVCCmd.Flags().StringVarP(&NodeLabel, "node-label", "", "", "The node label (key=value) to use")
115+
ShowPVCCmd.Flags().BoolVar(&AllFlag, "all", false, "show all resources.")
115116
ShowPVCCmd.Flags().StringVarP(&PVCRoot, "pvc-root", "", "", "The PVC directory to list.")
116117
ShowScheduleCmd.Flags().StringVarP(&Selector, "selector", "s", "", "The selector to use for cluster filtering.")
117118
ShowScheduleCmd.Flags().StringVarP(&ScheduleName, "schedule-name", "", "", "The name of the schedule to show.")
@@ -187,12 +188,13 @@ var ShowPVCCmd = &cobra.Command{
187188
Long: `Show PVC information. For example:
188189
189190
pgo show pvc mycluster
191+
pgo show pvc --all
190192
pgo show pvc mycluster-backup
191193
pgo show pvc mycluster-xlog
192194
pgo show pvc a2-backup --pvc-root=a2-backups/2019-01-12-17-09-42`,
193195
Run: func(cmd *cobra.Command, args []string) {
194-
if len(args) == 0 {
195-
fmt.Println("Error: PVC name(s) required for this command.")
196+
if len(args) == 0 && !AllFlag {
197+
fmt.Println("Error: PVC name(s) or --all required for this command.")
196198
} else {
197199
if Namespace == "" {
198200
Namespace = PGONamespace

0 commit comments

Comments
 (0)