拷贝本地ssh config到pod
(pod coreV1.Pod, containerName string, runAsUser string)
| 178 | |
| 179 | // 拷贝本地ssh config到pod |
| 180 | func (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 |
| 205 | sudo 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 |
| 217 | func (k *KubernetesUtil) CopyLocalGitConfigToPod(pod coreV1.Pod, containerName string, runAsUser string) error { |
no test coverage detected