45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
"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 PauseDeploymentLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewPauseDeploymentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PauseDeploymentLogic {
|
|
return &PauseDeploymentLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
// 暂停POD
|
|
func (l *PauseDeploymentLogic) PauseDeployment(in *kubernetes.DeploymentDetailReq) (*kubernetes.Resp, error) {
|
|
// 获取Deployment对象
|
|
deployment, err := l.svcCtx.ClientSet.AppsV1().Deployments(in.Namespace).Get(l.ctx, in.Name, metav1.GetOptions{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// 缩放Deployment对象为0个副本
|
|
rs := int32(0)
|
|
deployment.Spec.Replicas = &rs
|
|
annotations := deployment.GetAnnotations()
|
|
annotations["deploy.cloud.sealos.io/pause"] = `{"target":"","value":""}`
|
|
_, err = l.svcCtx.ClientSet.AppsV1().Deployments(in.Namespace).Update(l.ctx, deployment, metav1.UpdateOptions{})
|
|
return &kubernetes.Resp{
|
|
Code: "200",
|
|
Msg: "success",
|
|
}, nil
|
|
}
|