CEL Examples¶
Practical examples for common Hydra CEL use cases.
CLI Filtering¶
Show only Deployments that are out of sync¶
Exclude Events and PodMetrics from diff¶
Only show resources in a specific namespace¶
Find all Secrets across apps¶
Ref-Parser Predicates¶
Match all Deployments¶
Match resources with specific annotations¶
has(entity.metadata.annotations) && has(entity.metadata.annotations["app.kubernetes.io/managed-by"])
Match resources with ownerReferences¶
Match CRDs of a specific group¶
Ref-Parser Pick Rules¶
Simple namespace dependency¶
Extract all ownerReferences as refs¶
entity.metadata.ownerReferences.map(o,
refBuilder().outgoing(id(o.apiVersion + "/" + o.kind, ns, o.name))
.label("owner")
)
Conditional extraction (return empty list if field missing)¶
has(entity.spec.secretName) ?
[refBuilder().outgoing(id("v1/Secret", ns, entity.spec.secretName)).label("secret")] :
[]
Extract from a list field¶
has(entity.spec.volumes) ?
entity.spec.volumes.filter(v, has(v.configMap)).map(v,
refBuilder().outgoing(id("v1/ConfigMap", ns, v.configMap.name))
.label("volume-configmap")
) : []
Associate Events with their involved objects¶
clusterEntities({"namespace": ns, "gvk": "events.k8s.io/v1/Event"}).filter(e,
e.name.startsWith(name)
).map(e,
refBuilder().outgoing(id("events.k8s.io/v1/Event", ns, e.name))
.label("workloadRegardingEvent")
)
Preset CEL Patterns¶
Match by name pattern¶
Match DaemonSet pods¶
Match PodMetrics (optional)¶
Value Predicates¶
TemplatePatch: Add annotation to all Applications¶
Diff ignore: Skip all Events¶
Clone predicate: Select specific Secret¶
Ready probe: Check Deployment availability¶
kind == "Deployment" && has(entity.status.availableReplicas) && entity.status.availableReplicas >= entity.spec.replicas
Tips¶
- Always use
has()before accessing optional fields - Return
[](empty list) from pick rules when there's nothing to extract - Use ternary
condition ? value_if_true : value_if_falsefor conditional logic - Chain
.filter().map()for extracting refs from collections - String methods:
.startsWith(),.matches(),.contains()