Skip to main content

Relationships

Registry

The registry charts include many common relationships for Argo, Flux, etc out of the box.

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.

Relationships come in 2 types:

Hard Links represent a physical relationship, e.g. A pod is always a child of namespace, hard links are created automatically by the relevant scraper or can be created by specifying Parent Type and ID in custom scrapers.

Soft Links represent logical relationships and can have directionality. e.g. Node is related to a pod that runs on it, and a pod is related to an Persistent Volume that is attached the pod. Soft Links are created automatically by some scrapers e.g. Using ownerRef in kubernetes and subnet-id in AWS. Custom soft links can be created using a relationship transform:

In the example below, Kubernetes::Services are linked to Kubernetes::Pod using a soft link based on the service selector name

relate-services-to-pods.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

FieldDescriptionSchemeRequired
filterWhich config items to form relationships withCEL with ScrapeResulttrue
idThe ID or Alias (External ID) of the config to link toLookup
nameLookup
typeConfig TypeLookup
agentagent of the config to link toLookup that returns an Agent
labelsLabels of the config to link tomap[string]Lookup

Lookup

RelationshipLookup offers different ways to specify a lookup value

FieldDescriptionSchemeVariables
exprAn expression that returns a value to be usedCEL with ScrapeResultScrapeResult
valueA static value to use in the lookupstring
labelGet the value to use from an existing labellabel name

Dynamic Linking

Sometimes the logic for when to a form a relationship is complex, a CEL expression can be used to return a list of selectors dynamically.

FieldDescriptionSchemeVariables
exprAn expression that returns a list of ResourceSelectorsCELScrapeResult
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()