mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-17 19:20:36 +08:00
add sys-uid as a param to all workflows
This commit is contained in:
@@ -103,6 +103,20 @@ func (c *Client) injectAutomatedFields(namespace string, wf *wfv1.Workflow, opts
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uid := wf.Labels[label.WorkflowUid]
|
||||||
|
if uid == "" {
|
||||||
|
uid = "00000000-0000-0000-0000-000000000000"
|
||||||
|
}
|
||||||
|
if &wf.Spec.Arguments == nil {
|
||||||
|
wf.Spec.Arguments = wfv1.Arguments{
|
||||||
|
Parameters: []wfv1.Parameter{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wf.Spec.Arguments.Parameters = append(wf.Spec.Arguments.Parameters, wfv1.Parameter{
|
||||||
|
Name: "sys-uid",
|
||||||
|
Value: ptr.String(uid),
|
||||||
|
})
|
||||||
|
|
||||||
addSecretValsToTemplate := true
|
addSecretValsToTemplate := true
|
||||||
secret, err := c.GetSecret(namespace, "onepanel-default-env")
|
secret, err := c.GetSecret(namespace, "onepanel-default-env")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -384,7 +398,7 @@ func (c *Client) CreateWorkflowExecution(namespace string, workflow *WorkflowExe
|
|||||||
workflow.ID = id
|
workflow.ID = id
|
||||||
workflow.Name = createdWorkflow.Name
|
workflow.Name = createdWorkflow.Name
|
||||||
workflow.CreatedAt = createdWorkflow.CreationTimestamp.UTC()
|
workflow.CreatedAt = createdWorkflow.CreationTimestamp.UTC()
|
||||||
workflow.UID = string(createdWorkflow.ObjectMeta.UID)
|
workflow.UID = workflowUid
|
||||||
workflow.WorkflowTemplate = workflowTemplate
|
workflow.WorkflowTemplate = workflowTemplate
|
||||||
// Manifests could get big, don't return them in this case.
|
// Manifests could get big, don't return them in this case.
|
||||||
workflow.WorkflowTemplate.Manifest = ""
|
workflow.WorkflowTemplate.Manifest = ""
|
||||||
|
@@ -14,6 +14,7 @@ import (
|
|||||||
networking "istio.io/api/networking/v1alpha3"
|
networking "istio.io/api/networking/v1alpha3"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"net/http"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -41,12 +42,6 @@ func generateArguments(spec *WorkspaceSpec, config map[string]string) (err error
|
|||||||
})
|
})
|
||||||
|
|
||||||
// TODO: These can be removed when lint validation of workflows work
|
// TODO: These can be removed when lint validation of workflows work
|
||||||
// Workspace UID
|
|
||||||
spec.Arguments.Parameters = append(spec.Arguments.Parameters, Parameter{
|
|
||||||
Name: "sys-uid",
|
|
||||||
Value: ptr.String("00000000-0000-0000-0000-000000000000"),
|
|
||||||
Type: "input.hidden",
|
|
||||||
})
|
|
||||||
// Resource action parameter
|
// Resource action parameter
|
||||||
spec.Arguments.Parameters = append(spec.Arguments.Parameters, Parameter{
|
spec.Arguments.Parameters = append(spec.Arguments.Parameters, Parameter{
|
||||||
Name: "sys-resource-action",
|
Name: "sys-resource-action",
|
||||||
@@ -287,6 +282,20 @@ metadata:
|
|||||||
When: "{{workflow.parameters.sys-workspace-action}} == delete",
|
When: "{{workflow.parameters.sys-workspace-action}} == delete",
|
||||||
WithItems: volumeClaimItems,
|
WithItems: volumeClaimItems,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "sys-set-phase-running",
|
||||||
|
Template: "sys-update-status",
|
||||||
|
Dependencies: []string{"stateful-set"},
|
||||||
|
Arguments: wfv1.Arguments{
|
||||||
|
Parameters: []wfv1.Parameter{
|
||||||
|
{
|
||||||
|
Name: "sys-workspace-phase",
|
||||||
|
Value: ptr.String(string(WorkspaceRunning)),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
When: "{{workflow.parameters.sys-workspace-action}} == create",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: spec.PostExecutionWorkflow.Entrypoint,
|
Name: spec.PostExecutionWorkflow.Entrypoint,
|
||||||
Template: spec.PostExecutionWorkflow.Entrypoint,
|
Template: spec.PostExecutionWorkflow.Entrypoint,
|
||||||
@@ -335,24 +344,25 @@ metadata:
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// Add curl template
|
||||||
curlPath := fmt.Sprintf("/apis/v1beta1/{{workflow.namespace}}/workspaces/{{workflow.parameters.sys-uid}}/status")
|
curlPath := fmt.Sprintf("/apis/v1beta1/{{workflow.namespace}}/workspaces/{{workflow.parameters.sys-uid}}/status")
|
||||||
status := map[string]interface{}{
|
status := map[string]interface{}{
|
||||||
"phase": "{{input.parameters.phase}}",
|
"phase": "{{input.parameters.sys-workspace-phase}}",
|
||||||
}
|
}
|
||||||
statusBytes, err := json.Marshal(status)
|
statusBytes, err := json.Marshal(status)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
curlNodeTemplate, err := getCURLNodeTemplate("update-workspace-status", curlPath, string(statusBytes))
|
curlNodeTemplate, err := getCURLNodeTemplate("sys-update-status", http.MethodPut, curlPath, string(statusBytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
templates = append(templates, *curlNodeTemplate)
|
templates = append(templates, *curlNodeTemplate)
|
||||||
|
// Add postExecutionWorkflow if it exists
|
||||||
if spec.PostExecutionWorkflow != nil {
|
if spec.PostExecutionWorkflow != nil {
|
||||||
templates = append(templates, spec.PostExecutionWorkflow.Templates...)
|
templates = append(templates, spec.PostExecutionWorkflow.Templates...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Consider storing this as a Go template in a "settings" database table
|
|
||||||
workflowTemplateSpec := map[string]interface{}{
|
workflowTemplateSpec := map[string]interface{}{
|
||||||
"arguments": spec.Arguments,
|
"arguments": spec.Arguments,
|
||||||
"entrypoint": "workspace",
|
"entrypoint": "workspace",
|
||||||
|
Reference in New Issue
Block a user