pcm-kubernetes/internal/logic/startdeploymentlogic.go

57 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}