forked from nudtpc/pcm-kubernetes
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package logic
|
||
|
||
import (
|
||
"context"
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||
"strconv"
|
||
|
||
"gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes/internal/svc"
|
||
"gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes/kubernetes"
|
||
|
||
"github.com/zeromicro/go-zero/core/logx"
|
||
)
|
||
|
||
type StartDeploymentLogic struct {
|
||
ctx context.Context
|
||
svcCtx *svc.ServiceContext
|
||
logx.Logger
|
||
}
|
||
|
||
func NewStartDeploymentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StartDeploymentLogic {
|
||
return &StartDeploymentLogic{
|
||
ctx: ctx,
|
||
svcCtx: svcCtx,
|
||
Logger: logx.WithContext(ctx),
|
||
}
|
||
}
|
||
|
||
// 启动deployment
|
||
func (l *StartDeploymentLogic) StartDeployment(in *kubernetes.DeploymentDetailReq) (*kubernetes.Resp, error) {
|
||
deployment, err := l.svcCtx.ClientSet.AppsV1().Deployments(in.Namespace).Get(l.ctx, in.Name, metav1.GetOptions{})
|
||
//TODO 获取原始replicas数量,即metadata下annotations.deploy.cloud.sealos.io/minReplicas数量
|
||
minReplicas := deployment.Annotations["deploy.cloud.sealos.io/minReplicas"]
|
||
if minReplicas != "" {
|
||
rs := StringToInt32(minReplicas)
|
||
deployment.Spec.Replicas = &rs
|
||
}
|
||
annotations := deployment.GetAnnotations()
|
||
delete(annotations, "deploy.cloud.sealos.io/pause")
|
||
deployment, err = l.svcCtx.ClientSet.AppsV1().Deployments(in.Namespace).Update(l.ctx, deployment, metav1.UpdateOptions{})
|
||
if err != nil {
|
||
return &kubernetes.Resp{
|
||
Code: "500",
|
||
Msg: "failed",
|
||
Data: err.Error(),
|
||
}, nil
|
||
}
|
||
return &kubernetes.Resp{
|
||
Code: "200",
|
||
Msg: "success",
|
||
}, nil
|
||
}
|
||
|
||
func StringToInt32(str string) int32 {
|
||
j, _ := strconv.ParseInt(str, 10, 32)
|
||
return int32(j)
|
||
}
|