(kubectlFilePath string, command string, workingDirctory string)
| 558 | } |
| 559 | |
| 560 | func execKubectlCommandCombined(kubectlFilePath string, command string, workingDirctory string) (string, error) { |
| 561 | var execCommand *exec.Cmd |
| 562 | |
| 563 | kubeCommand := fmt.Sprintf("%v %v", kubectlFilePath, command) |
| 564 | |
| 565 | switch runtime.GOOS { |
| 566 | case "windows": |
| 567 | kubeCommand = strings.ReplaceAll(kubeCommand, "grep ", "findstr ") |
| 568 | execCommand = exec.Command("powershell", "/c", kubeCommand) |
| 569 | default: |
| 570 | execCommand = exec.Command("bash", "-c", kubeCommand) |
| 571 | } |
| 572 | |
| 573 | if workingDirctory != "" { |
| 574 | execCommand.Dir = workingDirctory |
| 575 | } |
| 576 | |
| 577 | bytes, err := execCommand.CombinedOutput() |
| 578 | output := string(bytes) |
| 579 | common.SmartIDELog.Debug(fmt.Sprintf("%v %v >> %v", workingDirctory, kubeCommand, output)) |
| 580 | if strings.Contains(output, "error:") || strings.Contains(output, "fatal:") { |
| 581 | return "", errors.New(output) |
| 582 | } |
| 583 | |
| 584 | return string(bytes), err |
| 585 | } |
| 586 | |
| 587 | // 根据selector获取pod |
| 588 | func (k *KubernetesUtil) GetPodInstanceBySelector(selector string) (*coreV1.Pod, error) { |
no test coverage detected