mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-11-02 09:42:32 +08:00
Added CreateCronWorkflow function to server.
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/onepanelio/core/api"
|
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/onepanelio/core/api"
|
||||||
|
v1 "github.com/onepanelio/core/pkg"
|
||||||
|
"github.com/onepanelio/core/pkg/util/ptr"
|
||||||
|
"github.com/onepanelio/core/server/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CronWorkflowServer struct{}
|
type CronWorkflowServer struct{}
|
||||||
@@ -11,8 +14,6 @@ func NewCronWorkflowServer() *CronWorkflowServer {
|
|||||||
return &CronWorkflowServer{}
|
return &CronWorkflowServer{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CronWorkflowServer) CreateCronWorkflow(ctx context.Context, req *api.CreateWorkflowRequest) (*api.CronWorkflow, error) {
|
|
||||||
panic("implement me")
|
|
||||||
func apiCronWorkflow(cwf *v1.CronWorkflow) (cronWorkflow *api.CronWorkflow) {
|
func apiCronWorkflow(cwf *v1.CronWorkflow) (cronWorkflow *api.CronWorkflow) {
|
||||||
cronWorkflow = &api.CronWorkflow{
|
cronWorkflow = &api.CronWorkflow{
|
||||||
Schedule: cwf.Schedule,
|
Schedule: cwf.Schedule,
|
||||||
@@ -26,4 +27,36 @@ func apiCronWorkflow(cwf *v1.CronWorkflow) (cronWorkflow *api.CronWorkflow) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CronWorkflowServer) CreateCronWorkflow(ctx context.Context, req *api.CreateWorkflowRequest) (*api.CronWorkflow, error) {
|
||||||
|
client := ctx.Value("kubeClient").(*v1.Client)
|
||||||
|
allowed, err := auth.IsAuthorized(client, req.Namespace, "create", "argoproj.io", "cronworkflows", "")
|
||||||
|
if err != nil || !allowed {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
workflow := &v1.WorkflowExecution{
|
||||||
|
WorkflowTemplate: &v1.WorkflowTemplate{
|
||||||
|
UID: req.CronWorkflow.WorkflowExecution.WorkflowTemplate.Uid,
|
||||||
|
Version: req.CronWorkflow.WorkflowExecution.WorkflowTemplate.Version,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, param := range req.CronWorkflow.WorkflowExecution.Parameters {
|
||||||
|
workflow.Parameters = append(workflow.Parameters, v1.WorkflowExecutionParameter{
|
||||||
|
Name: param.Name,
|
||||||
|
Value: ptr.String(param.Value),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
cronWorkflow := &v1.CronWorkflow{
|
||||||
|
WorkflowExecution: workflow,
|
||||||
|
}
|
||||||
|
|
||||||
|
cwf, err := client.CreateCronWorkflow(req.Namespace, cronWorkflow)
|
||||||
|
if err != nil {
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return apiCronWorkflow(cwf), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user