Added TerminateCronWorkflow endpoint.

- Also updated CronWorkflow message to include the name of the cron workflow.
- Updated related function that parses and sets the struct values, to include the name attribute
This commit is contained in:
Aleksandr Melnikov
2020-03-29 22:16:33 -07:00
parent 2ada65e87a
commit 8b4d93af4b
5 changed files with 312 additions and 61 deletions

View File

@@ -2,6 +2,7 @@ package server
import (
"context"
"github.com/golang/protobuf/ptypes/empty"
"github.com/onepanelio/core/api"
v1 "github.com/onepanelio/core/pkg"
"github.com/onepanelio/core/pkg/util/ptr"
@@ -17,6 +18,7 @@ func NewCronWorkflowServer() *CronWorkflowServer {
func apiCronWorkflow(cwf *v1.CronWorkflow) (cronWorkflow *api.CronWorkflow) {
cronWorkflow = &api.CronWorkflow{
Name: cwf.Name,
Schedule: cwf.Schedule,
Timezone: cwf.Timezone,
Suspend: cwf.Suspend,
@@ -139,3 +141,18 @@ func (c *CronWorkflowServer) ListCronWorkflows(ctx context.Context, req *api.Lis
TotalCount: int32(len(apiCronWorkflows)),
}, nil
}
func (c *CronWorkflowServer) TerminateCronWorkflow(ctx context.Context, req *api.TerminateCronWorkflowRequest) (*empty.Empty, error) {
client := ctx.Value("kubeClient").(*v1.Client)
allowed, err := auth.IsAuthorized(client, req.Namespace, "delete", "argoproj.io", "cronworkflows", "")
if err != nil || !allowed {
return nil, err
}
err = client.TerminateWorkflowExecution(req.Namespace, req.Name)
if err != nil {
return nil, err
}
return &empty.Empty{}, nil
}