[ Agent ] [ CMII ] - 新增版本更新的模式;新增部署模板;新增消息推送模块
This commit is contained in:
45
agent-go/k8s_exec/CmiiAppDeploy.go
Normal file
45
agent-go/k8s_exec/CmiiAppDeploy.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package k8s_exec
|
||||
|
||||
import (
|
||||
"agent-go/utils"
|
||||
"bytes"
|
||||
v1 "k8s.io/api/apps/v1"
|
||||
appsv1 "k8s.io/client-go/applyconfigurations/apps/v1"
|
||||
"sigs.k8s.io/yaml"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
type CmiiBackendDeploymentConfig struct {
|
||||
Namespace string
|
||||
AppName string
|
||||
ImageTag string
|
||||
TagVersion string
|
||||
Replicas string
|
||||
}
|
||||
|
||||
func (backend CmiiBackendDeploymentConfig) ParseToApplyConf() *appsv1.DeploymentApplyConfiguration {
|
||||
|
||||
// 解析模板
|
||||
tmpl, err := template.New("cmiiBackendDeploymentTemplate").Parse(cmiiBackendDeploymentTemplate)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 应用数据并打印结果
|
||||
var result bytes.Buffer
|
||||
err = tmpl.Execute(&result, backend)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 创建Deployment对象
|
||||
deployment := v1.Deployment{}
|
||||
err = yaml.Unmarshal(result.Bytes(), &deployment)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
utils.BeautifulPrint(&deployment)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user