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

Function InjectDevSpaceHelper

pkg/devspace/services/inject/inject.go:49–124  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

47
48// InjectDevSpaceHelper injects the devspace helper into the provided container
49func 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

Callers 5

startSSHWithRestartFunction · 0.92
initClientMethod · 0.92
restartContainerFunction · 0.92
inject.goFile · 0.92

Calls 14

GetRawVersionFunction · 0.92
ContainerArchitectureTypeAlias · 0.92
AssetFunction · 0.92
helperFileInfoTypeAlias · 0.85
downloadSyncHelperFunction · 0.85
injectSyncHelperFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
ExecBufferedMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected