npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nullplatform/collector-kubernetes

v0.6.1

Published

Feeds the catalog with the resources of a Kubernetes cluster: a backfill, then every change as it happens, and a daily resync.

Readme

Kubernetes collector

A nullplatform collector that keeps the catalog in sync with a Kubernetes cluster through catalog-ingest-api. Built with defineCollector from @nullplatform/plugin/collector. It ships as an image (its command line, Run) and as a library, @nullplatform/collector-kubernetes, that an application runs in its own process (Library).

  • Backfill: on start, and then once a day as a resync (NP_COLLECTOR_INTERVAL_SECONDS), it lists every configured resource cluster-wide (paginated) and sends the whole picture as one run. Between them the watch sends every change as it happens; the resync catches the deletes a watch misses while it is down. When the run finishes, entities of this cluster that no longer exist are deleted from the catalog, behind the source's guards (an empty listing, or one that would delete half the cluster or more, deletes nothing). If any resource cannot be listed, the run is aborted and nothing is deleted.
  • Watch: list-then-watch per resource. Every add, change and delete is sent as an event the moment it happens, stamped with when it was seen; the newest observation of an entity wins whatever order events arrive in. A dropped watch resumes where it was; one whose resourceVersion expired (410) lists again and sends exactly what changed meanwhile, deletions included. Only what changed is sent: an object whose payload is the one last sent (ignoring resourceVersion, condition heartbeats, and the count and last_at of its _events) is not sent again, and each object's latest change waits K8S_WATCH_WINDOW_SECONDS to go out once.

Objects are sent raw, minus metadata.managedFields, the kubectl.kubernetes.io/last-applied-configuration annotation and config map values (keys are kept, values become empty), plus two reserved keys: _refs, the object's references by name resolved to uids (see Relations), and _events, its current Kubernetes events (see Events). The mappings decide what reaches the catalog: they are the kubernetes source type's mappings, nullplatform's, evaluated by catalog-ingest-api and shared by every cluster. This package defines them, with the type and the catalog specifications (Definitions). Secrets are never read.

What reaches the catalog

One catalog specification per resource (src/specs/), one entity per object: an organization binds each of the type's mappings to the catalog target and the specification of its kind (k8s-<kind>) once, for every cluster, and the collector sends the record types bound for its source (the others it skips, and it fails when none is bound). The external id is the object's metadata.uid: a deleted and recreated object (same name) is a new entity, and many clusters can feed the same specifications. Every entity also has a key, <source slug>/<namespace>/<name> (<source slug>/<name> for namespaces and nodes), indexed for filter, sort and full text: find an entity by name with GET /instances/k8s-pod?key=<key>; its cluster is the source slug. Run one collector per cluster with its own source slug; two sources on one cluster would write the same entities.

| Record type | Specification | Highlights | | --- | --- | --- | | namespace | k8s-namespace | phase, labels | | node | k8s-node | roles, ready, kubelet/runtime/OS versions, architecture, capacity, allocatable, taints | | deployment | k8s-deployment | replicas (desired/ready/available/updated), available, strategy, images, containers | | replicaset | k8s-replicaset | replicas (desired/current/ready/available), revision, owning deployment, images | | statefulset | k8s-statefulset | replicas, service name, volume claim templates, images | | daemonset | k8s-daemonset | scheduled/ready/available counts, node selector, images | | job | k8s-job | state (complete/failed/active/pending), succeeded/failed/active, owning cron job | | cronjob | k8s-cronjob | schedule, suspended, last schedule/success, active jobs | | pod | k8s-pod | phase, ready, node, workload (its Deployment through the ReplicaSet), restarts, container states | | service | k8s-service | type, cluster IP, ports, load balancer, selector | | ingress | k8s-ingress | class, hosts, TLS hosts, rules (path → service:port), load balancer | | configmap | k8s-configmap | keys only (values never leave the cluster) | | persistentvolumeclaim | k8s-persistentvolumeclaim | phase, storage class, requested and bound capacity | | event | k8s-event | type, reason, message, count, first and last time, source, the object it is about (see Events) |

Every entity also carries key, name, cluster, labels, annotations and creation_timestamp (and namespace when namespaced), and every object event_count and warning_count (see Events). Optional properties are nullable, so a field that disappears in the cluster is cleared in the catalog.

Health

Every kind with a state (all but config maps and events) carries health, one of healthy, progressing, degraded, failing, unknown, and health_reason, a short token (null when healthy), both indexed for filter and facet: a board's top row is one facet per kind, and a tile drills into ?health=failing. The mapping normalizes it from the object's OWN status and conditions now, as Kubernetes states them (a pod's phase, readiness and container waiting reasons; a node's Ready and pressure conditions; a Deployment's Progressing and Available conditions and replica counts; a Job's Failed and Complete conditions; a claim's phase; an ingress's reconcile_status...): no threshold, no time math, nothing from another object. Each specification's health description says the rule for its kind. Beside it, what a Lens-like view lists: a pod's waiting_reason and its containers' requests and limits summed (cpu_request_m, cpu_limit_m, memory_request_bytes, memory_limit_bytes; init containers excluded); a node's conditions, memory_pressure, disk_pressure, pid_pressure, network_unavailable, and its capacity and allocatable as numbers (cpu_*_m, memory_*_bytes, pods_*); and the counters a board filters on (replicas, ready and available replicas, scheduled and ready pods, succeeded, failed and active, restarts, suspend, paused, the event's count, every creation_timestamp) indexed. Queries:

GET /instances/k8s-pod?health=failing                        pods crash-looping, failing to pull, evicted...
GET /instances/k8s-deployment?health:ne=healthy              deployments rolling out, short of replicas or stuck
GET /instances/k8s-node?memory_pressure=true                 nodes under memory pressure
GET /instances/k8s-pod?node_id=<node uid>                    one node's pods (sum their requests against its allocatable)
GET /facets/k8s-pod?field=waiting_reason                     how many pods wait, and why

Relations

| Specification | Relation | Type | Alias | Target | From | | --- | --- | --- | --- | --- | --- | | every namespaced one | ns | belongs_to | namespace_id | k8s-namespace | metadata.namespace | | k8s-pod | on_node | belongs_to | node_id | k8s-node | spec.nodeName | | k8s-pod | replicaset | belongs_to | replicaset_id | k8s-replicaset | controller owner reference | | k8s-pod | statefulset | belongs_to | statefulset_id | k8s-statefulset | controller owner reference | | k8s-pod | daemonset | belongs_to | daemonset_id | k8s-daemonset | controller owner reference | | k8s-pod | job | belongs_to | job_id | k8s-job | controller owner reference | | k8s-pod | configmaps | many_to_many | configmap_ids | k8s-configmap | volumes, projected volumes, envFrom and env of containers, init and ephemeral containers | | k8s-pod | pvcs | many_to_many | persistentvolumeclaim_ids | k8s-persistentvolumeclaim | persistentVolumeClaim.claimName, generic ephemeral volumes | | k8s-replicaset | deployment | belongs_to | deployment_id | k8s-deployment | controller owner reference | | k8s-job | owner_cronjob | belongs_to | cronjob_id | k8s-cronjob | controller owner reference | | k8s-service | pods | many_to_many | pod_ids | k8s-pod | label selector, same namespace (none when empty) | | k8s-ingress | services | many_to_many | service_ids | k8s-service | rule backends and the default backend |

All relations are non-strict and always sent: a belongs_to is the target's uid or null, a many_to_many the full list of target uids ([]: none).

Owner references carry uids; everything else references by name (or label selector), so the collector resolves names to uids itself against an index of the cluster and sends them under _refs:

  • the backfill lists every resource first, then sends each object with its references resolved against the whole listing;
  • the watch keeps one index for all its watchers. Its first listing of every resource is sent once all are listed. After that, when a referenced object appears, is recreated (new uid) or is deleted, the objects that reference it by name are sent again, observed now; a service is sent again when the set of pods it selects changes (pods added, deleted, relabelled). A pod seen before its config map gets linked when the config map shows up.

Adopt the type once per organization: apply the package's definitions (Definitions), then bind the type's mappings to the specifications (one call, every record type, every cluster):

CATALOG_API_URL=https://... INGEST_API_URL=https://... NP_API_KEY=... mise run definitions:apply
# POST /catalog/ingest/destinations { "data": [ { "mapping_id": "<the type's pod mapping>",
#   "target": "catalog", "endpoint": "k8s-pod" }, ... ] }
# (GET /catalog/ingest/source_types?slug=kubernetes, then GET …/source_types/{id}/mappings for the ids)

Events

The catalog is the cluster now: if broken it says broken, if fixed it says fixed. An object's state fields say what the object says now, with nothing kept from the past; its events are the cluster's own recent record (Kubernetes keeps an Event about an hour after what it describes). Kubernetes reports the failures that matter only as Warning events (Unhealthy, FailedScheduling, FailedMount, BackOff, FailedToRetrieveImagePullSecret, the AWS Load Balancer Controller's FailedBuildModel / FailedDeployModel on every Ingress of a blocked group). A controller may say something is fixed only with a Normal event (that controller's SuccessfullyReconciled on an Ingress). So every object goes with _events, its current events, as the collector knows them:

_events: [
  { type: "Warning" | "Normal", reason, message, count, first_at, last_at, source }, …
]
  • The events of the types configured about a collected object (K8S_EVENT_TYPES, config.events.types: Warning, Normal or both; Warning by default), each type read with its own server-side filtered list and watch (type=<type>). With Normal, K8S_EVENT_NORMAL_REASONS (config.events.normalReasons) narrows the Normal events to those reasons, a list and watch each (type=Normal,reason=<reason>) in place of type=Normal; unset, every Normal event is read. Reasons without Normal among the types are a configuration error at startup. The collector knows no controller: an application that knows its cluster runs the AWS Load Balancer Controller reads Warning,Normal narrowed to SuccessfullyReconciled, its "fixed".
  • One entry per Event object (Kubernetes counts repeats into one Event: count, last_at), newest last_at first, then reason. first_at is the Event's firstTimestamp (or eventTime), last_at its lastTimestamp (or its series' last observation, or eventTime), count its count (or its series'), source the reporting component.
  • Current means the Event exists: Kubernetes expires events (an hour by default), and an expired one leaves _events. A component that keeps failing keeps its Event alive.
  • An event attaches to the object of its uid only (a recreated pod does not inherit the old one's warnings); a node's, which the kubelet names by the node's name in place of its uid, by either. Events about kinds not collected (or in an excluded namespace, by the object's namespace) are dropped as they are read.
  • [] when there is none, or with K8S_EVENTS=false; a delete carries neither _refs nor _events.
  • The watch re-sends an object when an event about it appears, expires or changes its message, or when a Normal one becomes newer than every Warning of its source (a SuccessfullyReconciled: how an Ingress says it is fixed). One Warning firing again (its count and last_at move, nothing else) does not, nor do two swapping places as each fires (a liveness and a readiness probe), so a probe failing every 10 s is not a write every 10 s: what is compared leaves out count and last_at and takes no time order among the Warnings, while the payload keeps _events newest first. The backfill lists the events before it sends, so a snapshot carries them too.

Each event read is also a record of type event, an entity of k8s-event (one per Event object): the sanitized Event, plus _refs with two keys, namespace (the uid of the namespace its object is in; null for a node's) and its object's uid under its kind (pod, node, ingress...: the collector kind, involvedObject.kind lowercased), null until that very object (its uid) is indexed. The backfill sends them and reconciles them (an Event expired while the watch was down is deleted when the run finishes); the watch sends each as it appears and a delete when Kubernetes expires it. A new Event, a changed message or a new link goes at once; an Event that only repeats (count and lastTimestamp move) at most once per K8S_EVENT_REFRESH_SECONDS (300; 0: every repeat), so a probe failing every 10 s is a write every five minutes. K8S_EVENTS=false declares no event record type: event entities already in the catalog are then left as they are, like a kind left out of K8S_RESOURCES.

The mappings derive the rest from _events: on every entity event_count and warning_count (indexed: the catalog filters on scalars), on an ingress reconcile and reconcile_status (ok, error or blocked by another ingress of its group). Queries:

GET /instances/k8s-pod?warning_count:gt=0                     pods with a current warning
GET /instances/k8s-ingress?reconcile_status=blocked           ingresses the ALB controller cannot reconcile
GET /instances/k8s-event?type=Warning&reason=FailedScheduling  the cluster's current FailedScheduling events
GET /instances/k8s-event?pod_id=<pod uid>                      one pod's events

A cluster can deviate from its organization: its own destination of a record type and endpoint replaces the organization's for it (a disabled one stops the type there), and attributes on its source (env, region) reach the mappings as $source.attributes.

Definitions

A package defines everything its records need to mean anything, and ships it in its bundle (the library's dist/ and the compiled binary carry it; nothing is read from disk at run time):

| Definition | Where | What it is | | --- | --- | --- | | ENTITIES | src/specs/k8s-<kind>.json | the catalog entity specifications, one per record type, relation targets first (catalog-entities-api's POST /specifications body) | | SOURCE_TYPE | src/definitions/source-type.ts | the kubernetes source type: Kubernetes cluster, its runs max_delete_ratio: 0.5 and unguarded_types: ["event"] (catalog-ingest-api's POST /source_types body, the slug the source's type) | | SOURCE_TYPE.mappings | src/mappings/<record type>.jsonata | the mappings every source of the type shares, by slug, one per record type, each's slug its record type, JSONata (catalog-ingest-api's POST /source_types/{id}/mappings) |

SOURCE_TYPE = {
  name: "Kubernetes cluster",
  description: "A Kubernetes cluster, read by the Kubernetes collector: one source per cluster.",
  runs: { max_delete_ratio: 0.5, unguarded_types: ["event"] },
  platform: true,
  mappings: {
    pod: { engine: "jsonata", expression: "(…src/mappings/pod.jsonata…)", platform: true },
    // … one per record type: namespace, node, deployment, …, event
  },
};

All are nullplatform's (platform: true). The collector passes them to defineCollector (entities, and sourceType carrying the mappings of exactly the record types it collects: the event's only when it reads events; the SDK takes its recordTypes from them), and --describe lists them as the package's components: each entity's specification (entity_specification), the source type (source_type) and each mapping under it (mapping, kubernetes/<slug>), each owner: "platform". Publishing a package that ships them as they are pins nullplatform's; only nullplatform's own publish, with the platform's credentials, writes them.

Until the CLI publishes a package's components, definitions:apply applies what the collector describes, idempotently:

# An organization: looks nullplatform's specifications, type and mappings up and pins them, writing none
CATALOG_API_URL=https://... INGEST_API_URL=https://... NP_API_KEY=... mise run definitions:apply
# nullplatform, with the platform's credentials, on the internal network: updates each where it is found, creates a missing one global
CATALOG_API_URL=https://catalog.nullplatform.io INGEST_API_URL=https://ingestor.nullplatform.io CATALOG_TOKEN=... bun scripts/apply-definitions.ts --global

With --global, a specification found by its slug is updated where it is (no duplicate), and a missing one is created global (tenant_id: "*": every organization reads it, only the root tenant writes it); the type and its mappings are created with global: true. Without it, a missing one of nullplatform's fails the apply: it is nullplatform's to write. A mapping nullplatform has not yet brought up to date is pinned as it is, and the apply says so. CATALOG_TOKEN (or NP_API_KEY, exchanged at NP_API_URL) authenticates both APIs; INGEST_API_URL is the ingest library's public one unless set. --global runs on the internal network only, never through the public API (api.nullplatform.com refuses the root tenant's tokens): it needs INGEST_API_URL set and fails before any call without it, and both URLs are the APIs' internal ones. CATALOG_TENANT_ID names the organization a publisher's own specification is created in, when the token does not.

An extension reuses them as they are and adds its own beside them: an entity of its own (a CRD's kind) with its mapping, or a mapping of its own for a record type nullplatform's already maps (pod-acme, of record type pod, beside nullplatform's pod). Its own (no platform) are the publisher's, written into its organization by its publish; nullplatform's stay pinned.

import { defineCollector } from "@nullplatform/plugin/collector";
import { collectorDefinition, ENTITIES, SOURCE_TYPE } from "@nullplatform/collector-kubernetes";

const kubernetes = collectorDefinition(config);

export default defineCollector({
  ...kubernetes,
  package: { name: "collector-kubernetes-acme", version: "1.0.0" },
  entities: [...ENTITIES, { slug: "acme-widget", name: "Widget", schema: widgetSchema }],
  sourceType: {
    ...kubernetes.sourceType!,
    mappings: {
      ...kubernetes.sourceType!.mappings,
      widget: { engine: "jsonata", expression: widgetExpression },
      "pod-acme": { recordType: "pod", engine: "jsonata", expression: podWithTeamExpression },
    },
  },
  // The collector reads the kinds of its resource table: the widgets are the extension's to send.
  async *snapshot(ctx) {
    yield* kubernetes.snapshot(ctx);
    yield* widgets(ctx);
  },
});

The record types are the mappings' (widget added, pod once). An organization binds pod-acme where it wants it in place of pod.

Run

The collector is a defineCollector of @nullplatform/plugin: a plugin of its package (collector-kubernetes, its slug the name's; package.json's version and description), built by createCollector(config) from its own configuration. Its command line (src/cli.ts) maps each mode onto the SDK:

| Mode | What it does | Through | | --- | --- | --- | | --run | a backfill on start and every interval, plus the watch, until SIGTERM or SIGINT (a Deployment) | main, the agent's command line, which serves the collector | | --once | one backfill, its result printed as JSON on stdout; exit 0 reconciled, 2 a guard tripped (nothing deleted), 1 failed (a cron job) | handle, one snapshot answered as the agent's exec answers one | | --describe | the manifest np package publish reads: the package, no component of its own, the collector block | main |

Two entry points run it, and no variable switches one into the other:

| Entry | Ports | Run by | | --- | --- | --- | | src/index.ts | the real ones: catalog-ingest-api, the platform API, tracing | the image, bun run once, bun run describe, bun src/index.ts --run | | src/local.ts | in memory: InMemoryIngest (@nullplatform/ingest/testing), recordingPlatform(), noopTracing; nothing leaves the process but the cluster's reads, and stderr tells each source and run the ingest would get | mise run dev, bun src/local.ts --once |

Either reads the cluster of its kubeconfig. It never exits the process: it sets the exit code and lets the process end once the run has.

Library

@nullplatform/collector-kubernetes is what an application needs to run the collector in its own process: the collector, its configuration's defaults and the reader of its configuration from an environment, a hook for readiness, and what the package defines (Definitions). The SDK runs it.

bun add @nullplatform/collector-kubernetes @nullplatform/plugin @nullplatform/ingest

@nullplatform/plugin (^0.4.0) and @nullplatform/ingest (>=0.0.6 <1.0.0) are peers: the application brings them, and its one copy of the SDK runs the collector the library builds.

import { serve } from "@nullplatform/plugin";
import { configurationOf, createCollector, resolveSource } from "@nullplatform/collector-kubernetes";

const { config, ports } = configurationOf(process.env);
let watching = false;
const collector = createCollector(config, { onWatching: (now) => { watching = now; } });
const stop = new AbortController();
process.once("SIGTERM", () => stop.abort());
const source = await resolveSource(process.env, { log: console });
await serve(collector, { ...ports, source, signal: stop.signal });

| Export | What it is | | --- | --- | | createCollector(config?, deps?) | the collector of its configuration (KubernetesOptions: each part its default unless given, each of events too): a Plugin of @nullplatform/plugin, run by its serve (the backfill on start and every interval, plus the watch, until the signal aborts), main (the agent's command line) or handle (one snapshot) | | deps.onWatching(watching) | told whether the collector is watching: false when a watch starts and lists every resource (the SDK starts one only once its source is set up, so catalog-ingest-api was reached), true once every resource is listed and watched, false again when the watch ends (it failed and the SDK restarts it after a backoff, or the collector is stopping). A caller's readiness: serving while true; starting until then and while a failed watch restarts; stopping is the caller's own, once it aborts the signal | | deps.kube(context) | how the collector reaches the cluster (KubeApi): KUBECONFIG / ~/.kube/config / in-cluster unless given (a test's fake) | | configurationOf(environment) | what an environment configures (the variables of Settings): { config, ports }, the collector's own configuration and the ports serve and main take (settings, intervalSeconds, ingestUrl, ingestToken); refuses an interval that is not a number of seconds | | resolveSource(environment, { facts?, log? }) | the source a run feeds, the cluster's, asked of the cluster when the environment names none (async): its slug NP_COLLECTOR_SOURCE_SLUG, else the cluster's own name (in a cluster on GKE, the metadata server's cluster-name; on OKE, the OCI metadata server's oke-cluster-display-name; a node's alpha.eksctl.io/cluster-name label; the cluster in a node's kubernetes.azure.com/cluster label (AKS's node resource group MC_<group>_<cluster>_<region>); outside a cluster, the kubeconfig's current cluster), else the kube-system namespace's uid; a detected name that makes no slug is skipped. It logs source <slug> (<where from>). facts (ClusterFacts) replaces what the cluster says, for a test | | configOf(given?) | the collector's configuration, each part the one given, else DEFAULT_CONFIG's | | DEFAULT_CONFIG | every resource of the table, no excluded namespace, the current context, pages of 500, events read (Warnings only) | | ENTITIES | the catalog entity specifications the package defines, relation targets first, each nullplatform's (Definitions) | | SOURCE_TYPE | the kubernetes source type the package defines, nullplatform's, with its mappings by slug (SOURCE_TYPE.mappings) | | collectorDefinition(config?, deps?) | the collector's definition, which createCollector defines: what an extension builds its own collector from (Definitions) |

Types: KubernetesConfig, KubernetesOptions, EventsConfig, Configuration, ConfiguredPorts, Environment, KubernetesCollector, KubernetesPorts, CollectorDeps, KubeApi. A local run passes in-memory ports in code, as src/local.ts does: ingest: new InMemoryIngest() (@nullplatform/ingest/testing), fetch: recordingPlatform().fetch and tracing: noopTracing.

Deploy

In the cluster it collects (read-only RBAC on exactly the resources above, and on events):

kubectl create namespace nullplatform-catalog
kubectl -n nullplatform-catalog create secret generic catalog-collector \
  --from-literal=NP_INGEST_API_URL=https://<catalog-ingest-api> \
  --from-literal=NP_API_KEY=<nullplatform api key>
kubectl apply -f deploy/collector.yaml

Every key of the secret is a variable of Settings. One replica: the collector holds its watches in memory; a second replica would send everything twice (harmless, pointless). A restart resumes the watches at once; the next snapshot keeps its schedule, counted from the last run.

Settings

Environment variables, read in one place (src/settings.ts) with each default in code, and handed over in code: the K8S_* variables are the collector's own configuration, which builds it (createCollector(config)); the rest are @nullplatform/plugin's collector ports and the platform's settings. The SDK reads no config file; of the environment it reads only the variables the agent sets on a worker, in main, for what the code leaves unset.

| Variable | Setting | Default | | --- | --- | --- | | NP_API_URL | the platform API (settings.apiUrl) | https://api.nullplatform.com | | NP_API_KEY | the platform API key (settings.apiKey), exchanged for catalog-ingest-api's token | none | | NP_INGEST_API_URL | catalog-ingest-api's URL (the ingestUrl port) | <NP_API_URL>/catalog/ingest | | NP_INGEST_TOKEN | a ready token for catalog-ingest-api (the ingestToken port), in place of the API key: a local API's | none | | NP_COLLECTOR_SOURCE_SLUG | the source's slug as given (source.slug), over the name the collector finds: the cluster of its entities and their key prefix (prod-eu, prod-eu/shop/checkout). Without it the slug is the cluster's own name (in a cluster on GKE, the metadata server's cluster-name; on OKE, the OCI metadata server's oke-cluster-display-name; a node's alpha.eksctl.io/cluster-name label; the cluster in a node's kubernetes.azure.com/cluster label (AKS's node resource group MC_<group>_<cluster>_<region>); outside a cluster, the kubeconfig's current cluster), else the kube-system namespace's uid; a detected name that is not lowercase letters, digits, ., _, - is skipped. The collector logs the slug it chose and where from | found by the collector | | NP_COLLECTOR_SOURCE_NAME | the source's display name (source.name) | Kubernetes cluster | | NP_COLLECTOR_SOURCE_NRN | where the source lives (source.nrn); never changed once it exists | the organization's root | | NP_COLLECTOR_INTERVAL_SECONDS | seconds between resyncs after the backfill (the intervalSeconds port); 0: none; anything but a number of seconds is refused | 86400, a day (the definition's schedule) | | K8S_RESOURCES | comma-separated record types to collect, and so the ones each run covers (config.resources) | every one of the table | | K8S_EXCLUDE_NAMESPACES | comma-separated namespaces to ignore (config.excludeNamespaces) | none | | K8S_CONTEXT | a kubeconfig context other than the current one, outside a cluster (config.context) | the current one | | K8S_PAGE_SIZE | objects per list request (config.pageSize); anything but a whole number above zero is the default | 500 | | K8S_WATCH_WINDOW_SECONDS | seconds a watched object's change waits for its next one; only the latest is sent, and only if it changed (config.watchWindowSeconds); 0 sends each change at once; anything but a number of seconds is the default | 5 | | K8S_EVENTS | whether it reads Events for each object's current events, _events (config.events.enabled); false reads none and sends every _events as [] (a service account that cannot list events needs it); anything but true or false is the default | true | | K8S_EVENT_TYPES | comma-separated event types it reads, Warning, Normal or both, in any case, each with its own server-side filtered watch (config.events.types); another type is refused | Warning | | K8S_EVENT_REFRESH_SECONDS | seconds an event record that only repeats (its count and last time move) waits to be sent again (config.events.refreshSeconds); a new event, a changed message or a new link go at once; 0 sends every repeat; anything but a number of seconds is the default | 300 | | K8S_EVENT_NORMAL_REASONS | comma-separated reasons the Normal events read are narrowed to, a server-side filtered watch each in place of every Normal event (config.events.normalReasons): e.g. SuccessfullyReconciled, the AWS Load Balancer Controller's "fixed" (the collector knows no controller of its own). Only with Normal in K8S_EVENT_TYPES; without it, refused at startup | none: every Normal event, when Normal is read |

A variable set to nothing (empty or blank) is unset. Outside a cluster it uses KUBECONFIG / ~/.kube/config (client certificates, tokens and exec plugins such as aws eks get-token); inside, the service account.

Develop

mise run test        # standalone unit tests: sanitize, refs, records, the definitions (specs, mappings on the fixtures), watcher, backfill, the public entry — no cluster, no other project
mise run typecheck
mise run lint
mise run build       # the library: tsdown into dist/ with its declarations, then check:package loads it under bun and Node
mise run build:binary # the command line compiled for this machine (bin/kubernetes)
mise run dev         # src/local.ts --run: the current kube context, in-memory ports; sends nothing, reloads on a change (bun --hot)
bun src/local.ts --once   # one local backfill, its result printed; sends nothing
mise run once        # one real backfill, src/index.ts --once (needs NP_INGEST_API_URL + credentials)
mise run test:e2e    # see below

End to end on k3d

mise run test:e2e creates a k3d cluster (catalog-k8s-e2e, with its own kubeconfig file: yours is not touched), seeds it (e2e/manifests/shop.yaml: one of every kind) and runs against the real catalog stack:

  1. the collector as a local process: the backfill writes every kind to the catalog, found by key, ids the objects' uids, every relation resolved (belongs_to and many_to_many); the watch then carries a new deployment, a scale-up (the service gains the new pod), a label added and removed, a pod linked to a config map created after it and following it when recreated, and a deletion, without another backfill; stopped, then a --once backfill reconciles what changed while it was down (a deleted cron job is deleted, a new config map appears);
  2. the collector inside the cluster: the image (Dockerfile.local), imported into k3d and deployed with deploy/collector.yaml (RBAC, in-cluster credentials, non-root, read-only filesystem), backfills and watches on the same source slug (same cluster, same entities).

The stack is one you run: a catalog-ingest-api with its worker and the catalog-entities-api behind it (for example the local development stack). Set INGEST_API_URL, CATALOG_API_URL and INGEST_TOKEN (a bearer both accept); the ingest API must listen on an interface pods can reach at host.k3d.internal. KEEP_CLUSTER=1 leaves the cluster up.

Dependencies

@nullplatform/plugin (^0.4.0) and @nullplatform/ingest (>=0.0.6 <1.0.0) are the library's peers, and devDependencies here (0.0.9 for ingest, whose client definitions:apply uses); jsonata and ajv are devDependencies the definitions' tests evaluate and validate with; @kubernetes/client-node is its one dependency. All install from the npm registry, as bun.lock pins them. The image is the multi-stage Dockerfile (mise run build:image); Dockerfile.local packages a binary compiled on the host (mise run build:image:local), which the e2e uses.

Releases

nullplatform owns the version: it cuts a release from a green main build (.github/workflows/ci.yml gates every push and PR and registers one, the image its asset) and creates the GitHub Release, tag = the version. That fires publish.yml (the tag's version into package.json, the gate, npm by trusted publishing, mirrored to GitHub Packages), mirror-version.yml (the version back into main) and release.yml (the image, tagged and versioned with it). Never bump version by hand; a change goes under CHANGELOG.md's ## Unreleased.

Limits

  • Memory: the watch keeps the latest sanitized copy of every collected object (like an informer cache) to resolve references, and a backfill holds its whole listing until it is sent: about twice the sanitized size of the cluster at peak, while a backfill runs. The events read (their types, their Normal reasons) about a collected kind are collected objects too: one sanitized copy each. Normal without reasons reads every Normal event of the collected kinds: many more than the Warnings.
  • The source refuses a snapshot that would delete half its entities or more (maxDeleteRatio, across every record type): events are entities too, and a watch down for hours leaves a snapshot many expired ones to delete.
  • A relation to a kind left out of K8S_RESOURCES (or to an excluded namespace) is null or empty: the collector never sees its targets.
  • The watch starts once every resource is listed; one that cannot be listed fails the watch, which the SDK restarts with a backoff (as a backfill, it never runs on a partial picture).
  • Pods are high-churn: every status transition is an event (catalog writes only when the mapped data changes). Drop pod from K8S_RESOURCES if the catalog should only hold workloads.
  • Kubernetes Events are collected only when about an object collected, of the types read. Leases, Endpoints and EndpointSlices are not collected (high-volume, not catalog material); Secrets never are.
  • Events about objects the collector does not collect (a HorizontalPodAutoscaler, a TargetGroupBinding) are dropped: a service's load balancer reconciliation (its TargetGroupBinding's BackendNotFound) is not reported yet.
  • Events that cannot be listed abort every backfill and fail the watch, as any resource: grant list/watch on events or set K8S_EVENTS=false.
  • A resource the service account cannot list aborts every backfill (on purpose: nothing is deleted on an incomplete picture). Grant list/watch or remove it from K8S_RESOURCES.
  • Custom resources are not collected yet.