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

@@ -7,6 +7,7 @@ import (
"github.com/onepanelio/core/pkg/util"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"regexp"
"strings"
)
@@ -84,6 +85,34 @@ func (c *Client) CreateCronWorkflow(namespace string, cronWorkflow *CronWorkflow
return nil, nil
}
func (c *Client) GetCronWorkflow(namespace, name string) (cronWorkflow *CronWorkflow, err error) {
cwf, err := c.ArgoprojV1alpha1().CronWorkflows(namespace).Get(name, metav1.GetOptions{})
if err != nil {
log.WithFields(log.Fields{
"Namespace": namespace,
"Name": name,
"Error": err.Error(),
}).Error("CronWorkflow not found.")
return nil, util.NewUserError(codes.NotFound, "CronWorkflow not found.")
}
cronWorkflow = &CronWorkflow{
CreatedAt: cwf.CreationTimestamp.UTC(),
UID: string(cwf.UID),
Name: cwf.Name,
Schedule: cwf.Spec.Schedule,
Timezone: cwf.Spec.Timezone,
Suspend: cwf.Spec.Suspend,
ConcurrencyPolicy: string(cwf.Spec.ConcurrencyPolicy),
StartingDeadlineSeconds: cwf.Spec.StartingDeadlineSeconds,
SuccessfulJobsHistoryLimit: cwf.Spec.SuccessfulJobsHistoryLimit,
FailedJobsHistoryLimit: cwf.Spec.FailedJobsHistoryLimit,
WorkflowExecution: nil,
}
return
}
func (c *Client) createCronWorkflow(namespace string, cwf *wfv1.CronWorkflow, opts *WorkflowExecutionOptions) (createdCronWorkflow *wfv1.CronWorkflow, err error) {
if opts == nil {
opts = &WorkflowExecutionOptions{}