(ctx devspacecontext.Context, hook *latest.HookConfig, imageSelector []imageselector.ImageSelector)
| 73 | } |
| 74 | |
| 75 | func (r *remoteHook) execute(ctx devspacecontext.Context, hook *latest.HookConfig, imageSelector []imageselector.ImageSelector) (bool, error) { |
| 76 | labelSelector := "" |
| 77 | if len(hook.Container.LabelSelector) > 0 { |
| 78 | labelSelector = labels.Set(hook.Container.LabelSelector).String() |
| 79 | } |
| 80 | |
| 81 | timeout := int64(150) |
| 82 | if hook.Container.Timeout > 0 { |
| 83 | timeout = hook.Container.Timeout |
| 84 | } |
| 85 | |
| 86 | wait := false |
| 87 | if hook.Container.Wait == nil || *hook.Container.Wait { |
| 88 | ctx.Log().Infof("Waiting for running containers for hook '%s'", ansi.Color(hookName(hook), "white+b")) |
| 89 | wait = true |
| 90 | } |
| 91 | |
| 92 | // build target selector |
| 93 | targetSelectorOptions := targetselector.NewOptionsFromFlags(hook.Container.ContainerName, labelSelector, targetselector.ToStringImageSelector(imageSelector), hook.Container.Namespace, hook.Container.Pod). |
| 94 | WithTimeout(timeout). |
| 95 | WithWait(wait). |
| 96 | WithWaitingStrategy(r.WaitingStrategy) |
| 97 | |
| 98 | // select container |
| 99 | podContainer, err := targetselector.NewTargetSelector(targetSelectorOptions).SelectSingleContainer(ctx.Context(), ctx.KubeClient(), ctx.Log()) |
| 100 | if err != nil { |
| 101 | if _, ok := err.(*targetselector.NotFoundErr); ok { |
| 102 | return false, nil |
| 103 | } |
| 104 | |
| 105 | return false, err |
| 106 | } |
| 107 | |
| 108 | // execute the hook in the container |
| 109 | err = r.Hook.ExecuteRemotely(ctx, hook, podContainer) |
| 110 | if err != nil { |
| 111 | return false, err |
| 112 | } |
| 113 | |
| 114 | return true, nil |
| 115 | } |
no test coverage detected