38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package v1
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"jcc-schedule/pkg/apiserver"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type StatefulSet struct {
|
|
name string
|
|
namespace string
|
|
}
|
|
|
|
func RestartStatefulSet(c *gin.Context) {
|
|
clusterName := c.Param("clusterName")
|
|
var sts = &StatefulSet{}
|
|
if err := c.BindJSON(&sts); err != nil {
|
|
Response(c, http.StatusBadRequest, "invalid request params.", "")
|
|
return
|
|
}
|
|
//实现kubectl rollout restart StatefulSets功能
|
|
patchOpt := metav1.PatchOptions{FieldManager: "kubectl-rollout"}
|
|
|
|
dt := time.Now()
|
|
|
|
patchInfo := fmt.Sprintf(`{"spec":{"template":{"metadata":{"annotations":{"kubectl.kubernetes.io/restartedAt":"%s"}}}}}`, dt.String())
|
|
_, err := apiserver.ApiServer.ClientSetMap[clusterName].AppsV1().StatefulSets(sts.namespace).Patch(context.TODO(), sts.name, types.StrategicMergePatchType, []byte(patchInfo), patchOpt)
|
|
if err != nil {
|
|
Response(c, http.StatusBadRequest, "failed", nil)
|
|
}
|
|
Response(c, http.StatusOK, "success", nil)
|
|
}
|