(ctx context.Context, client Client, log log.Logger)
| 364 | } |
| 365 | |
| 366 | func wakeUp(ctx context.Context, client Client, log log.Logger) error { |
| 367 | // check if environment is sleeping |
| 368 | var isSleeping bool |
| 369 | isSleepingConfig := rest.CopyConfig(client.RestConfig()) |
| 370 | isSleepingConfig.WrapTransport = func(rt http.RoundTripper) http.RoundTripper { |
| 371 | return &devSpaceRoundTripper{ |
| 372 | roundTripper: rt, |
| 373 | requestType: "Ping", |
| 374 | callback: func(response *http.Response) { |
| 375 | if response.Header.Get("X-DevSpace-Response-Type") == "Blocked" { |
| 376 | isSleeping = true |
| 377 | } |
| 378 | }, |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | // create kube client |
| 383 | kubeClient, err := kubernetes.NewForConfig(isSleepingConfig) |
| 384 | if err != nil { |
| 385 | return err |
| 386 | } |
| 387 | |
| 388 | // wake up the environment |
| 389 | _, err = kubeClient.CoreV1().Pods(client.Namespace()).List(ctx, metav1.ListOptions{LabelSelector: "devspace=wakeup"}) |
| 390 | if err != nil && !isSleeping { |
| 391 | return fmt.Errorf("please make sure you have an existing valid kube config. You might want to check one of the following things:\n\n* Make sure you can use 'kubectl get namespaces' locally\n* If you are using Loft, you might want to run 'devspace create space' or 'loft create space'") |
| 392 | } else if !isSleeping { |
| 393 | return nil |
| 394 | } |
| 395 | |
| 396 | // wake up the environment |
| 397 | wakeUpConfig := rest.CopyConfig(client.RestConfig()) |
| 398 | wakeUpConfig.WrapTransport = func(rt http.RoundTripper) http.RoundTripper { |
| 399 | return &devSpaceRoundTripper{ |
| 400 | roundTripper: rt, |
| 401 | requestType: "WakeUp", |
| 402 | callback: func(response *http.Response) { |
| 403 | if response.Header.Get("X-DevSpace-Response-Type") == "WokenUp" { |
| 404 | log.Infof("Successfully woken up Kubernetes environment") |
| 405 | } |
| 406 | }, |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | // create kube client |
| 411 | kubeClient, err = kubernetes.NewForConfig(wakeUpConfig) |
| 412 | if err != nil { |
| 413 | return err |
| 414 | } |
| 415 | |
| 416 | // print message if it takes too long |
| 417 | log.Infof("DevSpace is waking up the Kubernetes environment, please wait a moment...") |
| 418 | |
| 419 | // wake up the environment |
| 420 | waitErr := wait.PollUntilContextTimeout(context.TODO(), time.Second, time.Second*30, true, func(_ context.Context) (done bool, err error) { |
| 421 | _, err = kubeClient.CoreV1().Pods(client.Namespace()).List(ctx, metav1.ListOptions{LabelSelector: "devspace=wakeup"}) |
| 422 | if err != nil { |
| 423 | return false, nil |
no test coverage detected