Complex filtering with Kubernetes Visibility Agent<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: block; max-width: ; width: auto; height: auto; } } The Kubernetes Visibility Agent pod (a.k.a informer) can be configured to filter in/out resources we would like to bring to the CMDB (Configuration Management Database). Basic filtering, based on multiple AND conditions based on regular expressions is explained in KB1638668. However, there are cases where more complex condition should be applied. As an example, we may want to bring ConfigMaps that match the following condition: (name=paas-info AND namespace=my_namespace) OR (name MATCHES ^(.*myconf1.*|myconf2) From informer version 2.5.x we support that by using an open-source package expr-lang/expr. In order to define complex condition, users will have to define: The set of fields to be included in the condition. Each field had a unique name, extraction JSON path, and optional regexThe condition expression. The expression syntax is defined here The filter is provided within the additionalResources.mappings parameter in the Helm chart or in the mappings part of the ConfigMap in k8s_informer.yaml. Example of mappings.yaml file: v1/configmaps: targetClass: u_cmdb_ci_kubernetes_configmap complexFilter: fields: name: fieldExtractor: jsonPath: ".metadata.name" namespace: fieldExtractor: jsonPath: ".metadata.namespace" expression: (name == 'paas-info' and namespace == 'my_namespace') or (name matches '^(.*myconf1.*|myconf2)') In the Helm command, use the parameter --set-file additionalResources.mappings=mappings.yaml If you are installing using k8s_informer.yaml, you need to provide the same information in JSON format in the data section of the ConfigMap: Example: data: mappings: '{"v1/configmaps":{"targetClass":"u_cmdb_ci_kubernetes_configmap","complexFilter":{"fields":{"name":{"fieldExtractor":{"jsonPath":".metadata.name"}},"namespace":{"fieldExtractor":{"jsonPath":".metadata.namespace"}}},"expression":"(name == 'paas-info' and namespace == 'my_namespace') or (name matches '^(.*myconf1.*|myconf2)'"}}}'