# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
# Definition source cue file: vela-templates/definitions/internal/clean-jobs.cue
apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
  annotations:
    custom.definition.oam.dev/category: Resource Management
    definition.oam.dev/description: clean applied jobs in the cluster
  name: clean-jobs
  namespace: {{ include "systemDefinitionNamespace" . }}
spec:
  schematic:
    cue:
      template: |
        import (
        	"vela/op"
        )

        parameter: {
        	labelselector?: {...}
        	namespace: *context.namespace | string
        }

        cleanJobs: op.#Delete & {
        	value: {
        		apiVersion: "batch/v1"
        		kind:       "Job"
        		metadata: {
        			name:      context.name
        			namespace: parameter.namespace
        		}
        	}
        	filter: {
        		namespace: parameter.namespace
        		if parameter.labelselector != _|_ {
        			matchingLabels: parameter.labelselector
        		}
        		if parameter.labelselector == _|_ {
        			matchingLabels: "workflow.oam.dev/name": context.name
        		}
        	}
        }

        cleanPods: op.#Delete & {
        	value: {
        		apiVersion: "v1"
        		kind:       "pod"
        		metadata: {
        			name:      context.name
        			namespace: parameter.namespace
        		}
        	}
        	filter: {
        		namespace: parameter.namespace
        		if parameter.labelselector != _|_ {
        			matchingLabels: parameter.labelselector
        		}
        		if parameter.labelselector == _|_ {
        			matchingLabels: "workflow.oam.dev/name": context.name
        		}
        	}
        }

