| 227 | } |
| 228 | |
| 229 | func startProcess(k8sClient kubernetes.Interface, cfg *rest.Config, cmd []string, namespace string, podName string, containerName string, ptyHandler PtyHandler) error { |
| 230 | |
| 231 | req := k8sClient.CoreV1().RESTClient().Post(). |
| 232 | Resource("pods"). |
| 233 | Name(podName). |
| 234 | Namespace(namespace). |
| 235 | SubResource("exec") |
| 236 | |
| 237 | req.VersionedParams(&v1.PodExecOptions{ |
| 238 | Container: containerName, |
| 239 | Command: cmd, |
| 240 | Stdin: true, |
| 241 | Stdout: true, |
| 242 | Stderr: true, |
| 243 | TTY: true, |
| 244 | }, scheme.ParameterCodec) |
| 245 | |
| 246 | exec, err := remotecommand.NewSPDYExecutor(cfg, "POST", req.URL()) |
| 247 | if err != nil { |
| 248 | return err |
| 249 | } |
| 250 | ctx :=context.Background() |
| 251 | err = exec.StreamWithContext(ctx,remotecommand.StreamOptions{ |
| 252 | Stdin: ptyHandler, |
| 253 | Stdout: ptyHandler, |
| 254 | Stderr: ptyHandler, |
| 255 | TerminalSizeQueue: ptyHandler, |
| 256 | Tty: true, |
| 257 | }) |
| 258 | if err != nil { |
| 259 | return err |
| 260 | } |
| 261 | |
| 262 | return nil |
| 263 | } |
| 264 | |
| 265 | func GenTerminalSessionId() (string, error) { |
| 266 | bytes := make([]byte, 16) |