github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/component/ref-objects.cue (about)

     1  "ref-objects": {
     2  	type: "component"
     3  	annotations: {}
     4  	labels: {
     5  		"ui-hidden": "true"
     6  	}
     7  	description: "Ref-objects allow users to specify ref objects to use. Notice that this component type have special handle logic."
     8  	attributes: {
     9  		workload: type: "autodetects.core.oam.dev"
    10  		status: {
    11  			customStatus: #"""
    12  				if context.output.apiVersion == "apps/v1" && context.output.kind == "Deployment" {
    13  					ready: {
    14  						readyReplicas: *0 | int
    15  					} & {
    16  						if context.output.status.readyReplicas != _|_ {
    17  							readyReplicas: context.output.status.readyReplicas
    18  						}
    19  					}
    20  					message: "Ready:\(ready.readyReplicas)/\(context.output.spec.replicas)"
    21  				}
    22  				if context.output.apiVersion != "apps/v1" || context.output.kind != "Deployment" {
    23  					message: ""
    24  				}
    25  				"""#
    26  			healthPolicy: #"""
    27  				if context.output.apiVersion == "apps/v1" && context.output.kind == "Deployment" {
    28  					ready: {
    29  						updatedReplicas:    *0 | int
    30  						readyReplicas:      *0 | int
    31  						replicas:           *0 | int
    32  						observedGeneration: *0 | int
    33  					} & {
    34  						if context.output.status.updatedReplicas != _|_ {
    35  							updatedReplicas: context.output.status.updatedReplicas
    36  						}
    37  						if context.output.status.readyReplicas != _|_ {
    38  							readyReplicas: context.output.status.readyReplicas
    39  						}
    40  						if context.output.status.replicas != _|_ {
    41  							replicas: context.output.status.replicas
    42  						}
    43  						if context.output.status.observedGeneration != _|_ {
    44  							observedGeneration: context.output.status.observedGeneration
    45  						}
    46  					}
    47  					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)
    48  				}
    49  				if context.output.apiVersion != "apps/v1" || context.output.kind != "Deployment" {
    50  					isHealth: true
    51  				}
    52  				"""#
    53  		}
    54  	}
    55  }
    56  template: {
    57  	#K8sObject: {
    58  		// +usage=The resource type for the Kubernetes objects
    59  		resource?: string
    60  		// +usage=The group name for the Kubernetes objects
    61  		group?: string
    62  		// +usage=If specified, fetch the Kubernetes objects with the name, exclusive to labelSelector
    63  		name?: string
    64  		// +usage=If specified, fetch the Kubernetes objects from the namespace. Otherwise, fetch from the application's namespace.
    65  		namespace?: string
    66  		// +usage=If specified, fetch the Kubernetes objects from the cluster. Otherwise, fetch from the local cluster.
    67  		cluster?: string
    68  		// +usage=If specified, fetch the Kubernetes objects according to the label selector, exclusive to name
    69  		labelSelector?: [string]: string
    70  		...
    71  	}
    72  
    73  	output: {
    74  		if len(parameter.objects) > 0 {
    75  			parameter.objects[0]
    76  		}
    77  		...
    78  	}
    79  
    80  	outputs: {
    81  		for i, v in parameter.objects {
    82  			if i > 0 {
    83  				"objects-\(i)": v
    84  			}
    85  		}
    86  	}
    87  	parameter: {
    88  		// +usage=If specified, application will fetch native Kubernetes objects according to the object description
    89  		objects?: [...#K8sObject]
    90  		// +usage=If specified, the objects in the urls will be loaded.
    91  		urls?: [...string]
    92  	}
    93  }