github.com/oam-dev/kubevela@v1.9.11/charts/vela-core/templates/defwithtemplate/daemon.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/daemon.cue
     3  apiVersion: core.oam.dev/v1beta1
     4  kind: ComponentDefinition
     5  metadata:
     6    annotations:
     7      definition.oam.dev/description: Describes daemonset services in Kubernetes.
     8    name: daemon
     9    namespace: {{ include "systemDefinitionNamespace" . }}
    10  spec:
    11    schematic:
    12      cue:
    13        template: |
    14          import (
    15          	"strconv"
    16          )
    17  
    18          mountsArray: [
    19          	if parameter.volumeMounts != _|_ && parameter.volumeMounts.pvc != _|_ for v in parameter.volumeMounts.pvc {
    20          		{
    21          			mountPath: v.mountPath
    22          			if v.subPath != _|_ {
    23          				subPath: v.subPath
    24          			}
    25          			name: v.name
    26          		}
    27          	},
    28  
    29          	if parameter.volumeMounts != _|_ && parameter.volumeMounts.configMap != _|_ for v in parameter.volumeMounts.configMap {
    30          		{
    31          			mountPath: v.mountPath
    32          			if v.subPath != _|_ {
    33          				subPath: v.subPath
    34          			}
    35          			name: v.name
    36          		}
    37          	},
    38  
    39          	if parameter.volumeMounts != _|_ && parameter.volumeMounts.secret != _|_ for v in parameter.volumeMounts.secret {
    40          		{
    41          			mountPath: v.mountPath
    42          			if v.subPath != _|_ {
    43          				subPath: v.subPath
    44          			}
    45          			name: v.name
    46          		}
    47          	},
    48  
    49          	if parameter.volumeMounts != _|_ && parameter.volumeMounts.emptyDir != _|_ for v in parameter.volumeMounts.emptyDir {
    50          		{
    51          			mountPath: v.mountPath
    52          			if v.subPath != _|_ {
    53          				subPath: v.subPath
    54          			}
    55          			name: v.name
    56          		}
    57          	},
    58  
    59          	if parameter.volumeMounts != _|_ && parameter.volumeMounts.hostPath != _|_ for v in parameter.volumeMounts.hostPath {
    60          		{
    61          			mountPath: v.mountPath
    62          			if v.subPath != _|_ {
    63          				subPath: v.subPath
    64          			}
    65          			name: v.name
    66          		}
    67          	},
    68          ]
    69  
    70          volumesList: [
    71          	if parameter.volumeMounts != _|_ && parameter.volumeMounts.pvc != _|_ for v in parameter.volumeMounts.pvc {
    72          		{
    73          			name: v.name
    74          			persistentVolumeClaim: claimName: v.claimName
    75          		}
    76          	},
    77  
    78          	if parameter.volumeMounts != _|_ && parameter.volumeMounts.configMap != _|_ for v in parameter.volumeMounts.configMap {
    79          		{
    80          			name: v.name
    81          			configMap: {
    82          				defaultMode: v.defaultMode
    83          				name:        v.cmName
    84          				if v.items != _|_ {
    85          					items: v.items
    86          				}
    87          			}
    88          		}
    89          	},
    90  
    91          	if parameter.volumeMounts != _|_ && parameter.volumeMounts.secret != _|_ for v in parameter.volumeMounts.secret {
    92          		{
    93          			name: v.name
    94          			secret: {
    95          				defaultMode: v.defaultMode
    96          				secretName:  v.secretName
    97          				if v.items != _|_ {
    98          					items: v.items
    99          				}
   100          			}
   101          		}
   102          	},
   103  
   104          	if parameter.volumeMounts != _|_ && parameter.volumeMounts.emptyDir != _|_ for v in parameter.volumeMounts.emptyDir {
   105          		{
   106          			name: v.name
   107          			emptyDir: medium: v.medium
   108          		}
   109          	},
   110  
   111          	if parameter.volumeMounts != _|_ && parameter.volumeMounts.hostPath != _|_ for v in parameter.volumeMounts.hostPath {
   112          		{
   113          			name: v.name
   114          			hostPath: path: v.path
   115          		}
   116          	},
   117          ]
   118  
   119          deDupVolumesArray: [
   120          	for val in [
   121          		for i, vi in volumesList {
   122          			for j, vj in volumesList if j < i && vi.name == vj.name {
   123          				_ignore: true
   124          			}
   125          			vi
   126          		},
   127          	] if val._ignore == _|_ {
   128          		val
   129          	},
   130          ]
   131  
   132          output: {
   133          	apiVersion: "apps/v1"
   134          	kind:       "DaemonSet"
   135          	spec: {
   136          		selector: matchLabels: "app.oam.dev/component": context.name
   137  
   138          		template: {
   139          			metadata: {
   140          				labels: {
   141          					if parameter.labels != _|_ {
   142          						parameter.labels
   143          					}
   144          					if parameter.addRevisionLabel {
   145          						"app.oam.dev/revision": context.revision
   146          					}
   147          					"app.oam.dev/name":      context.appName
   148          					"app.oam.dev/component": context.name
   149          				}
   150          				if parameter.annotations != _|_ {
   151          					annotations: parameter.annotations
   152          				}
   153          			}
   154  
   155          			spec: {
   156          				containers: [{
   157          					name:  context.name
   158          					image: parameter.image
   159          					if parameter["port"] != _|_ && parameter["ports"] == _|_ {
   160          						ports: [{
   161          							containerPort: parameter.port
   162          						}]
   163          					}
   164          					if parameter["ports"] != _|_ {
   165          						ports: [ for v in parameter.ports {
   166          							{
   167          								containerPort: v.port
   168          								protocol:      v.protocol
   169          								if v.name != _|_ {
   170          									name: v.name
   171          								}
   172          								if v.name == _|_ {
   173          									name: "port-" + strconv.FormatInt(v.port, 10)
   174          								}
   175          							}}]
   176          					}
   177  
   178          					if parameter["imagePullPolicy"] != _|_ {
   179          						imagePullPolicy: parameter.imagePullPolicy
   180          					}
   181  
   182          					if parameter["cmd"] != _|_ {
   183          						command: parameter.cmd
   184          					}
   185  
   186          					if parameter["env"] != _|_ {
   187          						env: parameter.env
   188          					}
   189  
   190          					if context["config"] != _|_ {
   191          						env: context.config
   192          					}
   193  
   194          					if parameter["cpu"] != _|_ {
   195          						resources: {
   196          							limits: cpu:   parameter.cpu
   197          							requests: cpu: parameter.cpu
   198          						}
   199          					}
   200  
   201          					if parameter["memory"] != _|_ {
   202          						resources: {
   203          							limits: memory:   parameter.memory
   204          							requests: memory: parameter.memory
   205          						}
   206          					}
   207  
   208          					if parameter["volumes"] != _|_ && parameter["volumeMounts"] == _|_ {
   209          						volumeMounts: [ for v in parameter.volumes {
   210          							{
   211          								mountPath: v.mountPath
   212          								name:      v.name
   213          							}}]
   214          					}
   215  
   216          					if parameter["volumeMounts"] != _|_ {
   217          						volumeMounts: mountsArray
   218          					}
   219  
   220          					if parameter["livenessProbe"] != _|_ {
   221          						livenessProbe: parameter.livenessProbe
   222          					}
   223  
   224          					if parameter["readinessProbe"] != _|_ {
   225          						readinessProbe: parameter.readinessProbe
   226          					}
   227  
   228          				}]
   229  
   230          				if parameter["hostAliases"] != _|_ {
   231          					// +patchKey=ip
   232          					hostAliases: parameter.hostAliases
   233          				}
   234  
   235          				if parameter["imagePullSecrets"] != _|_ {
   236          					imagePullSecrets: [ for v in parameter.imagePullSecrets {
   237          						name: v
   238          					},
   239          					]
   240          				}
   241  
   242          				if parameter["volumes"] != _|_ && parameter["volumeMounts"] == _|_ {
   243          					volumes: [ for v in parameter.volumes {
   244          						{
   245          							name: v.name
   246          							if v.type == "pvc" {
   247          								persistentVolumeClaim: claimName: v.claimName
   248          							}
   249          							if v.type == "configMap" {
   250          								configMap: {
   251          									defaultMode: v.defaultMode
   252          									name:        v.cmName
   253          									if v.items != _|_ {
   254          										items: v.items
   255          									}
   256          								}
   257          							}
   258          							if v.type == "secret" {
   259          								secret: {
   260          									defaultMode: v.defaultMode
   261          									secretName:  v.secretName
   262          									if v.items != _|_ {
   263          										items: v.items
   264          									}
   265          								}
   266          							}
   267          							if v.type == "emptyDir" {
   268          								emptyDir: medium: v.medium
   269          							}
   270          						}
   271          					}]
   272          				}
   273  
   274          				if parameter["volumeMounts"] != _|_ {
   275          					volumes: deDupVolumesArray
   276          				}
   277          			}
   278          		}
   279          	}
   280          }
   281  
   282          exposePorts: [
   283          	if parameter.ports != _|_ for v in parameter.ports if v.expose == true {
   284          		port:       v.port
   285          		targetPort: v.port
   286          		if v.name != _|_ {
   287          			name: v.name
   288          		}
   289          		if v.name == _|_ {
   290          			name: "port-" + strconv.FormatInt(v.port, 10)
   291          		}
   292          	},
   293          ]
   294  
   295          outputs: {
   296          	if len(exposePorts) != 0 {
   297          		webserviceExpose: {
   298          			apiVersion: "v1"
   299          			kind:       "Service"
   300          			metadata: name: context.name
   301          			spec: {
   302          				selector: "app.oam.dev/component": context.name
   303          				ports: exposePorts
   304          				type:  parameter.exposeType
   305          			}
   306          		}
   307          	}
   308          }
   309  
   310          parameter: {
   311          	// +usage=Specify the labels in the workload
   312          	labels?: [string]: string
   313  
   314          	// +usage=Specify the annotations in the workload
   315          	annotations?: [string]: string
   316  
   317          	// +usage=Which image would you like to use for your service
   318          	// +short=i
   319          	image: string
   320  
   321          	// +usage=Specify image pull policy for your service
   322          	imagePullPolicy?: "Always" | "Never" | "IfNotPresent"
   323  
   324          	// +usage=Specify image pull secrets for your service
   325          	imagePullSecrets?: [...string]
   326  
   327          	// +ignore
   328          	// +usage=Deprecated field, please use ports instead
   329          	// +short=p
   330          	port?: int
   331  
   332          	// +usage=Which ports do you want customer traffic sent to, defaults to 80
   333          	ports?: [...{
   334          		// +usage=Number of port to expose on the pod's IP address
   335          		port: int
   336          		// +usage=Name of the port
   337          		name?: string
   338          		// +usage=Protocol for port. Must be UDP, TCP, or SCTP
   339          		protocol: *"TCP" | "UDP" | "SCTP"
   340          		// +usage=Specify if the port should be exposed
   341          		expose: *false | bool
   342          	}]
   343  
   344          	// +ignore
   345          	// +usage=Specify what kind of Service you want. options: "ClusterIP", "NodePort", "LoadBalancer", "ExternalName"
   346          	exposeType: *"ClusterIP" | "NodePort" | "LoadBalancer" | "ExternalName"
   347  
   348          	// +ignore
   349          	// +usage=If addRevisionLabel is true, the revision label will be added to the underlying pods
   350          	addRevisionLabel: *false | bool
   351  
   352          	// +usage=Commands to run in the container
   353          	cmd?: [...string]
   354  
   355          	// +usage=Define arguments by using environment variables
   356          	env?: [...{
   357          		// +usage=Environment variable name
   358          		name: string
   359          		// +usage=The value of the environment variable
   360          		value?: string
   361          		// +usage=Specifies a source the value of this var should come from
   362          		valueFrom?: {
   363          			// +usage=Selects a key of a secret in the pod's namespace
   364          			secretKeyRef?: {
   365          				// +usage=The name of the secret in the pod's namespace to select from
   366          				name: string
   367          				// +usage=The key of the secret to select from. Must be a valid secret key
   368          				key: string
   369          			}
   370          			// +usage=Selects a key of a config map in the pod's namespace
   371          			configMapKeyRef?: {
   372          				// +usage=The name of the config map in the pod's namespace to select from
   373          				name: string
   374          				// +usage=The key of the config map to select from. Must be a valid secret key
   375          				key: string
   376          			}
   377          		}
   378          	}]
   379  
   380          	// +usage=Number of CPU units for the service, like `0.5` (0.5 CPU core), `1` (1 CPU core)
   381          	cpu?: string
   382  
   383          	// +usage=Specifies the attributes of the memory resource required for the container.
   384          	memory?: string
   385  
   386          	volumeMounts?: {
   387          		// +usage=Mount PVC type volume
   388          		pvc?: [...{
   389          			name:      string
   390          			mountPath: string
   391          			// +usage=The name of the PVC
   392          			claimName: string
   393          		}]
   394          		// +usage=Mount ConfigMap type volume
   395          		configMap?: [...{
   396          			name:        string
   397          			mountPath:   string
   398          			defaultMode: *420 | int
   399          			cmName:      string
   400          			items?: [...{
   401          				key:  string
   402          				path: string
   403          				mode: *511 | int
   404          			}]
   405          		}]
   406          		// +usage=Mount Secret type volume
   407          		secret?: [...{
   408          			name:        string
   409          			mountPath:   string
   410          			defaultMode: *420 | int
   411          			secretName:  string
   412          			items?: [...{
   413          				key:  string
   414          				path: string
   415          				mode: *511 | int
   416          			}]
   417          		}]
   418          		// +usage=Mount EmptyDir type volume
   419          		emptyDir?: [...{
   420          			name:      string
   421          			mountPath: string
   422          			medium:    *"" | "Memory"
   423          		}]
   424          		// +usage=Mount HostPath type volume
   425          		hostPath?: [...{
   426          			name:              string
   427          			mountPath:         string
   428          			mountPropagation?: "None" | "HostToContainer" | "Bidirectional"
   429          			path:              string
   430          			readOnly?:         bool
   431          		}]
   432          	}
   433  
   434          	// +usage=Deprecated field, use volumeMounts instead.
   435          	volumes?: [...{
   436          		name:      string
   437          		mountPath: string
   438          		// +usage=Specify volume type, options: "pvc","configMap","secret","emptyDir", default to emptyDir
   439          		type: *"emptyDir" | "pvc" | "configMap" | "secret"
   440          		if type == "pvc" {
   441          			claimName: string
   442          		}
   443          		if type == "configMap" {
   444          			defaultMode: *420 | int
   445          			cmName:      string
   446          			items?: [...{
   447          				key:  string
   448          				path: string
   449          				mode: *511 | int
   450          			}]
   451          		}
   452          		if type == "secret" {
   453          			defaultMode: *420 | int
   454          			secretName:  string
   455          			items?: [...{
   456          				key:  string
   457          				path: string
   458          				mode: *511 | int
   459          			}]
   460          		}
   461          		if type == "emptyDir" {
   462          			medium: *"" | "Memory"
   463          		}
   464          	}]
   465  
   466          	// +usage=Instructions for assessing whether the container is alive.
   467          	livenessProbe?: #HealthProbe
   468  
   469          	// +usage=Instructions for assessing whether the container is in a suitable state to serve traffic.
   470          	readinessProbe?: #HealthProbe
   471  
   472          	// +usage=Specify the hostAliases to add
   473          	hostAliases?: [...{
   474          		ip: string
   475          		hostnames: [...string]
   476          	}]
   477          }
   478  
   479          #HealthProbe: {
   480  
   481          	// +usage=Instructions for assessing container health by executing a command. Either this attribute or the httpGet attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the httpGet attribute and the tcpSocket attribute.
   482          	exec?: {
   483          		// +usage=A command to be executed inside the container to assess its health. Each space delimited token of the command is a separate array element. Commands exiting 0 are considered to be successful probes, whilst all other exit codes are considered failures.
   484          		command: [...string]
   485          	}
   486  
   487          	// +usage=Instructions for assessing container health by executing an HTTP GET request. Either this attribute or the exec attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the tcpSocket attribute.
   488          	httpGet?: {
   489          		// +usage=The endpoint, relative to the port, to which the HTTP GET request should be directed.
   490          		path: string
   491          		// +usage=The TCP socket within the container to which the HTTP GET request should be directed.
   492          		port:    int
   493          		host?:   string
   494          		scheme?: *"HTTP" | string
   495          		httpHeaders?: [...{
   496          			name:  string
   497          			value: string
   498          		}]
   499          	}
   500  
   501          	// +usage=Instructions for assessing container health by probing a TCP socket. Either this attribute or the exec attribute or the httpGet attribute MUST be specified. This attribute is mutually exclusive with both the exec attribute and the httpGet attribute.
   502          	tcpSocket?: {
   503          		// +usage=The TCP socket within the container that should be probed to assess container health.
   504          		port: int
   505          	}
   506  
   507          	// +usage=Number of seconds after the container is started before the first probe is initiated.
   508          	initialDelaySeconds: *0 | int
   509  
   510          	// +usage=How often, in seconds, to execute the probe.
   511          	periodSeconds: *10 | int
   512  
   513          	// +usage=Number of seconds after which the probe times out.
   514          	timeoutSeconds: *1 | int
   515  
   516          	// +usage=Minimum consecutive successes for the probe to be considered successful after having failed.
   517          	successThreshold: *1 | int
   518  
   519          	// +usage=Number of consecutive failures required to determine the container is not alive (liveness probe) or not ready (readiness probe).
   520          	failureThreshold: *3 | int
   521          }
   522    status:
   523      customStatus: |-
   524        ready: {
   525        	replicas: *0 | int
   526        } & {
   527        	if context.output.status.numberReady != _|_ {
   528        		replicas: context.output.status.numberReady
   529        	}
   530        }
   531        desired: {
   532        	replicas: *0 | int
   533        } & {
   534        	if context.output.status.desiredNumberScheduled != _|_ {
   535        		replicas: context.output.status.desiredNumberScheduled
   536        	}
   537        }
   538        message: "Ready:\(ready.replicas)/\(desired.replicas)"
   539      healthPolicy: |-
   540        ready: {
   541        	replicas: *0 | int
   542        } & {
   543        	if context.output.status.numberReady != _|_ {
   544        		replicas: context.output.status.numberReady
   545        	}
   546        }
   547        desired: {
   548        	replicas: *0 | int
   549        } & {
   550        	if context.output.status.desiredNumberScheduled != _|_ {
   551        		replicas: context.output.status.desiredNumberScheduled
   552        	}
   553        }
   554        current: {
   555        	replicas: *0 | int
   556        } & {
   557        	if context.output.status.currentNumberScheduled != _|_ {
   558        		replicas: context.output.status.currentNumberScheduled
   559        	}
   560        }
   561        updated: {
   562        	replicas: *0 | int
   563        } & {
   564        	if context.output.status.updatedNumberScheduled != _|_ {
   565        		replicas: context.output.status.updatedNumberScheduled
   566        	}
   567        }
   568        generation: {
   569        	metadata: context.output.metadata.generation
   570        	observed: *0 | int
   571        } & {
   572        	if context.output.status.observedGeneration != _|_ {
   573        		observed: context.output.status.observedGeneration
   574        	}
   575        }
   576        isHealth: (desired.replicas == ready.replicas) && (desired.replicas == updated.replicas) && (desired.replicas == current.replicas) && (generation.observed == generation.metadata || generation.observed > generation.metadata)
   577    workload:
   578      definition:
   579        apiVersion: apps/v1
   580        kind: DaemonSet
   581      type: daemonsets.apps
   582