|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | 4 | "os" |
6 | 5 | "os/exec" |
7 | 6 | "path/filepath" |
@@ -381,6 +380,7 @@ func (cmd *UpCmd) deployChart() { |
381 | 380 | config := configutil.GetConfig() |
382 | 381 |
|
383 | 382 | log.StartWait("Deploying helm chart") |
| 383 | + defer log.StopWait() |
384 | 384 |
|
385 | 385 | releaseName := *config.DevSpace.Release.Name |
386 | 386 | releaseNamespace := *config.DevSpace.Release.Namespace |
@@ -426,81 +426,18 @@ func (cmd *UpCmd) deployChart() { |
426 | 426 | overwriteValues["pullSecrets"] = pullSecrets |
427 | 427 |
|
428 | 428 | appRelease, err := cmd.helm.InstallChartByPath(releaseName, releaseNamespace, chartPath, &overwriteValues) |
429 | | - |
430 | | - log.StopWait() |
431 | | - |
432 | 429 | if err != nil { |
433 | 430 | log.Fatalf("Unable to deploy helm chart: %s", err.Error()) |
434 | 431 | } |
435 | 432 |
|
436 | 433 | releaseRevision := int(appRelease.Version) |
437 | 434 | log.Donef("Deployed helm chart (Release revision: %d)", releaseRevision) |
438 | 435 | log.StartWait("Waiting for release pod to become ready") |
439 | | - defer log.StopWait() |
440 | | - |
441 | | - for true { |
442 | | - podList, err := cmd.kubectl.Core().Pods(releaseNamespace).List(metav1.ListOptions{ |
443 | | - LabelSelector: "release=" + releaseName, |
444 | | - }) |
445 | | - |
446 | | - if err != nil { |
447 | | - log.Panicf("Unable to list devspace pods: %s", err.Error()) |
448 | | - } |
449 | | - |
450 | | - if len(podList.Items) > 0 { |
451 | | - highestRevision := 0 |
452 | | - var selectedPod *k8sv1.Pod |
453 | | - |
454 | | - for i, pod := range podList.Items { |
455 | | - if kubectl.GetPodStatus(&pod) == "Terminating" { |
456 | | - continue |
457 | | - } |
458 | | - |
459 | | - podRevision, podHasRevision := pod.Annotations["revision"] |
460 | | - hasHigherRevision := (i == 0) |
461 | | - |
462 | | - if !hasHigherRevision && podHasRevision { |
463 | | - podRevisionInt, _ := strconv.Atoi(podRevision) |
464 | | - |
465 | | - if podRevisionInt > highestRevision { |
466 | | - hasHigherRevision = true |
467 | | - } |
468 | | - } |
469 | | - |
470 | | - if hasHigherRevision { |
471 | | - selectedPod = &pod |
472 | | - highestRevision, _ = strconv.Atoi(podRevision) |
473 | | - } |
474 | | - } |
475 | | - |
476 | | - if selectedPod != nil { |
477 | | - _, hasRevision := selectedPod.Annotations["revision"] |
478 | 436 |
|
479 | | - if !hasRevision || highestRevision == releaseRevision { |
480 | | - if !hasRevision { |
481 | | - log.Warn("Found pod without revision. Use annotation 'revision' for your pods to avoid this warning.") |
482 | | - } |
483 | | - |
484 | | - cmd.pod = selectedPod |
485 | | - err = waitForPodReady(cmd.kubectl, cmd.pod, 2*60*time.Second, 5*time.Second) |
486 | | - |
487 | | - if err != nil { |
488 | | - log.Fatalf("Error during waiting for pod: %s", err.Error()) |
489 | | - } |
490 | | - |
491 | | - break |
492 | | - } else { |
493 | | - log.Info("Waiting for release upgrade to complete.") |
494 | | - } |
495 | | - } |
496 | | - } else { |
497 | | - log.Info("Waiting for release to be deployed.") |
498 | | - } |
499 | | - |
500 | | - time.Sleep(2 * time.Second) |
| 437 | + cmd.pod, err = helmClient.WaitForReleasePodToGetReady(cmd.kubectl, releaseName, releaseNamespace, releaseRevision) |
| 438 | + if err != nil { |
| 439 | + log.Fatal(err) |
501 | 440 | } |
502 | | - |
503 | | - log.StopWait() |
504 | 441 | } |
505 | 442 |
|
506 | 443 | func (cmd *UpCmd) startSync() []*synctool.SyncConfig { |
@@ -592,7 +529,7 @@ func (cmd *UpCmd) startPortForwarding() { |
592 | 529 | config := configutil.GetConfig() |
593 | 530 |
|
594 | 531 | for _, portForwarding := range *config.DevSpace.PortForwarding { |
595 | | - if *portForwarding.ResourceType == "pod" { |
| 532 | + if portForwarding.ResourceType == nil || *portForwarding.ResourceType == "pod" { |
596 | 533 | if len(*portForwarding.LabelSelector) > 0 { |
597 | 534 | labels := make([]string, 0, len(*portForwarding.LabelSelector)) |
598 | 535 |
|
@@ -634,22 +571,3 @@ func (cmd *UpCmd) startPortForwarding() { |
634 | 571 | } |
635 | 572 | } |
636 | 573 | } |
637 | | - |
638 | | -func waitForPodReady(kubectl *kubernetes.Clientset, pod *k8sv1.Pod, maxWaitTime time.Duration, checkInterval time.Duration) error { |
639 | | - for maxWaitTime > 0 { |
640 | | - pod, err := kubectl.Core().Pods(pod.Namespace).Get(pod.Name, metav1.GetOptions{}) |
641 | | - |
642 | | - if err != nil { |
643 | | - return err |
644 | | - } |
645 | | - |
646 | | - if len(pod.Status.ContainerStatuses) > 0 && pod.Status.ContainerStatuses[0].Ready { |
647 | | - return nil |
648 | | - } |
649 | | - |
650 | | - time.Sleep(checkInterval) |
651 | | - maxWaitTime = maxWaitTime - checkInterval |
652 | | - } |
653 | | - |
654 | | - return fmt.Errorf("Max wait time expired") |
655 | | -} |
0 commit comments