github.com/oam-dev/kubevela@v1.9.11/charts/vela-core/templates/defwithtemplate/resource.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/resource.cue
     3  apiVersion: core.oam.dev/v1beta1
     4  kind: TraitDefinition
     5  metadata:
     6    annotations:
     7      definition.oam.dev/description: Add resource requests and limits on K8s pod for your workload which follows the pod spec in path 'spec.template.'
     8    name: resource
     9    namespace: {{ include "systemDefinitionNamespace" . }}
    10  spec:
    11    appliesToWorkloads:
    12      - deployments.apps
    13      - statefulsets.apps
    14      - daemonsets.apps
    15      - jobs.batch
    16      - cronjobs.batch
    17    podDisruptive: true
    18    schematic:
    19      cue:
    20        template: |2
    21          let resourceContent = {
    22          	resources: {
    23          		if parameter.cpu != _|_ if parameter.memory != _|_ if parameter.requests == _|_ if parameter.limits == _|_ {
    24          			// +patchStrategy=retainKeys
    25          			requests: {
    26          				cpu:    parameter.cpu
    27          				memory: parameter.memory
    28          			}
    29          			// +patchStrategy=retainKeys
    30          			limits: {
    31          				cpu:    parameter.cpu
    32          				memory: parameter.memory
    33          			}
    34          		}
    35  
    36          		if parameter.requests != _|_ {
    37          			// +patchStrategy=retainKeys
    38          			requests: {
    39          				cpu:    parameter.requests.cpu
    40          				memory: parameter.requests.memory
    41          			}
    42          		}
    43          		if parameter.limits != _|_ {
    44          			// +patchStrategy=retainKeys
    45          			limits: {
    46          				cpu:    parameter.limits.cpu
    47          				memory: parameter.limits.memory
    48          			}
    49          		}
    50          	}
    51          }
    52  
    53          if context.output.spec != _|_ if context.output.spec.template != _|_ {
    54          	patch: spec: template: spec: {
    55          		// +patchKey=name
    56          		containers: [resourceContent]
    57          	}
    58          }
    59          if context.output.spec != _|_ if context.output.spec.jobTemplate != _|_ {
    60          	patch: spec: jobTemplate: spec: template: spec: {
    61          		// +patchKey=name
    62          		containers: [resourceContent]
    63          	}
    64          }
    65  
    66          parameter: {
    67          	// +usage=Specify the amount of cpu for requests and limits
    68          	cpu?: *1 | number | string
    69          	// +usage=Specify the amount of memory for requests and limits
    70          	memory?: *"2048Mi" | =~"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$"
    71          	// +usage=Specify the resources in requests
    72          	requests?: {
    73          		// +usage=Specify the amount of cpu for requests
    74          		cpu: *1 | number | string
    75          		// +usage=Specify the amount of memory for requests
    76          		memory: *"2048Mi" | =~"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$"
    77          	}
    78          	// +usage=Specify the resources in limits
    79          	limits?: {
    80          		// +usage=Specify the amount of cpu for limits
    81          		cpu: *1 | number | string
    82          		// +usage=Specify the amount of memory for limits
    83          		memory: *"2048Mi" | =~"^([1-9][0-9]{0,63})(E|P|T|G|M|K|Ei|Pi|Ti|Gi|Mi|Ki)$"
    84          	}
    85          }
    86