forked from nudtpc/pcm-kubernetes
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package pkg
|
|
|
|
import (
|
|
"context"
|
|
"github.com/sirupsen/logrus"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/dynamic"
|
|
kubernetes2 "k8s.io/client-go/kubernetes"
|
|
"strconv"
|
|
)
|
|
|
|
func Start(name, namespace, kind string, clientSet *kubernetes2.Clientset, dynamicClient dynamic.Interface) {
|
|
switch kind {
|
|
case "Deployment":
|
|
deployment, err := clientSet.AppsV1().Deployments(namespace).Get(context.Background(), name, metav1.GetOptions{})
|
|
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 = clientSet.AppsV1().Deployments(namespace).Update(context.Background(), deployment, metav1.UpdateOptions{})
|
|
if err != nil {
|
|
logrus.Error(err)
|
|
}
|
|
case "StatefulSet":
|
|
sts, err := clientSet.AppsV1().StatefulSets(namespace).Get(context.Background(), name, metav1.GetOptions{})
|
|
minReplicas := sts.Annotations["deploy.cloud.sealos.io/minReplicas"]
|
|
if minReplicas != "" {
|
|
rs := StringToInt32(minReplicas)
|
|
sts.Spec.Replicas = &rs
|
|
}
|
|
annotations := sts.GetAnnotations()
|
|
delete(annotations, "deploy.cloud.sealos.io/pause")
|
|
sts, err = clientSet.AppsV1().StatefulSets(namespace).Update(context.Background(), sts, metav1.UpdateOptions{})
|
|
if err != nil {
|
|
logrus.Error(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func StringToInt32(str string) int32 {
|
|
j, _ := strconv.ParseInt(str, 10, 32)
|
|
return int32(j)
|
|
}
|