Files
onepanel/server/cron_workflow_server.go
Aleksandr Melnikov aab8b4a69b Setting cronWorkflow values during server create request,
from the request data.
2020-03-27 12:20:58 -07:00

68 lines
2.3 KiB
Go

package server
import (
"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{}
func NewCronWorkflowServer() *CronWorkflowServer {
return &CronWorkflowServer{}
}
func apiCronWorkflow(cwf *v1.CronWorkflow) (cronWorkflow *api.CronWorkflow) {
cronWorkflow = &api.CronWorkflow{
Schedule: cwf.Schedule,
Timezone: cwf.Timezone,
Suspend: cwf.Suspend,
ConcurrencyPolicy: cwf.ConcurrencyPolicy,
StartingDeadlineSeconds: *cwf.StartingDeadlineSeconds,
SuccessfulJobsHistoryLimit: *cwf.SuccessfulJobsHistoryLimit,
FailedJobsHistoryLimit: *cwf.FailedJobsHistoryLimit,
WorkflowExecution: GenApiWorkflowExecution(cwf.WorkflowExecution),
}
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{
Schedule: req.CronWorkflow.Schedule,
Timezone: req.CronWorkflow.Timezone,
Suspend: req.CronWorkflow.Suspend,
ConcurrencyPolicy: req.CronWorkflow.ConcurrencyPolicy,
StartingDeadlineSeconds: &req.CronWorkflow.StartingDeadlineSeconds,
SuccessfulJobsHistoryLimit: &req.CronWorkflow.SuccessfulJobsHistoryLimit,
FailedJobsHistoryLimit: &req.CronWorkflow.FailedJobsHistoryLimit,
WorkflowExecution: workflow,
}
cwf, err := client.CreateCronWorkflow(req.Namespace, &cronWorkflow)
if err != nil {
return nil, err
}
return apiCronWorkflow(cwf), nil
}