(ctx devspacecontext.Context, hook *latest.HookConfig, podContainer *selector.SelectedPodContainer)
| 26 | type remoteUploadHook struct{} |
| 27 | |
| 28 | func (r *remoteUploadHook) ExecuteRemotely(ctx devspacecontext.Context, hook *latest.HookConfig, podContainer *selector.SelectedPodContainer) error { |
| 29 | containerPath := "." |
| 30 | if hook.Upload.ContainerPath != "" { |
| 31 | containerPath = hook.Upload.ContainerPath |
| 32 | } |
| 33 | localPath := "." |
| 34 | if hook.Upload.LocalPath != "" { |
| 35 | localPath = hook.Upload.LocalPath |
| 36 | } |
| 37 | |
| 38 | ctx.Log().Infof("Execute hook '%s' in container '%s/%s/%s'", ansi.Color(hookName(hook), "white+b"), podContainer.Pod.Namespace, podContainer.Pod.Name, podContainer.Container.Name) |
| 39 | ctx.Log().Infof("Copy local '%s' -> container '%s'", localPath, containerPath) |
| 40 | // Make sure the target folder exists |
| 41 | destDir := path.Dir(containerPath) |
| 42 | if len(destDir) > 0 { |
| 43 | _, stderr, err := ctx.KubeClient().ExecBuffered(ctx.Context(), podContainer.Pod, podContainer.Container.Name, []string{"mkdir", "-p", destDir}, nil) |
| 44 | if err != nil { |
| 45 | return errors.Errorf("error in container '%s/%s/%s': %v: %s", podContainer.Pod.Namespace, podContainer.Pod.Name, podContainer.Container.Name, err, string(stderr)) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | // Upload the files |
| 50 | err := upload(ctx.Context(), ctx.KubeClient(), podContainer.Pod, podContainer.Container.Name, localPath, containerPath) |
| 51 | if err != nil { |
| 52 | return errors.Errorf("error in container '%s/%s/%s': %v", podContainer.Pod.Namespace, podContainer.Pod.Name, podContainer.Container.Name, err) |
| 53 | } |
| 54 | |
| 55 | return nil |
| 56 | } |
| 57 | |
| 58 | func upload(ctx context.Context, client kubectl.Client, pod *v1.Pod, container string, localPath string, containerPath string) error { |
| 59 | // do the actual copy |
nothing calls this directly
no test coverage detected