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

Function downloadConfigAndLinkFiles

cli/cmd/start/k8s.go:651–699  ·  view source on GitHub ↗

下载配置文件 和 关联的k8s yaml文件

(workspaceInfo workspace.WorkspaceInfo)

Source from the content-addressed store, hash-verified

649
650// 下载配置文件 和 关联的k8s yaml文件
651func downloadConfigAndLinkFiles(workspaceInfo workspace.WorkspaceInfo) (
652 gitRepoRootDirPath string,
653 configFileRelativePath string, linkK8sYamlRelativePaths []string, err error) {
654
655 //3.1. 下载配置文件
656 gitActualRepoUrl := workspaceInfo.GitCloneRepoUrl
657 if workspaceInfo.GitRepoAuthType == workspace.GitRepoAuthType_Basic {
658 gitActualRepoUrl, _ = common.AddUsernamePassword4ActualGitRpoUrl(gitActualRepoUrl, workspaceInfo.GitUserName, workspaceInfo.GitPassword)
659 }
660 gitRepoRootDirPath, fileRelativePaths, err := downloadFilesByGit(gitActualRepoUrl, workspaceInfo.GitBranch, workspaceInfo.ConfigFileRelativePath)
661 if err != nil {
662 return
663 }
664 if len(fileRelativePaths) != 1 || !strings.Contains(fileRelativePaths[0], filepath.Join(workspaceInfo.ConfigFileRelativePath)) {
665 currentErr := fmt.Errorf("配置文件 %v 不存在!git url: %v , branch: %v",
666 workspaceInfo.ConfigFileRelativePath, workspaceInfo.GitCloneRepoUrl, workspaceInfo.GitBranch)
667 err = &fs.PathError{Op: "open", Path: workspaceInfo.ConfigFileRelativePath, Err: currentErr}
668 return
669 }
670
671 //3.2. 下载配置文件关联的yaml文件
672 common.SmartIDELog.Info("下载配置文件 关联的 k8s yaml 文件")
673 configFileRelativePath = fileRelativePaths[0]
674 var configYaml map[string]interface{}
675 configFileBytes, err := os.ReadFile(filepath.Join(gitRepoRootDirPath, configFileRelativePath))
676 if err != nil {
677 return
678 }
679 err = yaml.Unmarshal(configFileBytes, &configYaml)
680 if err != nil {
681 return
682 }
683 filePathExpression := configYaml["workspace"].(map[interface{}]interface{})["kube-deploy-files"].(string)
684 if filePathExpression == "" {
685 return "", "", []string{}, fmt.Errorf("配置文件 %v Workspace.kube-deploy-files 节点未配置!", workspaceInfo.ConfigFileRelativePath)
686 }
687 filePathExpression = filepath.Join(".ide", filePathExpression)
688
689 //
690 _, linkK8sYamlRelativePaths, err = downloadFilesByGit(gitActualRepoUrl, workspaceInfo.GitBranch, filePathExpression)
691 if err != nil {
692 return "", "", []string{}, err
693 }
694 if len(linkK8sYamlRelativePaths) == 0 {
695 return "", "", []string{}, fmt.Errorf("没有找到 %v 匹配的yaml文件!", filePathExpression)
696 }
697
698 return gitRepoRootDirPath, configFileRelativePath, linkK8sYamlRelativePaths, nil
699}
700
701// 等待webide可以访问,并打开
702func waitingAndOpenBrower(workspaceInfo workspace.WorkspaceInfo, originK8sConfig config.SmartIdeK8SConfig) error {

Callers 1

ExecuteK8sStartCmdFunction · 0.85

Calls 3

downloadFilesByGitFunction · 0.85
InfoMethod · 0.80
JoinMethod · 0.45

Tested by

no test coverage detected