Skip to main content

Ref-objects

TypeComponent

Parameters

Parameter
Type
Required
DefaultDescription
objectsarrayNo

If specified, workload will fetch native Kubernetes objects according to the object description

urlsarrayNo

If specified, the objects in the urls will be loaded.

Template

The following tabs display the definition's Cue template and the rendered YAML. The rendered YAML is the output of the Cue template when the definition is applied to a cluster.

"ref-objects": {
type: "component"
annotations: {}
labels: {
"componentdefinition.spectrocloud.com/type": "application"
"definition.spectrocloud.com/category": "Kubernetes-Resources"
}
description: "Ref-objects allow users to specify ref objects to use. Notice that this component type have special handle logic."
attributes: {
status: {
customStatus: {
if context.output.apiVersion == "apps/v1" && context.output.kind == "Deployment" {
ready: {
readyReplicas: *0 | int
} & {
if context.output.status.readyReplicas != _|_ {
readyReplicas: context.output.status.readyReplicas
}
}
message: "Ready:\(ready.readyReplicas)/\(context.output.spec.replicas)"
}
if context.output.apiVersion != "apps/v1" || context.output.kind != "Deployment" {
message: ""
}
}
healthPolicy: {
if context.output.apiVersion == "apps/v1" && context.output.kind == "Deployment" {
ready: {
updatedReplicas: *0 | int
readyReplicas: *0 | int
replicas: *0 | int
} & {
if context.output.status.updatedReplicas != _|_ {
updatedReplicas: context.output.status.updatedReplicas
}
if context.output.status.readyReplicas != _|_ {
readyReplicas: context.output.status.readyReplicas
}
if context.output.status.replicas != _|_ {
replicas: context.output.status.replicas
}
}
isHealth: (context.output.spec.replicas == ready.readyReplicas) && (context.output.spec.replicas == ready.updatedReplicas) && (context.output.spec.replicas == ready.replicas)
}
if context.output.apiVersion != "apps/v1" || context.output.kind != "Deployment" {
isHealth: true
}
}
}
}
}
template: {
#K8sObject: {
// +usage=The resource type for the Kubernetes objects
resource?: string
// +usage=The group name for the Kubernetes objects
group?: string
// +usage=If specified, fetch the Kubernetes objects with the name, exclusive to labelSelector
name?: string
// +usage=If specified, fetch the Kubernetes objects from the namespace. Otherwise, fetch from the workload's namespace.
namespace?: string
// +usage=If specified, fetch the Kubernetes objects from the cluster. Otherwise, fetch from the local cluster.
cluster?: string
// +usage=If specified, fetch the Kubernetes objects according to the label selector, exclusive to name
labelSelector?: [string]: string
...
}

output: {
if len(parameter.objects) > 0 {
parameter.objects[0]
}
...
}

outputs: {
for i, v in parameter.objects {
if i > 0 {
"objects-\(i)": v
}
}
}
parameter: {
// +usage=If specified, workload will fetch native Kubernetes objects according to the object description
objects?: [...#K8sObject]
// +usage=If specified, the objects in the urls will be loaded.
urls?: [...string]
}
}