Adding GetCronWorkflow endpoint.

- Added supporting proto code
- Added supporting server function and cron_workflow client function
- Added extra checking for possible nil values
This commit is contained in:
Aleksandr Melnikov
2020-03-29 21:37:03 -07:00
parent bcf4400aac
commit 1096a21058
5 changed files with 341 additions and 69 deletions

View File

@@ -16,19 +16,32 @@ func NewCronWorkflowServer() *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),
Schedule: cwf.Schedule,
Timezone: cwf.Timezone,
Suspend: cwf.Suspend,
ConcurrencyPolicy: cwf.ConcurrencyPolicy,
}
if cwf.StartingDeadlineSeconds != nil {
cronWorkflow.StartingDeadlineSeconds = *cwf.StartingDeadlineSeconds
}
if cwf.SuccessfulJobsHistoryLimit != nil {
cronWorkflow.SuccessfulJobsHistoryLimit = *cwf.SuccessfulJobsHistoryLimit
}
if cwf.FailedJobsHistoryLimit != nil {
cronWorkflow.FailedJobsHistoryLimit = *cwf.FailedJobsHistoryLimit
}
if cwf.WorkflowExecution != nil {
cronWorkflow.WorkflowExecution = GenApiWorkflowExecution(cwf.WorkflowExecution)
}
return
}
func (c *CronWorkflowServer) CreateCronWorkflow(ctx context.Context, req *api.CreateWorkflowRequest) (*api.CronWorkflow, error) {
func (c *CronWorkflowServer) CreateCronWorkflow(ctx context.Context, req *api.CreateCronWorkflowRequest) (*api.CronWorkflow, error) {
client := ctx.Value("kubeClient").(*v1.Client)
allowed, err := auth.IsAuthorized(client, req.Namespace, "create", "argoproj.io", "cronworkflows", "")
if err != nil || !allowed {
@@ -68,3 +81,16 @@ func (c *CronWorkflowServer) CreateCronWorkflow(ctx context.Context, req *api.Cr
}
return apiCronWorkflow(cwf), nil
}
func (c *CronWorkflowServer) GetCronWorkflow(ctx context.Context, req *api.GetCronWorkflowRequest) (*api.CronWorkflow, error) {
client := ctx.Value("kubeClient").(*v1.Client)
allowed, err := auth.IsAuthorized(client, req.Namespace, "get", "argoproj.io", "cronworkflows", req.Name)
if err != nil || !allowed {
return nil, err
}
cwf, err := client.GetCronWorkflow(req.Namespace, req.Name)
if err != nil {
return nil, err
}
return apiCronWorkflow(cwf), nil
}