Skip to main content

Relationships

Relationships associate two different configs. They help in visualizing the connection of a config above and below in a hierarchy. Example: A kubernetes pod is linked to a Deployment and ReplicaSet and also to the persistent volumes.

Kubernetes Relationship

kubernetes-scraper.yaml
apiVersion: configs.flanksource.com/v1
kind: ScrapeConfig
metadata:
name: kubernetes-scraper
spec:
kubernetes:
- clusterName: local-kind-cluster
transform:
relationship:
# Link a service to a deployment
- filter: config_type == "Kubernetes::Service"
type:
value: 'Kubernetes::Deployment'
name:
expr: |
has(config.spec.selector) && has(config.spec.selector.name) ? config.spec.selector.name : ''
Directionality matters

When creating relationships ensure that you specify the relationship on the parent and not on the child, as this can effect the change graph, e.g. If you link a pod to a namespace, when you view changes on the pod by default it will show all changes to all resources in the namespace. When a namespace is linked to a pod, no changes at the namespace level will be shown when using Outgoing (the default) option.

You can see changes on the incoming relationships (and their parents) by choosing the Incoming option.

Relationship Config

This transformation function allows you to dynamically form relationships between two different config items using selectors.

Example: You can link a kubernetes deployment with the corresponding pods, or you can link AWS EC2 instances with the AWS Account. It's even possible to link two configs scraped by different scrape configs like: linking a Kubernetes Node in an EKS cluster to the EC2 instance.

FieldDescriptionSchemeRequired
filterSpecify the config item with which relationship should be formedstringtrue
exprcel-expression that returns a list of relationship selector.Dynamic Linking
idid of the config to link toRelationshipLookup
namename of the config to link toRelationshipLookup
typetype of the config to link toRelationshipLookup
agentagent of the config to link toRelationshipLookup
labelsLabels of the config to link toRelationshipLookup
info

expr is an alternative, more flexible, way to define the selectors. Either use expr or the other selector fields (id, name, type, agent, labels) but not both.

Relationship Lookup

RelationshipLookup offers different ways to specify a lookup value

FieldDescriptionSchemeVariables
exprAn expression that returns a value to be usedCELScrapeResult
valueSpecify a static valuestring
labelUse the value from an existing labelstring

Dynamic Linking

Expressions can be used to define the linking criteria by return a list of resource selectors.

link-pvc-to-pod.yaml
apiVersion: configs.flanksource.com/v1
kind: ScrapeConfig
metadata:
name: kubernetes-scraper
spec:
kubernetes:
- clusterName: local-kind-cluster
transform:
relationship:
- filter: config_type == 'Kubernetes::Pod'
expr: |
config.spec.volumes.
filter(item, has(item.persistentVolumeClaim)).
map(item, {
"type": "Kubernetes::PersistentVolumeClaim",
"name": item.persistentVolumeClaim.claimName
}).
toJSON()
FieldDescriptionSchemeVariables
exprAn expression that returns a list of ResourceSelectorsCELScrapeResult