mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-07 06:30:53 +08:00
update/fix: fixed issue where parameters were not being sent with API response.
Fixed issue where cron workflows did not apply their labels to the newly created workflow executions.
This commit is contained in:
29
pkg/types.go
29
pkg/types.go
@@ -452,6 +452,25 @@ type WorkflowExecution struct {
|
|||||||
Labels map[string]string
|
Labels map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (we *WorkflowExecution) LoadParametersFromBytes() ([]Parameter, error) {
|
||||||
|
loadedParameters := make([]Parameter, 0)
|
||||||
|
|
||||||
|
err := json.Unmarshal(we.ParametersBytes, &loadedParameters)
|
||||||
|
if err != nil {
|
||||||
|
return we.Parameters, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// It might be nil because the value "null" is stored in db if there are no parameters.
|
||||||
|
// for consistency, we return an empty array.
|
||||||
|
if loadedParameters == nil {
|
||||||
|
loadedParameters = make([]Parameter, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
we.Parameters = loadedParameters
|
||||||
|
|
||||||
|
return we.Parameters, err
|
||||||
|
}
|
||||||
|
|
||||||
type ListOptions = metav1.ListOptions
|
type ListOptions = metav1.ListOptions
|
||||||
|
|
||||||
type PodGCStrategy = wfv1.PodGCStrategy
|
type PodGCStrategy = wfv1.PodGCStrategy
|
||||||
@@ -653,3 +672,13 @@ func getWorkspaceColumns(alias string, destination string, extraColumns ...strin
|
|||||||
columns := []string{"id", "created_at", "modified_at", "uid", "name", "namespace", "phase", "parameters", "workspace_template_id", "workspace_template_version", "started_at", "paused_at", "terminated_at"}
|
columns := []string{"id", "created_at", "modified_at", "uid", "name", "namespace", "phase", "parameters", "workspace_template_id", "workspace_template_version", "started_at", "paused_at", "terminated_at"}
|
||||||
return formatColumnSelect(columns, alias, destination, extraColumns...)
|
return formatColumnSelect(columns, alias, destination, extraColumns...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LabelsToMapping(labels ...*Label) map[string]string {
|
||||||
|
result := make(map[string]string)
|
||||||
|
|
||||||
|
for _, label := range labels {
|
||||||
|
result[label.Key] = label.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
@@ -516,6 +516,11 @@ func (c *Client) CronStartWorkflowExecutionStatisticInsert(namespace, name strin
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cronLabels, err := c.GetDbLabels(TypeCronWorkflow, cronWorkflow.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
tx, err := c.DB.Begin()
|
tx, err := c.DB.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -541,11 +546,27 @@ func (c *Client) CronStartWorkflowExecutionStatisticInsert(namespace, name strin
|
|||||||
"parameters": string(parametersJson),
|
"parameters": string(parametersJson),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = sb.Insert("workflow_executions").
|
workflowExecutionId := uint64(0)
|
||||||
SetMap(insertMap).RunWith(tx).Exec()
|
err = sb.Insert("workflow_executions").
|
||||||
|
SetMap(insertMap).
|
||||||
|
Suffix("RETURNING id").
|
||||||
|
RunWith(tx).
|
||||||
|
QueryRow().
|
||||||
|
Scan(&workflowExecutionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(cronLabels) > 0 {
|
||||||
|
labelsMapped := LabelsToMapping(cronLabels...)
|
||||||
|
_, err = c.InsertLabelsBuilder(TypeWorkflowExecution, workflowExecutionId, labelsMapped).
|
||||||
|
RunWith(tx).
|
||||||
|
Exec()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -556,7 +577,7 @@ func (c *Client) CronStartWorkflowExecutionStatisticInsert(namespace, name strin
|
|||||||
func (c *Client) GetWorkflowExecution(namespace, name string) (workflow *WorkflowExecution, err error) {
|
func (c *Client) GetWorkflowExecution(namespace, name string) (workflow *WorkflowExecution, err error) {
|
||||||
workflow = &WorkflowExecution{}
|
workflow = &WorkflowExecution{}
|
||||||
|
|
||||||
query, args, err := sb.Select("we.uid", "we.name", "we.phase", "we.started_at", "we.finished_at").
|
query, args, err := sb.Select(getWorkflowExecutionColumns("we", "")...).
|
||||||
From("workflow_executions we").
|
From("workflow_executions we").
|
||||||
Join("workflow_template_versions wtv ON wtv.id = we.workflow_template_version_id").
|
Join("workflow_template_versions wtv ON wtv.id = we.workflow_template_version_id").
|
||||||
Join("workflow_templates wt ON wt.id = wtv.workflow_template_id").
|
Join("workflow_templates wt ON wt.id = wtv.workflow_template_id").
|
||||||
|
@@ -2,6 +2,7 @@ package converter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/onepanelio/core/api"
|
"github.com/onepanelio/core/api"
|
||||||
|
v1 "github.com/onepanelio/core/pkg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func APIKeyValueToLabel(apiKeyValues []*api.KeyValue) map[string]string {
|
func APIKeyValueToLabel(apiKeyValues []*api.KeyValue) map[string]string {
|
||||||
@@ -29,3 +30,58 @@ func MappingToKeyValue(mapping map[string]string) []*api.KeyValue {
|
|||||||
|
|
||||||
return keyValues
|
return keyValues
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParameterOptionToAPI(option v1.ParameterOption) *api.ParameterOption {
|
||||||
|
apiOption := &api.ParameterOption{
|
||||||
|
Name: option.Name,
|
||||||
|
Value: option.Value,
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiOption
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParameterOptionsToAPI(options []*v1.ParameterOption) []*api.ParameterOption {
|
||||||
|
result := make([]*api.ParameterOption, len(options))
|
||||||
|
|
||||||
|
for i := range options {
|
||||||
|
newItem := ParameterOptionToAPI(*options[i])
|
||||||
|
result[i] = newItem
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParameterToAPI(param v1.Parameter) *api.Parameter {
|
||||||
|
apiParam := &api.Parameter{
|
||||||
|
Name: param.Name,
|
||||||
|
Type: param.Type,
|
||||||
|
Required: param.Required,
|
||||||
|
}
|
||||||
|
|
||||||
|
if param.Value != nil {
|
||||||
|
apiParam.Value = *param.Value
|
||||||
|
}
|
||||||
|
if param.DisplayName != nil {
|
||||||
|
apiParam.DisplayName = *param.DisplayName
|
||||||
|
}
|
||||||
|
if param.Hint != nil {
|
||||||
|
apiParam.Hint = *param.Hint
|
||||||
|
}
|
||||||
|
|
||||||
|
if param.Options != nil {
|
||||||
|
apiParam.Options = ParameterOptionsToAPI(param.Options)
|
||||||
|
}
|
||||||
|
|
||||||
|
return apiParam
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParametersToAPI(params []v1.Parameter) []*api.Parameter {
|
||||||
|
result := make([]*api.Parameter, len(params))
|
||||||
|
|
||||||
|
for i := range params {
|
||||||
|
newItem := ParameterToAPI(params[i])
|
||||||
|
result[i] = newItem
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
@@ -49,6 +49,15 @@ func apiWorkflowExecution(wf *v1.WorkflowExecution) (workflow *api.WorkflowExecu
|
|||||||
workflow.WorkflowTemplate = apiWorkflowTemplate(wf.WorkflowTemplate)
|
workflow.WorkflowTemplate = apiWorkflowTemplate(wf.WorkflowTemplate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if wf.ParametersBytes != nil {
|
||||||
|
parameters, err := wf.LoadParametersFromBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
workflow.Parameters = converter.ParametersToAPI(parameters)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user