InjectDevSpaceHelper injects the devspace helper into the provided container
(ctx context.Context, client kubectl.Client, pod *v1.Pod, container string, arch string, log logpkg.Logger)
| 47 | |
| 48 | // InjectDevSpaceHelper injects the devspace helper into the provided container |
| 49 | func InjectDevSpaceHelper(ctx context.Context, client kubectl.Client, pod *v1.Pod, container string, arch string, log logpkg.Logger) error { |
| 50 | if log == nil { |
| 51 | log = logpkg.Discard |
| 52 | } |
| 53 | |
| 54 | injectMutex.Lock() |
| 55 | defer injectMutex.Unlock() |
| 56 | |
| 57 | // Compare sync versions |
| 58 | version := upgrade.GetRawVersion() |
| 59 | if version == "" { |
| 60 | version = "latest" |
| 61 | } |
| 62 | if arch != "" { |
| 63 | if latest.ContainerArchitecture(arch) == latest.ContainerArchitectureAmd64 { |
| 64 | arch = "" |
| 65 | } else { |
| 66 | arch = "-" + arch |
| 67 | } |
| 68 | } else { |
| 69 | // check arch on pod node |
| 70 | stdout, _, err := client.ExecBuffered(ctx, pod, container, []string{"uname", "-a"}, nil) |
| 71 | if err == nil { |
| 72 | if strings.Contains(string(stdout), "arm64") || strings.Contains(string(stdout), "aarch64") { |
| 73 | arch = "-" + string(latest.ContainerArchitectureArm64) |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // Check if sync is already in pod |
| 79 | localHelperName := "devspacehelper" + arch |
| 80 | stdout, _, err := client.ExecBuffered(ctx, pod, container, []string{DevSpaceHelperContainerPath, "version"}, nil) |
| 81 | if err != nil || version != string(stdout) { |
| 82 | log.Info("Inject devspacehelper...") |
| 83 | homedir, err := homedir.Dir() |
| 84 | if err != nil { |
| 85 | return err |
| 86 | } |
| 87 | |
| 88 | syncBinaryFolder := filepath.Join(homedir, constants.DefaultHomeDevSpaceFolder, DevSpaceHelperTempFolder, version) |
| 89 | if env.GlobalGetEnv("DEVSPACE_INJECT_REMOTE") == "true" { |
| 90 | // Install devspacehelper inside container |
| 91 | log.Debugf("Trying to download devspacehelper into pod %s/%s", pod.Namespace, pod.Name) |
| 92 | err = installDevSpaceHelperInContainer(ctx, client, pod, container, version, localHelperName) |
| 93 | if err == nil { |
| 94 | log.Donef("Successfully injected devspacehelper into pod %s/%s", pod.Namespace, pod.Name) |
| 95 | return nil |
| 96 | } |
| 97 | |
| 98 | log.Debugf("Couldn't download devspacehelper in container, error: %s", err) |
| 99 | } |
| 100 | |
| 101 | // check if we can find it in the assets |
| 102 | helperBytes, err := assets.Asset("release/" + localHelperName) |
| 103 | if err == nil { |
| 104 | return injectSyncHelperFromBytes(ctx, client, pod, container, helperFileInfo(helperBytes), bytes.NewReader(helperBytes)) |
| 105 | } |
| 106 |
no test coverage detected