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

Function execKubectlCommandCombined

cli/pkg/k8s/k8sUtil.go:560–585  ·  view source on GitHub ↗
(kubectlFilePath string, command string, workingDirctory string)

Source from the content-addressed store, hash-verified

558}
559
560func 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
588func (k *KubernetesUtil) GetPodInstanceBySelector(selector string) (*coreV1.Pod, error) {

Callers 3

newK8sUtilFunction · 0.85
checkAndInstallKubectlFunction · 0.85

Calls 2

CombinedOutputMethod · 0.80
DebugMethod · 0.80

Tested by

no test coverage detected