(ctx context.Context, client Client, log log.Logger)
| 317 | } |
| 318 | |
| 319 | func wakeUpAndPing(ctx context.Context, client Client, log log.Logger) error { |
| 320 | err := wakeUp(ctx, client, log) |
| 321 | if err != nil { |
| 322 | return err |
| 323 | } |
| 324 | |
| 325 | // create ping config |
| 326 | pingConfig := rest.CopyConfig(client.RestConfig()) |
| 327 | pingConfig.WrapTransport = func(rt http.RoundTripper) http.RoundTripper { |
| 328 | return &devSpaceRoundTripper{ |
| 329 | roundTripper: rt, |
| 330 | requestType: "Ping", |
| 331 | callback: func(response *http.Response) { |
| 332 | if response.Header.Get("X-DevSpace-Response-Type") == "Blocked" { |
| 333 | kill.StopDevSpace("Targeted Kubernetes environment has begun sleeping. Please restart DevSpace to wake up the environment") |
| 334 | } |
| 335 | }, |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | // create kube client |
| 340 | kubeClient, err := kubernetes.NewForConfig(pingConfig) |
| 341 | if err != nil { |
| 342 | return err |
| 343 | } |
| 344 | |
| 345 | // start pinging |
| 346 | go func() { |
| 347 | getter, _ := idle.NewIdleGetter() |
| 348 | wait.UntilWithContext(ctx, func(ctx context.Context) { |
| 349 | if getter != nil { |
| 350 | amountIdle, err := getter.Idle() |
| 351 | if err == nil && amountIdle > stopPingAfter { |
| 352 | return |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | _, err = kubeClient.CoreV1().Pods(client.Namespace()).List(ctx, metav1.ListOptions{LabelSelector: "devspace=ping"}) |
| 357 | if err != nil { |
| 358 | log.Debugf("Error pinging Kubernetes environment: %v", err) |
| 359 | } |
| 360 | }, time.Minute) |
| 361 | }() |
| 362 | |
| 363 | return nil |
| 364 | } |
| 365 | |
| 366 | func wakeUp(ctx context.Context, client Client, log log.Logger) error { |
| 367 | // check if environment is sleeping |
no test coverage detected