Skip to main content

Lookups

Lookup enables you to form components from an external source eg: an HTTP endpoint, kubernetes clusters or a database.

The response from the external sources are then "shaped" to a component using the display field.

The display field contains several scripting mechanism to transform any arbitrary data to a component.

For example this topology will create a root Ingress component with all the ingresses in a kubernetes cluster as its child components.

kubernetes-ingress-classes.yaml
apiVersion: canaries.flanksource.com/v1
kind: Topology
metadata:
name: kubernetes-ingress-classes
namespace: default
spec:
schedule: '@every 30s'
components:
- name: Ingress
type: Ingress
icon: server
lookup:
configDB:
- query: SELECT name FROM config_items WHERE type = 'Kubernetes::IngressClass'
expr: |
dyn(results).map(e, {
'name': e.name,
'type': "Ingress",
}).toJSON()
FieldDescriptionTypeRequired
catalogLookup catalogs in configDB.[]Catalog
execLookup by running (bash/powershell) scripts.[]Exec
kubernetesLookup kubernetes resources[]Kubernetes
httpLookup an HTTP endpoint.[]HTTP
mongodbQuery records from a MongoDB database.[]MongoDB
sqlQuery records from a MSSQL database.[]SQL
redisQuery records from a Redis server.[]Redis
prometheusQuery metrics from Prometheus.[]Prometheus

For Each

The forEach operation allows you to perform operations that you would apply to all the components crafted during the lookup phase.

In the example below, we can add a kubernetes check on each of the ingresses as follows

kubernetes-ingress-classes.yaml
apiVersion: canaries.flanksource.com/v1
kind: Topology
metadata:
name: kubernetes-ingress-classes
namespace: default
spec:
schedule: '@every 30s'
components:
- name: Ingress
type: Ingress
icon: server
lookup:
configDB:
- query: SELECT name FROM config_items WHERE type = 'Kubernetes::IngressClass'
expr: |
dyn(results).map(e, {
'name': e.name,
'type': "Ingress",
}).toJSON()
forEach:
checks:
- inline:
kubernetes:
- kind: Pod
ready: true
resource:
labelSelector: 'app.kubernetes.io/name=ingress-{{.component.name}}&app.kubernetes.io/component=controller'
FieldDescriptionSchemeRequired
componentsCreate sub-components for each component[]Component
propertiesCreate or lookup properties for each component[]Property
configsLink configuration items for each component[]ConfigSelector
checksCreate or link health checks for each component[]CheckSelector
selectorsSelect existing components to be used as the child components.[]ResourceSelector

Templating

All the fields in forEach are templatable. They receive the following context

FieldDescriptionScheme
componentComponent from the lookup[]Component
propertiesThe component's propertiesmap[string]any