[ Agent ] [ CMII ] - 新增大量功能
This commit is contained in:
@@ -31,6 +31,7 @@ const (
|
||||
devOperation = "uavcloud-devoperation"
|
||||
validation = "uavcloud-feature"
|
||||
integration = "uavcloud-test"
|
||||
uat = "uavcloud-uat"
|
||||
demo = "uavcloud-demo"
|
||||
workerThread = 4
|
||||
)
|
||||
@@ -96,6 +97,10 @@ func (op *CmiiK8sOperator) changeOperatorEnv(cmiiEnv string) {
|
||||
op.CurrentNamespace = validation
|
||||
}
|
||||
|
||||
if strings.Contains(cmiiEnv, "uat") {
|
||||
op.CurrentNamespace = uat
|
||||
}
|
||||
|
||||
if strings.Contains(cmiiEnv, "demo") {
|
||||
op.CurrentNamespace = demo
|
||||
}
|
||||
@@ -236,11 +241,24 @@ func (op *CmiiK8sOperator) DeploymentAllInterface(cmiiEnv string) []CmiiDeployme
|
||||
|
||||
index := 0
|
||||
for deployment := range ccc {
|
||||
// 过滤所有非CMII的内容
|
||||
if strings.Contains(deployment.Name, "proxy") {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(deployment.Name, "minio") {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(deployment.Name, "helm-live-rtsp") {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(deployment.Name, "nfs") {
|
||||
continue
|
||||
}
|
||||
results[index] = deployment
|
||||
index++
|
||||
}
|
||||
|
||||
return results
|
||||
return results[:index]
|
||||
}
|
||||
|
||||
func (op *CmiiK8sOperator) DeploymentFizz(cmiiEnv, appFizz string) (fizzDeployment []v1.Deployment) {
|
||||
@@ -262,7 +280,7 @@ func (op *CmiiK8sOperator) DeploymentFizz(cmiiEnv, appFizz string) (fizzDeployme
|
||||
}
|
||||
|
||||
func (op *CmiiK8sOperator) DeploymentExist(cmiiEnv, appName string) (exists *v1.Deployment) {
|
||||
|
||||
op.changeOperatorEnv(cmiiEnv)
|
||||
client := op.CurrentClient
|
||||
|
||||
deployment, err := client.AppsV1().Deployments(op.CurrentNamespace).Get(context.TODO(), appName, metav1.GetOptions{})
|
||||
@@ -273,6 +291,23 @@ func (op *CmiiK8sOperator) DeploymentExist(cmiiEnv, appName string) (exists *v1.
|
||||
|
||||
return deployment
|
||||
}
|
||||
|
||||
func (op *CmiiK8sOperator) DeploymentOneInterface(cmiiEnv, appName string) (deploy *CmiiDeploymentInterface) {
|
||||
op.changeOperatorEnv(cmiiEnv)
|
||||
client := op.CurrentClient
|
||||
deploymentInterface := CmiiDeploymentInterface{}
|
||||
|
||||
deployment, err := client.AppsV1().Deployments(op.CurrentNamespace).Get(context.TODO(), appName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
log.ErrorF("[DeploymentExist] - deployments [%s] [%s] not exists ! %s", cmiiEnv, appName, err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
convert := deploymentInterface.Convert(*deployment)
|
||||
|
||||
return &convert
|
||||
}
|
||||
|
||||
func (op *CmiiK8sOperator) DeploymentScale(cmiiEnv, appFizz string, scaleCount int32) bool {
|
||||
|
||||
deploymentFizz := op.DeploymentFizz(cmiiEnv, appFizz)
|
||||
@@ -309,6 +344,41 @@ func (op *CmiiK8sOperator) DeploymentScale(cmiiEnv, appFizz string, scaleCount i
|
||||
return true
|
||||
}
|
||||
|
||||
func (op *CmiiK8sOperator) DeploymentUpdateTag(cmiiEnv, appName, newTag string) bool {
|
||||
|
||||
if newTag == "" {
|
||||
log.WarnF("[DeploymentUpdateTag] - can not update image tag to null!")
|
||||
return false
|
||||
}
|
||||
|
||||
deployment := op.DeploymentExist(cmiiEnv, appName)
|
||||
if deployment == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
containers := deployment.Spec.Template.Spec.Containers
|
||||
if len(containers) == 1 {
|
||||
// only update this kind
|
||||
container := containers[0]
|
||||
split := strings.Split(container.Image, ":")
|
||||
|
||||
container.Image = split[0] + ":" + newTag
|
||||
log.InfoF("[DeploymentUpdateTag] - update [%s] [%s] from [%s] to [%s]", op.CurrentNamespace, appName, split[1], container.Image)
|
||||
|
||||
// re assign
|
||||
deployment.Spec.Template.Spec.Containers[0] = container
|
||||
|
||||
// update
|
||||
_, err := op.CurrentClient.AppsV1().Deployments(deployment.Namespace).Update(context.TODO(), deployment, metav1.UpdateOptions{})
|
||||
if err != nil {
|
||||
log.ErrorF("[DeploymentUpdateTag] - update [%s] [%s] from [%s] to [%s] error ! %s", op.CurrentNamespace, appName, split[1], container.Image, err.Error())
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (op *CmiiK8sOperator) ReplicaSet(cmiiEnv, replicaSetName string) *v1.ReplicaSet {
|
||||
|
||||
op.changeOperatorEnv(cmiiEnv)
|
||||
|
||||
Reference in New Issue
Block a user