MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / CopyLocalSSHConfigToPod

Method CopyLocalSSHConfigToPod

cli/pkg/k8s/k8sUtil.go:180–214  ·  view source on GitHub ↗

拷贝本地ssh config到pod

(pod coreV1.Pod, containerName string, runAsUser string)

Source from the content-addressed store, hash-verified

178
179// 拷贝本地ssh config到pod
180func (k *KubernetesUtil) CopyLocalSSHConfigToPod(pod coreV1.Pod, containerName string, runAsUser string) error {
181 home, err := os.UserHomeDir()
182 if err != nil {
183 return err
184 }
185
186 // current user dir
187 podCurrentUserHomeDir, err := k.GetPodCurrentUserHomeDirection(pod, containerName, runAsUser)
188 if err != nil {
189 return err
190 }
191
192 // copy
193 sshPath := filepath.Join(home, ".ssh/")
194 if runtime.GOOS == "windows" {
195 sshPath = filepath.Join(home, ".ssh\\")
196 }
197 err = k.CopyToPod(pod, containerName, sshPath, podCurrentUserHomeDir, runAsUser) //.ssh
198 if err != nil { //TODO 文件不存在,仅警告
199 return err
200 }
201
202 // .ssh 目录授权
203 if runAsUser != "" {
204 podCommand := fmt.Sprintf(`sudo chown -R %v:%v ~/.ssh
205sudo chmod -R 700 ~/.ssh`, runAsUser, runAsUser)
206 k.ExecuteCommandCombinedInPod(pod, containerName, podCommand, "")
207 }
208
209 // chmod
210 commad := `sudo echo -e 'Host *\n StrictHostKeyChecking no' >> ~/.ssh/config`
211 k.ExecuteCommandRealtimeInPod(pod, containerName, commad, runAsUser)
212
213 return nil
214}
215
216// 拷贝本地git config到pod
217func (k *KubernetesUtil) CopyLocalGitConfigToPod(pod coreV1.Pod, containerName string, runAsUser string) error {

Callers 1

execPodFunction · 0.80

Calls 5

CopyToPodMethod · 0.95
JoinMethod · 0.45

Tested by

no test coverage detected