github.com/argoproj/argo-cd/v2@v2.10.9/resource_customizations/argoproj.io/WorkflowTemplate/actions/create-workflow/action.lua (about)

     1  local os = require("os")
     2  
     3  -- This action constructs a Workflow resource from a WorkflowTemplate resource, to enable creating a WorkflowTemplate instance
     4  -- on demand.
     5  -- It returns an array with a single member - a table with the operation to perform (create) and the Workflow resource.
     6  -- It mimics the output of "argo submit --from=workflowtemplate/<WORKFLOW_TEMPLATE_NAME>" command, declaratively.
     7  
     8  -- This code is written to mimic what the Argo Workflows API server does to create a Workflow from a WorkflowTemplate.
     9  -- https://github.com/argoproj/argo-workflows/blob/873a58de7dd9dad76d5577b8c4294a58b52849b8/workflow/common/convert.go#L34
    10  
    11  local workflow = {}
    12  workflow.apiVersion = "argoproj.io/v1alpha1"
    13  workflow.kind = "Workflow"
    14  
    15  workflow.metadata = {}
    16  workflow.metadata.name = obj.metadata.name .. "-" ..os.date("!%Y%m%d%H%M")
    17  workflow.metadata.namespace = obj.metadata.namespace
    18  workflow.metadata.labels = {}
    19  workflow.metadata.labels["workflows.argoproj.io/workflow-template"] = obj.metadata.name
    20  
    21  workflow.spec = {}
    22  workflow.spec.workflowTemplateRef = {}
    23  workflow.spec.workflowTemplateRef.name = obj.metadata.name
    24  
    25  local ownerRef = {}
    26  ownerRef.apiVersion = obj.apiVersion
    27  ownerRef.kind = obj.kind
    28  ownerRef.name = obj.metadata.name
    29  ownerRef.uid = obj.metadata.uid
    30  workflow.metadata.ownerReferences = {}
    31  workflow.metadata.ownerReferences[1] = ownerRef
    32  
    33  local impactedResource = {}
    34  impactedResource.operation = "create"
    35  impactedResource.resource = workflow
    36  local result = {}
    37  result[1] = impactedResource
    38  
    39  return result