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

Method ExecuteRemotely

pkg/devspace/hook/upload.go:28–56  ·  view source on GitHub ↗
(ctx devspacecontext.Context, hook *latest.HookConfig, podContainer *selector.SelectedPodContainer)

Source from the content-addressed store, hash-verified

26type remoteUploadHook struct{}
27
28func (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
58func upload(ctx context.Context, client kubectl.Client, pod *v1.Pod, container string, localPath string, containerPath string) error {
59 // do the actual copy

Callers

nothing calls this directly

Calls 8

hookNameFunction · 0.85
uploadFunction · 0.85
LogMethod · 0.65
ExecBufferedMethod · 0.65
KubeClientMethod · 0.65
ContextMethod · 0.65
InfofMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected