github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/trait/startup-probe.cue (about) 1 "startup-probe": { 2 type: "trait" 3 annotations: {} 4 description: "Add startup probe hooks for the specified container of K8s pod for your workload which follows the pod spec in path 'spec.template'." 5 attributes: { 6 podDisruptive: true 7 appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps", "jobs.batch"] 8 } 9 } 10 template: { 11 #StartupProbeParams: { 12 // +usage=Specify the name of the target container, if not set, use the component name 13 containerName: *"" | string 14 // +usage=Number of seconds after the container has started before liveness probes are initiated. Minimum value is 0. 15 initialDelaySeconds: *0 | int 16 // +usage=How often, in seconds, to execute the probe. Minimum value is 1. 17 periodSeconds: *10 | int 18 // +usage=Number of seconds after which the probe times out. Minimum value is 1. 19 timeoutSeconds: *1 | int 20 // +usage=Minimum consecutive successes for the probe to be considered successful after having failed. Minimum value is 1. 21 successThreshold: *1 | int 22 // +usage=Minimum consecutive failures for the probe to be considered failed after having succeeded. Minimum value is 1. 23 failureThreshold: *3 | int 24 // +usage=Optional duration in seconds the pod needs to terminate gracefully upon probe failure. Set this value longer than the expected cleanup time for your process. 25 terminationGracePeriodSeconds?: int 26 // +usage=Instructions for assessing container startup status by executing a command. Either this attribute or the httpGet attribute or the grpc attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with the httpGet attribute and the tcpSocket attribute and the gRPC attribute. 27 exec?: { 28 // +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. 29 command: [...string] 30 } 31 // +usage=Instructions for assessing container startup status by executing an HTTP GET request. Either this attribute or the exec attribute or the grpc attribute or the tcpSocket attribute MUST be specified. This attribute is mutually exclusive with the exec attribute and the tcpSocket attribute and the gRPC attribute. 32 httpGet?: { 33 // +usage=The endpoint, relative to the port, to which the HTTP GET request should be directed. 34 path?: string 35 // +usage=The port numer to access on the host or container. 36 port: int 37 // +usage=The hostname to connect to, defaults to the pod IP. You probably want to set "Host" in httpHeaders instead. 38 host?: string 39 // +usage=The Scheme to use for connecting to the host. 40 scheme?: *"HTTP" | "HTTPS" 41 // +usage=Custom headers to set in the request. HTTP allows repeated headers. 42 httpHeaders?: [...{ 43 // +usage=The header field name 44 name: string 45 //+usage=The header field value 46 value: string 47 }] 48 } 49 // +usage=Instructions for assessing container startup status by probing a gRPC service. Either this attribute or the exec attribute or the grpc attribute or the httpGet attribute MUST be specified. This attribute is mutually exclusive with the exec attribute and the httpGet attribute and the tcpSocket attribute. 50 grpc?: { 51 // +usage=The port number of the gRPC service. 52 port: int 53 // +usage=The name of the service to place in the gRPC HealthCheckRequest 54 service?: string 55 } 56 // +usage=Instructions for assessing container startup status by probing a TCP socket. Either this attribute or the exec attribute or the tcpSocket attribute or the httpGet attribute MUST be specified. This attribute is mutually exclusive with the exec attribute and the httpGet attribute and the gRPC attribute. 57 tcpSocket?: { 58 // +usage=Number or name of the port to access on the container. 59 port: int 60 // +usage=Host name to connect to, defaults to the pod IP. 61 host?: string 62 } 63 } 64 PatchContainer: { 65 _params: #StartupProbeParams 66 name: _params.containerName 67 _baseContainers: context.output.spec.template.spec.containers 68 _matchContainers_: [ for _container_ in _baseContainers if _container_.name == name {_container_}] 69 if len(_matchContainers_) == 0 { 70 err: "container \(name) not found" 71 } 72 if len(_matchContainers_) > 0 { 73 startupProbe: { 74 if _params.exec != _|_ { 75 exec: _params.exec 76 } 77 if _params.httpGet != _|_ { 78 httpGet: _params.httpGet 79 } 80 if _params.grpc != _|_ { 81 grpc: _params.grpc 82 } 83 if _params.tcpSocket != _|_ { 84 tcpSocket: _params.tcpSocket 85 } 86 if _params.initialDelaySeconds != _|_ { 87 initialDelaySeconds: _params.initialDelaySeconds 88 } 89 if _params.periodSeconds != _|_ { 90 periodSeconds: _params.periodSeconds 91 } 92 if _params.tcpSocket != _|_ { 93 tcpSocket: _params.tcpSocket 94 } 95 if _params.timeoutSeconds != _|_ { 96 timeoutSeconds: _params.timeoutSeconds 97 } 98 if _params.successThreshold != _|_ { 99 successThreshold: _params.successThreshold 100 } 101 if _params.failureThreshold != _|_ { 102 failureThreshold: _params.failureThreshold 103 } 104 if _params.terminationGracePeriodSeconds != _|_ { 105 terminationGracePeriodSeconds: _params.terminationGracePeriodSeconds 106 } 107 } 108 } 109 } 110 111 patch: spec: template: spec: { 112 if parameter.probes == _|_ { 113 // +patchKey=name 114 containers: [{ 115 PatchContainer & {_params: { 116 if parameter.containerName == "" { 117 containerName: context.name 118 } 119 if parameter.containerName != "" { 120 containerName: parameter.containerName 121 } 122 periodSeconds: parameter.periodSeconds 123 initialDelaySeconds: parameter.initialDelaySeconds 124 timeoutSeconds: parameter.timeoutSeconds 125 successThreshold: parameter.successThreshold 126 failureThreshold: parameter.failureThreshold 127 terminationGracePeriodSeconds: parameter.terminationGracePeriodSeconds 128 if parameter.exec != _|_ { 129 exec: parameter.exec 130 } 131 if parameter.httpGet != _|_ { 132 httpGet: parameter.httpGet 133 } 134 if parameter.grpc != _|_ { 135 grpc: parameter.grpc 136 } 137 if parameter.tcpSocket != _|_ { 138 tcpSocket: parameter.tcpSocket 139 } 140 }} 141 }] 142 } 143 if parameter.probes != _|_ { 144 // +patchKey=name 145 containers: [ for c in parameter.probes { 146 if c.name == "" { 147 err: "containerName must be set when specifying startup probe for multiple containers" 148 } 149 if c.name != "" { 150 PatchContainer & {_params: c} 151 } 152 }] 153 } 154 } 155 156 parameter: *#StartupProbeParams | close({ 157 // +usage=Specify the startup probe for multiple containers 158 probes: [...#StartupProbeParams] 159 }) 160 161 errs: [ for c in patch.spec.template.spec.containers if c.err != _|_ {c.err}] 162 163 }