Join us Dec. 16 for The Community Hour, our first global virtual User Group event!
Release: Any Version / Not Version-Specific
Paulo Ferreira
ServiceNow Employee

Introduction

ServiceNow provides an official KB article on extending the Kubernetes Visibility Agent (KVA, formerly CNO for Visibility): KB1638668 – Kubernetes Visibility Agent extensibility and customization. It explains the additionalResources mechanism (resources and mappings), field extraction, filtering, custom relations, and pre/post-sensor scripts.

The KB is the authoritative reference. This post adds two hands-on, end-to-end examples, along with the issues I ran into and how I solved them:

  1. Enriching an out-of-the-box class: populating a custom URL field on cmdb_ci_kubernetes_ingress with the Ingress host.
  2. Collecting a resource that isn’t collected by default: bringing PersistentVolumeClaims (PVCs) into cmdb_ci_kubernetes_volume.

Environment: Informer 2.6.3, deployed through the Helm chart and managed by Argo CD (GitOps), on OpenShift clusters.


Example 1: Collecting the Ingress host into a custom field

Ingress is already collected by default into cmdb_ci_kubernetes_ingress, so this case is simpler. You only need a mappings entry. You don’t need a resources entry or new RBAC permissions.

Prerequisite: a custom field on cmdb_ci_kubernetes_ingress (in this example, u_url).

values.yaml

 
additionalResources:
  resources: ""
  mappings: |
    networking.k8s.io/v1/ingresses:
      fields:
      - fieldExtractor:
          jsonPath: ".spec.rules[:].host"
        name: url
        targetColumn: "u_url"

Key lessons

mappings and resources must be strings, not YAML structures. My first attempt defined them as nested YAML objects. The ConfigMap was never mounted, and the Informer log showed:

 
Failed to read file from /etc/additionalResources/mappings.json: no such file or directory

Using a block scalar (mappings: |) fixed it. The chart writes the string into a ConfigMap and mounts it at /etc/additionalResources/.

Use [:] for arrays. The KB examples use [:] (for example, .spec.rules[:].host), not the more common [*] JSONPath syntax. Stick to the KB’s notation.

Start with a filter. For the first test, I limited the mapping to a single Ingress and then removed the filter after validating:

 
      filter:
      - jsonPath: ".metadata.name"
        regex: "^<ingress-name>$"

Note: Some Ingresses, such as certain gRPC ones, may have no host in spec.rules. In those cases an empty field is expected behavior, not a mapping failure.

Result

After a Full Discovery, the Ingress CI showed the host in the custom field, and the out-of-the-box fields stayed intact:

  • Name: <ingress-name>
  • Kubernetes Cluster: <cluster-name>
  • Namespace: <namespace>
  • URL (u_url) : <app>.<your-domain>

Alternative: configure from the instance

You can also provide mappings (but not resources) from the instance. Add the Informer parameter Additional Resources ConfigMap with JSON wrapped in a mappings key:

 
{
  "mappings": {
    "networking.k8s.io/v1/ingresses": {
      "fields": [
        {
          "fieldExtractor": { "jsonPath": ".spec.rules[:].host" },
          "name": "url",
          "targetColumn": "u_url"
        }
      ]
    }
  }
}

Then run Sync Parameters to informer, Restart Informer, and Full Discovery. This route is handy for a quick test on a single cluster. For a large fleet, GitOps with values.yaml scales much better.


Example 2: Collecting PersistentVolumeClaims

PVCs aren’t collected by default, so this case needs more setup: a resources entry, RBAC permissions, and CMDB identification adjustments.

Step 1: values.yaml

 
additionalResources:
  resources: |
    - apiGroups:
      - ""
      apiVersions:
      - v1
      resources:
      - persistentvolumeclaims
  mappings: |
    v1/persistentvolumeclaims:
      targetClass: "cmdb_ci_kubernetes_volume"
      fields:
      - fieldExtractor:
          jsonPath: ".spec.volumeName"
        name: volume_id
        targetColumn: "volume_id"
      - fieldExtractor:
          jsonPath: ".spec.storageClassName"
        name: storage_class
        targetColumn: "category"
      - fieldExtractor:
          jsonPath: ".status.phase"
        name: phase
        targetColumn: "state"
      - fieldExtractor:
          jsonPath: ".status.capacity.storage"
        name: capacity
      - fieldExtractor:
          jsonPath: ".status.accessModes[:]"
        name: access_mode
      - fieldExtractor:
          jsonPath: ".spec.volumeMode"
        name: volume_mode

Notes on this mapping:

  • Name, Namespace, and Kubernetes UID are collected by default, so you don’t need to map them.
  • Fields without a targetColumn are stored as key/value pairs in the attributes JSON field. Don’t point multiple fields at targetColumn: "attributes", because that can make them collide.
  • mount_path can’t be extracted from a PVC. The mount path is defined in the Pod (spec.containers[].volumeMounts[].mountPath), not in the claim.

Step 2: RBAC

After the first sync, no volumes were created. The Informer log showed the cause:

 
Authorization failure on v1 persistentvolumeclaims
Informer not found for resource: v1/persistentvolumeclaims

The KB says the chart adds list/get/watch for declared resources when you use the ClusterRole the chart provides. If your environment uses a custom ClusterRole, you must add the permission yourself:

 
- apiGroups: [""]
  resources: ["persistentvolumeclaims"]
  verbs: ["get", "list", "watch"]

After updating the ClusterRole and restarting the Informer, the log showed the PVCs being listed and queued:

 
Listing resource:  v1/persistentvolumeclaims
Queueing 50 items, payload size: ...
v1/persistentvolumeclaims  listed: <count>

Step 3: Identification rule

The default identification rule for cmdb_ci_kubernetes_volume relies on mount_path, which a PVC doesn’t have. I changed the identifier entry to Name + Volume ID. Consider the trade-offs for your environment:

  • volumeName is empty while a PVC is Pending.
  • Kubernetes UID is another strong option, because it’s always present and unique.

Step 4: Dependent relationship (MISSING_DEPENDENCY)

Even with a valid payload, the IRE rejected the inserts:

 
"error":"MISSING_DEPENDENCY","message":"In payload no relations defined for dependent class
[cmdb_ci_kubernetes_volume] that matches any containment/hosting rules:
[cmdb_ci_kubernetes_pod <- Contains <- cmdb_ci_kubernetes_volume]"

cmdb_ci_kubernetes_volume is a dependent class with a default containment rule (Kubernetes Pod Contains Kubernetes Volume). A PVC payload doesn’t carry a relation to a Pod, so the IRE can’t satisfy that rule.

Instead of removing the default rule, I added a second containment rule:

  1. Open CI Class Manager, select Kubernetes Volume, and go to Dependent Relationships.
  2. Click Add dependency and set:
    • Rule Type: Containment
    • Relationship: Contained by (Contains::Contained by)
    • Target Class: Kubernetes Namespace
  3. Save.

The Informer already creates a relation from every namespaced resource to its Namespace CI, so this rule can be satisfied by the PVC payload.

After adding the Namespace containment rule and running a new Full Discovery, the MISSING_DEPENDENCY errors stopped and the PVCs were created in cmdb_ci_kubernetes_volume. The default Pod containment rule did not need to be removed: the two containment rules work as alternatives, and either one satisfies the IRE.

An alternative is to build Pod-to-PVC relations with the Custom Relations feature from the KB. That approach is more complex, and it won’t cover PVCs that aren’t mounted by any Pod.

Result

A resulting Kubernetes Volume CI looks like this:

  • Name: <pvc-name>
  • Kubernetes Cluster: <cluster-name>
  • Namespace: <namespace>
  • Volume ID: pvc-<uid>
  • Category: <storage-class>
  • State: Bound
  • Attributes: {"capacity":"2Gi","access_mode":"ReadWriteOnce","volume_mode":"Filesystem"}

The exact serialization of the attributes field may vary slightly depending on the value type (for example, an array like accessModes).


Troubleshooting checklist

Is the mapping file mounted?

 
kubectl exec -n <informer-namespace> <informer-pod> -- ls -la /etc/additionalResources/

If you see “no such file or directory,” check how the values are delivered (string vs. structure) and whether your Argo/Helm sync applied them.

Was the mapping loaded? Check the Informer log for Additional resource <resource> exists in the cluster.

Is it an RBAC issue? Search the Informer log for Authorization failure on <resource>.

Are records being rejected by the IRE? On the instance, check the system logs for IRE errors such as MISSING_DEPENDENCY. This points to the class’s identification rule or dependent relationships.

Did discovery run after the change? Trigger a Full Discovery after every mapping, RBAC, or identification change.


Takeaways

  • Enriching a class that’s already collected (like Ingress) needs only mappings.
  • Collecting a new resource (like PVC) needs resources, mappings, RBAC, and an identification model that fits the data the resource actually has.
  • When a target class is dependent, check its dependent relationships. You can add an alternative containment rule without removing the default one (best practices).
  • Read the Informer log before changing the mapping. It tells you exactly where the pipeline stopped.
  • Validate on one cluster with filters first, then remove the filters and roll out through GitOps.

I hope this complements KB1638668 with some practical guidance. Feedback and other examples are welcome in the comments.

References:

  • KB1638668: Kubernetes Visibility Agent (formerly CNO for Visibility) extensibility and customization
  • KB1648272: API for retrieving information on a Kubernetes resource on-demand
Version history
Last update:
25m ago
Updated by:
Contributors