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.yamlapiVersion: 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()
| Field | Description | Type | Required | 
|---|---|---|---|
| catalog | Lookup catalogs in configDB. | []Catalog | |
| exec | Lookup by running (bash/powershell) scripts. | []Exec | |
| kubernetes | Lookup kubernetes resources | []Kubernetes | |
| http | Lookup an HTTP endpoint. | []HTTP | |
| mongodb | Query records from a MongoDB database. | []MongoDB | |
| sql | Query records from a MSSQL database. | []SQL | |
| redis | Query records from a Redis server. | []Redis | |
| prometheus | Query 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.yamlapiVersion: 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'
| Field | Description | Scheme | Required | 
|---|---|---|---|
| components | Create sub-components for each component | []Component | |
| properties | Create or lookup properties for each component | []Property | |
| configs | Link configuration items for each component | []ConfigSelector | |
| checks | Create or link health checks for each component | []CheckSelector | |
| selectors | Select existing components to be used as the child components. | []ResourceSelector | 
Templating
All the fields in forEach are templatable. They receive the following context
| Field | Description | Scheme | 
|---|---|---|
| component | Component from the lookup | []Component | 
| properties | The component's properties | map[string]any |