MCPcopy Index your code
hub / github.com/devspace-sh/devspace / execute

Method execute

pkg/devspace/hook/wait.go:64–110  ·  view source on GitHub ↗
(ctx context.Context, hook *latest.HookConfig, client kubectl.Client, imageSelector []imageselector.ImageSelector, log logpkg.Logger)

Source from the content-addressed store, hash-verified

62}
63
64func (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
112func isWaitConditionTrue(condition *latest.HookWaitConfig, podContainer *selector.SelectedPodContainer) bool {
113 if selector.IsPodTerminating(podContainer.Pod) {

Callers 1

ExecuteMethod · 0.95

Calls 9

NewFilterFunction · 0.92
ToStringImageSelectorFunction · 0.92
HasPodProblemFunction · 0.92
GetPodStatusFunction · 0.92
isWaitConditionTrueFunction · 0.85
SelectContainersMethod · 0.65
StringMethod · 0.45
SetMethod · 0.45
WarnfMethod · 0.45

Tested by

no test coverage detected