(ctx context.Context, hook *latest.HookConfig, client kubectl.Client, imageSelector []imageselector.ImageSelector, log logpkg.Logger)
| 62 | } |
| 63 | |
| 64 | func (r *waitHook) execute(ctx context.Context, hook *latest.HookConfig, client kubectl.Client, imageSelector []imageselector.ImageSelector, log logpkg.Logger) error { |
| 65 | labelSelector := "" |
| 66 | if len(hook.Container.LabelSelector) > 0 { |
| 67 | labelSelector = labels.Set(hook.Container.LabelSelector).String() |
| 68 | } |
| 69 | |
| 70 | timeout := int64(150) |
| 71 | if hook.Wait.Timeout > 0 { |
| 72 | timeout = hook.Wait.Timeout |
| 73 | } |
| 74 | |
| 75 | // wait until the defined condition will be true, this will wait initially 2 seconds |
| 76 | err := wait.PollUntilContextTimeout(ctx, time.Second*2, time.Duration(timeout)*time.Second, false, func(ctx context.Context) (done bool, err error) { |
| 77 | podContainers, err := selector.NewFilter(client).SelectContainers(ctx, selector.Selector{ |
| 78 | ImageSelector: targetselector.ToStringImageSelector(imageSelector), |
| 79 | LabelSelector: labelSelector, |
| 80 | Pod: hook.Container.Pod, |
| 81 | ContainerName: hook.Container.ContainerName, |
| 82 | Namespace: hook.Container.Namespace, |
| 83 | FilterContainer: selector.FilterTerminatingContainers, |
| 84 | }) |
| 85 | if err != nil { |
| 86 | return false, err |
| 87 | } |
| 88 | |
| 89 | // lets check if all containers satisfy the condition |
| 90 | for _, pc := range podContainers { |
| 91 | if targetselector.HasPodProblem(pc.Pod) { |
| 92 | r.printWarning.Do(func() { |
| 93 | status := kubectl.GetPodStatus(pc.Pod) |
| 94 | log.Warnf("Pod %s/%s has critical status: %s. DevSpace will continue waiting, but this operation might timeout", pc.Pod.Namespace, pc.Pod.Name, status) |
| 95 | }) |
| 96 | } |
| 97 | |
| 98 | if !isWaitConditionTrue(hook.Wait, pc) { |
| 99 | return false, nil |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return true, nil |
| 104 | }) |
| 105 | if err != nil { |
| 106 | return err |
| 107 | } |
| 108 | |
| 109 | return nil |
| 110 | } |
| 111 | |
| 112 | func isWaitConditionTrue(condition *latest.HookWaitConfig, podContainer *selector.SelectedPodContainer) bool { |
| 113 | if selector.IsPodTerminating(podContainer.Pod) { |
no test coverage detected