mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Periodically shows message while waiting for completion of REST
operations so that users understand what is happening.
This commit is contained in:
parent
28f7d60965
commit
c9676aa2d5
@ -26,6 +26,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
kube_client "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
kube_client "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubecfg"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubecfg"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"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")
|
www = flag.String("www", "", "If -proxy is true, use this directory to serve static files")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
pollPeriod = 20 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
fmt.Fprint(os.Stderr, `usage: kubecfg -h [-c config/file.json] [-p :,..., :] <method>
|
fmt.Fprint(os.Stderr, `usage: kubecfg -h [-c config/file.json] [-p :,..., :] <method>
|
||||||
|
|
||||||
@ -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
|
// Attempts to execute an API request
|
||||||
func executeAPIRequest(method string, s *kube_client.Client) bool {
|
func executeAPIRequest(method string, s *kube_client.Client) bool {
|
||||||
parseStorage := func() string {
|
parseStorage := func() string {
|
||||||
@ -175,7 +198,7 @@ func executeAPIRequest(method string, s *kube_client.Client) bool {
|
|||||||
if method == "create" || method == "update" {
|
if method == "create" || method == "update" {
|
||||||
r.Body(readConfig(parseStorage()))
|
r.Body(readConfig(parseStorage()))
|
||||||
}
|
}
|
||||||
result := r.Do()
|
result := doVerb(s, r)
|
||||||
obj, err := result.Get()
|
obj, err := result.Get()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Got request error: %v\n", err)
|
glog.Fatalf("Got request error: %v\n", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user