github.com/oam-dev/kubevela@v1.9.11/test/e2e-test/testdata/definition/replica-webservice.yaml (about)

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