Custom Code Filters

Items can be filtered using arbitrary code following JavaScript syntax. The example below selects Deployments that have dnsPolicy set to ClusterFirst. The filter should return true or false to indicate whether the item should be included. Multiple filters can be used, and for the item to be passed along to the rule script, all the filter functions should return true. The item.config would represent the actual YAML file provided by Kubernetes.

select('Launcher') .name('Deployment') .filter({item} => { if (item.config.spec.template.dnsPolicy == 'ClusterFirst') { return true; } return false; })

Filters can also access synthetic properties. The target script below selects applications exposed to the public internet and running less than three pod replicas.

select('Application') .filter({item} => { return (item.props['Replicas'] < 3) && (item.props['Exposed'] == 'With Ingress'); })

The same result can be achieved by fetching replicas from the config object, and checking whether there is an Ingress item underneath.

select('Application') .filter({item} => { return (item.config.spec.replicas < 3) && item.hasDescendants('Ingress'); })
Share this article on:
message