github.com/kubevela/workflow@v0.6.0/charts/vela-workflow/templates/definitions/vela-cli.yaml (about)

     1  # Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
     2  # Definition source cue file: vela-templates/definitions/internal/vela-cli.cue
     3  apiVersion: core.oam.dev/v1beta1
     4  kind: WorkflowStepDefinition
     5  metadata:
     6    annotations:
     7      definition.oam.dev/description: Run a vela command
     8      definition.oam.dev/example-url: https://raw.githubusercontent.com/kubevela/workflow/main/examples/workflow-run/apply-terraform-resource.yaml
     9    name: vela-cli
    10    namespace: {{ include "systemDefinitionNamespace" . }}
    11  spec:
    12    schematic:
    13      cue:
    14        template: |
    15          import (
    16          	"vela/op"
    17          )
    18  
    19          mountsArray: [
    20          	if parameter.storage != _|_ && parameter.storage.secret != _|_ for v in parameter.storage.secret {
    21          		{
    22          			name:      "secret-" + v.name
    23          			mountPath: v.mountPath
    24          			if v.subPath != _|_ {
    25          				subPath: v.subPath
    26          			}
    27          		}
    28          	},
    29          	if parameter.storage != _|_ && parameter.storage.hostPath != _|_ for v in parameter.storage.hostPath {
    30          		{
    31          			name:      "hostpath-" + v.name
    32          			mountPath: v.mountPath
    33          		}
    34          	},
    35          ]
    36          volumesList: [
    37          	if parameter.storage != _|_ && parameter.storage.secret != _|_ for v in parameter.storage.secret {
    38          		{
    39          			name: "secret-" + v.name
    40          			secret: {
    41          				defaultMode: v.defaultMode
    42          				secretName:  v.secretName
    43          				if v.items != _|_ {
    44          					items: v.items
    45          				}
    46          			}
    47          		}
    48          		if parameter.storage != _|_ && parameter.storage.hostPath != _|_ for v in parameter.storage.hostPath {
    49          			{
    50          				name: "hostpath-" + v.name
    51          				path: v.path
    52          			}
    53          		}
    54          	},
    55          ]
    56          deDupVolumesArray: [
    57          	for val in [
    58          		for i, vi in volumesList {
    59          			for j, vj in volumesList if j < i && vi.name == vj.name {
    60          				_ignore: true
    61          			}
    62          			vi
    63          		},
    64          	] if val._ignore == _|_ {
    65          		val
    66          	},
    67          ]
    68          job: op.#Apply & {
    69          	value: {
    70          		apiVersion: "batch/v1"
    71          		kind:       "Job"
    72          		metadata: {
    73          			name: "\(context.name)-\(context.stepName)-\(context.stepSessionID)"
    74          			if parameter.serviceAccountName == "kubevela-vela-core" {
    75          				namespace: "vela-system"
    76          			}
    77          			if parameter.serviceAccountName != "kubevela-vela-core" {
    78          				namespace: context.namespace
    79          			}
    80          		}
    81          		spec: {
    82          			backoffLimit: 3
    83          			template: {
    84          				metadata: labels: "workflow.oam.dev/step-name": "\(context.name)-\(context.stepName)"
    85          				spec: {
    86          					containers: [
    87          						{
    88          							name:         "\(context.name)-\(context.stepName)-\(context.stepSessionID)-job"
    89          							image:        parameter.image
    90          							command:      parameter.command
    91          							volumeMounts: mountsArray
    92          						},
    93          					]
    94          					restartPolicy:  "Never"
    95          					serviceAccount: parameter.serviceAccountName
    96          					volumes:        deDupVolumesArray
    97          				}
    98          			}
    99          		}
   100          	}
   101          }
   102          log: op.#Log & {
   103          	source: resources: [{labelSelector: "workflow.oam.dev/step-name": "\(context.name)-\(context.stepName)"}]
   104          }
   105          fail: op.#Steps & {
   106          	if job.value.status.failed != _|_ {
   107          		if job.value.status.failed > 2 {
   108          			breakWorkflow: op.#Fail & {
   109          				message: "failed to execute vela command"
   110          			}
   111          		}
   112          	}
   113          }
   114          wait: op.#ConditionalWait & {
   115          	continue: job.value.status.succeeded != _|_ && job.value.status.succeeded > 0
   116          }
   117          parameter: {
   118          	// +usage=Specify the name of the addon.
   119          	addonName: string
   120          	// +usage=Specify the vela command
   121          	command: [...string]
   122          	// +usage=Specify the image
   123          	image: *"oamdev/vela-cli:v1.6.4" | string
   124          	// +usage=specify serviceAccountName want to use
   125          	serviceAccountName: *"kubevela-vela-core" | string
   126          	storage?: {
   127          		// +usage=Mount Secret type storage
   128          		secret?: [...{
   129          			name:        string
   130          			mountPath:   string
   131          			subPath?:    string
   132          			defaultMode: *420 | int
   133          			secretName:  string
   134          			items?: [...{
   135          				key:  string
   136          				path: string
   137          				mode: *511 | int
   138          			}]
   139          		}]
   140          		// +usage=Declare host path type storage
   141          		hostPath?: [...{
   142          			name:      string
   143          			path:      string
   144          			mountPath: string
   145          			type:      *"Directory" | "DirectoryOrCreate" | "FileOrCreate" | "File" | "Socket" | "CharDevice" | "BlockDevice"
   146          		}]
   147          	}
   148          }
   149