执行k8s start
(cmd *cobra.Command, k8sUtil k8s.KubernetesUtil, workspaceInfo workspace.WorkspaceInfo, yamlExecuteFun func(yamlConfig config.SmartIdeK8SConfig, workspaceInfo workspace.WorkspaceInfo, cmdtype, userguid, workspaceid string))
| 48 | |
| 49 | // 执行k8s start |
| 50 | func ExecuteK8sStartCmd(cmd *cobra.Command, k8sUtil k8s.KubernetesUtil, |
| 51 | workspaceInfo workspace.WorkspaceInfo, |
| 52 | yamlExecuteFun func(yamlConfig config.SmartIdeK8SConfig, workspaceInfo workspace.WorkspaceInfo, cmdtype, userguid, workspaceid string)) (*workspace.WorkspaceInfo, error) { |
| 53 | common.SmartIDELog.Info(i18nInstance.Start.Info_k8s_init) |
| 54 | |
| 55 | if workspaceInfo.K8sInfo.Namespace == "" { |
| 56 | workspaceInfo.K8sInfo.Namespace = k8sUtil.Namespace |
| 57 | } |
| 58 | runAsUserName := "smartide" //TODO: 可能是自定义的 |
| 59 | |
| 60 | if common.SmartIDELog.Ws_id != "" { |
| 61 | execSSHPolicy(workspaceInfo, common.ServerHost, common.ServerToken, common.ServerUserGuid) |
| 62 | |
| 63 | } |
| 64 | |
| 65 | //1. 解析 配置文件 |
| 66 | var originK8sConfig *config.SmartIdeK8SConfig = nil |
| 67 | var applicationRootDirPath, configFileRelativePath string |
| 68 | var err error |
| 69 | //1.1. 获取配置文件所在根目录、以及配置文件相对路径 |
| 70 | //1.1.1. clone 并解析 |
| 71 | if workspaceInfo.GitCloneRepoUrl != "" { |
| 72 | // 解析 .k8s.ide.yaml 文件(是否需要注入到deploy.yaml文件中) |
| 73 | common.SmartIDELog.Info("下载配置文件 及 关联k8s yaml文件") |
| 74 | applicationRootDirPath, configFileRelativePath, _, err = downloadConfigAndLinkFiles(workspaceInfo) |
| 75 | |
| 76 | // 错误处理 |
| 77 | if err != nil { |
| 78 | if workspaceInfo.SelectedTemplate == nil { // 非模板模式,所有的错误都抛出 |
| 79 | return nil, model.CreateFeedbackError2(err.Error(), false) |
| 80 | } else { // 在没有模板的时候,配置文件不存在的错误不抛出 |
| 81 | switch err.(type) { |
| 82 | case *fs.PathError: |
| 83 | common.SmartIDELog.Warning(err.Error()) |
| 84 | err = nil |
| 85 | default: |
| 86 | return nil, model.CreateFeedbackError2(err.Error(), false) |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // git库中配置文件 和 模板 不能同时存在 |
| 92 | if configFileRelativePath != "" && workspaceInfo.SelectedTemplate != nil { //1.1.1.1. |
| 93 | errMsg := fmt.Sprintf("配置文件 %v 重复", workspaceInfo.ConfigFileRelativePath) |
| 94 | return nil, model.CreateFeedbackError2(errMsg, false) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | //1.1.2. 模板形式,从现有文件夹中加载和解析配置文件 |
| 99 | if workspaceInfo.SelectedTemplate != nil { |
| 100 | applicationRootDirPath = filepath.Join(workspaceInfo.SelectedTemplate.GetTemplateLocalRootDirAbsolutePath(), |
| 101 | workspaceInfo.SelectedTemplate.GetTemplateDirRelativePath()) |
| 102 | configFileRelativePath = globalModel.CONST_Default_ConfigRelativeFilePath //TODO 配置文件名是否有可能会变 |
| 103 | } |
| 104 | |
| 105 | //1.2. 解析配置文件 + 关联的 k8s yaml |
| 106 | if filepath.Join(applicationRootDirPath, configFileRelativePath) == "" || |
| 107 | !common.IsExist(filepath.Join(applicationRootDirPath, configFileRelativePath)) { |
no test coverage detected