From c9676aa2d50cbc87dff4efea705a5fc27bfab28f Mon Sep 17 00:00:00 2001 From: Yuki Yugui Sonoda Date: Tue, 8 Jul 2014 16:40:52 +0900 Subject: [PATCH 1/2] Periodically shows message while waiting for completion of REST operations so that users understand what is happening. --- cmd/kubecfg/kubecfg.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/kubecfg/kubecfg.go b/cmd/kubecfg/kubecfg.go index ae13408b394..a92cf0e7579 100644 --- a/cmd/kubecfg/kubecfg.go +++ b/cmd/kubecfg/kubecfg.go @@ -26,6 +26,7 @@ import ( "strings" "time" + "github.com/GoogleCloudPlatform/kubernetes/pkg/api" kube_client "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubecfg" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" @@ -51,6 +52,10 @@ var ( www = flag.String("www", "", "If -proxy is true, use this directory to serve static files") ) +var ( + pollPeriod = 20 * time.Second +) + func usage() { fmt.Fprint(os.Stderr, `usage: kubecfg -h [-c config/file.json] [-p :,..., :] @@ -146,6 +151,24 @@ func main() { } } +func doVerb(s *kube_client.Client, r *kube_client.Request) kube_client.Result { + for { + r = r.PollPeriod(0) + result := r.Do() + if result.Error() == nil { + return result + } + if statusErr, ok := result.Error().(*kube_client.StatusErr); ok && statusErr.Status.Status == api.StatusWorking { + fmt.Fprintf(os.Stderr, "Waiting for completion of /operations/%s\n", statusErr.Status.Details) + time.Sleep(pollPeriod) + pollOp := s.PollFor(statusErr.Status.Details) + r = pollOp + continue + } + return result + } +} + // Attempts to execute an API request func executeAPIRequest(method string, s *kube_client.Client) bool { parseStorage := func() string { @@ -175,7 +198,7 @@ func executeAPIRequest(method string, s *kube_client.Client) bool { if method == "create" || method == "update" { r.Body(readConfig(parseStorage())) } - result := r.Do() + result := doVerb(s, r) obj, err := result.Get() if err != nil { glog.Fatalf("Got request error: %v\n", err) From 602f7d811201f35471e6b28ff5e618037fb6ae37 Mon Sep 17 00:00:00 2001 From: Yuki Yugui Sonoda Date: Wed, 9 Jul 2014 14:35:58 +0900 Subject: [PATCH 2/2] Use glog instead of printing to stderr. --- cmd/kubecfg/kubecfg.go | 25 +------------------------ pkg/client/request.go | 2 ++ 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/cmd/kubecfg/kubecfg.go b/cmd/kubecfg/kubecfg.go index a92cf0e7579..ae13408b394 100644 --- a/cmd/kubecfg/kubecfg.go +++ b/cmd/kubecfg/kubecfg.go @@ -26,7 +26,6 @@ import ( "strings" "time" - "github.com/GoogleCloudPlatform/kubernetes/pkg/api" kube_client "github.com/GoogleCloudPlatform/kubernetes/pkg/client" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubecfg" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" @@ -52,10 +51,6 @@ var ( www = flag.String("www", "", "If -proxy is true, use this directory to serve static files") ) -var ( - pollPeriod = 20 * time.Second -) - func usage() { fmt.Fprint(os.Stderr, `usage: kubecfg -h [-c config/file.json] [-p :,..., :] @@ -151,24 +146,6 @@ func main() { } } -func doVerb(s *kube_client.Client, r *kube_client.Request) kube_client.Result { - for { - r = r.PollPeriod(0) - result := r.Do() - if result.Error() == nil { - return result - } - if statusErr, ok := result.Error().(*kube_client.StatusErr); ok && statusErr.Status.Status == api.StatusWorking { - fmt.Fprintf(os.Stderr, "Waiting for completion of /operations/%s\n", statusErr.Status.Details) - time.Sleep(pollPeriod) - pollOp := s.PollFor(statusErr.Status.Details) - r = pollOp - continue - } - return result - } -} - // Attempts to execute an API request func executeAPIRequest(method string, s *kube_client.Client) bool { parseStorage := func() string { @@ -198,7 +175,7 @@ func executeAPIRequest(method string, s *kube_client.Client) bool { if method == "create" || method == "update" { r.Body(readConfig(parseStorage())) } - result := doVerb(s, r) + result := r.Do() obj, err := result.Get() if err != nil { glog.Fatalf("Got request error: %v\n", err) diff --git a/pkg/client/request.go b/pkg/client/request.go index 16da594aec8..329ca707352 100644 --- a/pkg/client/request.go +++ b/pkg/client/request.go @@ -27,6 +27,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" + "github.com/golang/glog" ) // Server contains info locating a kubernetes api server. @@ -216,6 +217,7 @@ func (r *Request) Do() Result { if err != nil { if statusErr, ok := err.(*StatusErr); ok { if statusErr.Status.Status == api.StatusWorking && r.pollPeriod != 0 { + glog.Infof("Waiting for completion of /operations/%s", statusErr.Status.Details) time.Sleep(r.pollPeriod) // Make a poll request pollOp := r.c.PollFor(statusErr.Status.Details).PollPeriod(r.pollPeriod)