@redkern/node-red-flow-splitter 1.0.0

Node-RED plugin that splits flows into deterministic, reviewable files in src/ for Git-based change control

npm install @redkern/node-red-flow-splitter

@redkern/node-red-flow-splitter

A Node-RED plugin that writes the running flows into small, deterministic files under src/ after every deploy, so that each Git commit shows exactly the change that was made in the editor. It is built for change control in production (SOX-style audit trails): same flow state, same bytes; every change reaches src/; files changed behind the editor's back are detected; nothing blocks the runtime.

It replaces @yroshcha/node-red-contrib-flow-splitter-extended. Where 1.3.2 needed about 15,800 synchronous file operations to save one edited function in a large project, this plugin writes only the changed file plus its bookkeeping.

This is a plugin, not a palette: it registers no node types.

Requirements

  • Node.js 22 or newer
  • Node-RED 4.1.0 or newer, below 6.0.0
  • adminAuth configured, if you want the admin routes and the sidebar status (the routes fail closed without it)

Install

From your Node-RED user directory (or through Manage palette):

npm install @redkern/node-red-flow-splitter

Restart Node-RED. Remove the old @yroshcha/node-red-contrib-flow-splitter-extended first: when both are installed, this plugin goes to an error state and writes nothing.

Recommended for production: set UV_THREADPOOL_SIZE=16 so that file operations do not crowd DNS lookups of Kafka, Redis and HTTP clients out of the libuv pool.

What it writes

src/
  tabs/
    loyalty-points--a1b2c3d4.json            tab node + its nodes, sorted by ID
    loyalty-points--a1b2c3d4/
      calc-bonus--9f8e7d6c.js                 function code
      calc-bonus--9f8e7d6c.initialize.js      "On Start"
      calc-bonus--9f8e7d6c.finalize.js        "On Stop"
      calc-bonus--9f8e7d6c.md                 node description (info)
      render-card--5a4b3c2d.vue               Dashboard 2 ui-template
  subflows/
    retry-wrapper--0e1f2a3b.json
  config-nodes/
    kafka-prod--77aa88bb.json
  tabs-order.json                             tab order (only file touched by reordering)
  .redkern-splitter/
    manifest.json                             SHA-256 of every file and of the whole state
    audit.jsonl                               append-only change log
    lock                                      writer lock (ignored by Git)
  • Names are <slug>--<first 8 characters of the node ID>. Cyrillic is transliterated; the slug keeps a-z, 0-9 and -, at most 48 characters. Names never depend on the position of a tab, so renaming one tab changes one file and one folder. When two nodes in one folder share the first 8 ID characters, both use 12.
  • Extracted code is replaced in the JSON by {"$file": "calc-bonus--9f8e7d6c.js"}, so it shows up in exactly one diff. Code is stored byte for byte. Extracted: function func/initialize/finalize (.js), any node's info (.md), core template (.html, or .mustache for the mustache format), Dashboard 2 ui-template (.vue), Dashboard 1 ui_template (.html).
  • JSON uses two-space indentation, LF and a final newline. Keys are ordered id, type, z, g, name, label, then the other keys alphabetically, then x, y, w, h, wires.
  • Credentials are never written: flows_cred.json stays with Node-RED (and Projects encrypts it).
  • flows.json stays the source of truth and stays in the repository (Projects needs it). The plugin adds flows.json -diff linguist-generated=true to .gitattributes so reviews show the diff of src/ only.

The plugin keeps the lock out of Git with src/.redkern-splitter/.gitignore.

How it behaves

  • Deploy: the flows:started handler only queues work. "Modified flows/nodes" deploys process the tabs in Node-RED's deploy diff plus tabs whose node positions changed (the diff ignores positions). Full deploys and reloads render every tab but write only files whose hash changed. A burst of deploys collapses to one running and one pending pass. Deploys while the runtime is stopped are split too.
  • Startup: the plugin reads src/ once, asynchronously, compares it with the manifest and the running flows, and writes nothing if they match. If flows.json is newer than the manifest (for example a deploy through the Admin API while the plugin was not installed) it writes what changed. It never rebuilds flows.json from src/ on its own; use the CLI for that.
  • Master/worker pods on one volume (EFS, ReadWriteMany): set REDKERN_SPLITTER_ROLE=master on the single master pod and REDKERN_SPLITTER_ROLE=worker on every worker. If the role is missing or invalid, the plugin does not split. The lock records the master's Kubernetes pod name, namespace and UID. Once a lock is stale, only a master with in-cluster Pod get permission may clear it, and only after Kubernetes confirms that exact UID is NotFound, replaced by another UID, or in Succeeded/Failed phase. Running, Pending, API errors, timeouts, missing identity and RBAC denial all keep the lock in place. After recovery the master rescans src/ before writing. On Node-RED installations outside Kubernetes, stale locks remain fail-closed and require operator-confirmed cleanup.
  • Drift: a file whose hash differs from the manifest (edited outside the editor), a missing file or an unknown file. With onDrift: "report" (default) it is logged as an error, recorded in the audit log, shown in the sidebar, and left alone until the next deploy rewrites it. With "overwrite" it is rewritten from the running flows at once. Drift is detected at startup and by GET /redkern/splitter/verify.
  • Audit log: src/.redkern-splitter/audit.jsonl, one line per pass that changed a file (time, host, user, deploy type, tabs, written/deleted/renamed files, state hash before and after), plus lines for drift, stale locks, lost locks and write errors. A pass without changes writes nothing, so git status stays clean. The deploying user comes from Node-RED's own flows.set audit event. Every record is also logged as JSON with the [redkern:splitter] prefix for central log storage. Rotation by size (10 MB, previous files kept).
  • Commits: the plugin never commits. Commit through Node-RED Projects (or your usual Git flow) with a meaningful message. Wait until the sidebar shows Complete; while it shows Writing a commit could catch half a pass.

Configuration

Project level, .config.redkern-splitter.json next to flows.json (all optional):

{
  "destinationFolder": "src",
  "fileFormat": "json",
  "extractCode": true
}

fileFormat is always json in 1.0.0; any other value logs a warning and uses JSON.

Instance level, settings.js:

redkern: {
  splitter: {
    // Set REDKERN_SPLITTER_ROLE=master only on the active master pod.
    enabled: true,            // REDKERN_SPLITTER_ENABLED
    concurrency: 8,           // REDKERN_SPLITTER_CONCURRENCY, parallel file operations
    reloadEnabled: false,     // REDKERN_SPLITTER_RELOAD_ENABLED
    onDrift: 'report',        // or 'overwrite'
    auditMaxBytes: 10485760,  // rotation size of audit.jsonl
    auditKeep: 10,            // rotated files kept
    lockStaleMs: 60000,
    lockRefreshMs: 10000,
    projectDir: ''            // only to override the Projects/flowFile directory detection
  }
}

Environment variables win over settings.js; empty values fall through. REDKERN_SPLITTER_ROLE defaults to worker, so only an explicit master enables project writes. REDKERN_SPLITTER_ENABLED=false switches the plugin off without changing the image.

For Kubernetes, expose the pod identity with the Downward API on the master container:

env:
  - name: REDKERN_SPLITTER_ROLE
    value: master
  - name: POD_NAME
    valueFrom:
      fieldRef:
        fieldPath: metadata.name
  - name: POD_NAMESPACE
    valueFrom:
      fieldRef:
        fieldPath: metadata.namespace
  - name: POD_UID
    valueFrom:
      fieldRef:
        fieldPath: metadata.uid

Set REDKERN_SPLITTER_ROLE=worker on worker containers. The master service account needs a mounted token and a namespace-scoped permission to get Pods; it does not need list, watch, or write permissions:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: redkern-splitter-pod-reader
rules:
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: redkern-splitter-pod-reader
subjects:
  - kind: ServiceAccount
    name: node-red-master
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: redkern-splitter-pod-reader

Bind the Role in the same namespace as the master and the pods sharing src/; set serviceAccountName: node-red-master on the master Pod. Existing lock files created before pod identity was added cannot be verified automatically: confirm the old writer is stopped and remove such a lock once during upgrade. Build/migrate actions against the shared project run on the master; GitHub CI and npm release jobs remain on their isolated GitHub runners.

Admin routes

All routes are registered on the Node-RED admin API and need adminAuth.

Route Permission Purpose
GET /redkern/splitter/status redkern.splitter.read state, last pass, drift, lock owner
GET /redkern/splitter/verify redkern.splitter.read rescan src/, report drift and compare with the running flows
POST /redkern/splitter/reload redkern.splitter.write build flows from src/ and deploy them

Troubleshooting: admin routes unavailable. If the Node-RED log reports [redkern:splitter] [plugin] Admin route unavailable because adminAuth is not configured, configure Node-RED adminAuth and restart the runtime. Without it, the splitter's status, verify and reload routes are unavailable; callers also need the permissions listed above. In one observed setup, enabling adminAuth resolved a long apparent editor stall during change scanning, including full-instance deploys with a large flow. Check the browser Network panel for failed /redkern/splitter/status requests before attributing an editor pause to EFS or splitter file I/O. Confirm that the status request returns 200 after authentication.

reload is disabled unless REDKERN_SPLITTER_RELOAD_ENABLED=true: in production, editing files behind the editor bypasses change control. When enabled it deploys through the public POST /flows (API v2, current rev) with the caller's own token, so it passes the same authorization and audit as a normal deploy; the plugin also writes a reload audit record with the deployed rev and node count. Users with the plain read scope can call status and verify. When a split pass is still running or waiting for another pod's lock, reload answers 409 with code BUSY instead of deploying later. Besides Authorization, the header named in adminAuth.tokenHeader is forwarded.

When the plugin is switched off or its settings are invalid, status still answers with state: "disabled" and the reason, so the sidebar shows why. The editor gets only a change signal over the comms channel; the status itself is always read through the permission-checked route.

Sidebar

The splitter tab (icon fa-code-fork) shows the state (Complete with the short state hash, Writing, Waiting for another pod's lock, Drift, Error), the last pass, the drift list and the lock owner, and has a Verify button. English and Ukrainian texts are included. Following the Node-RED packaging conventions, the flow-splitter icon is in icons/ and the sidebar styles are in resources/; Node-RED serves both to the editor.

Examples

Import them in the editor from Import > Examples > @redkern/node-red-flow-splitter:

  • 01 what gets split: a function with On Start, On Stop and a description, a mustache template and an HTML template. Deploy it and look at src/ to see which file each part lands in.
  • 02 drift check: calls GET /redkern/splitter/verify every 15 minutes with a read-only admin token, keeps the result in flow context (splitterVerify) and sends drift or errors to its second output for alerting. Set REDKERN_SPLITTER_VERIFY_URL and REDKERN_SPLITTER_TOKEN in the tab's environment variables or for the process.

CLI for CI

The package ships redkern-flow-splitter:

npx redkern-flow-splitter verify --project .        # exit 1 when src/ and flows.json differ or src/ drifted
npx redkern-flow-splitter build --project .         # rebuild flows.json from src/
npx redkern-flow-splitter build --out -             # ... to stdout
npx redkern-flow-splitter migrate --project .       # convert a 1.3.x src/ in place
npx redkern-flow-splitter hash --project .          # canonical state SHA-256 of src/

verify is the pipeline check that what is committed in src/ is what is deployed. To restore flows from src/, run build and commit the rebuilt flows.json through Projects.

Migrating from @yroshcha/node-red-contrib-flow-splitter-extended

  1. Install this plugin and uninstall the old one.
  2. On first start the plugin reads .config.flow-splitter.json and creates .config.redkern-splitter.json with the same folder and extraction setting. The format becomes JSON even if the old file says yaml.
  3. Extracted code files are moved with rename, so Git shows them as renames. JSON tab files are rewritten in place and Git detects them as renames by content. YAML tab files of 1.3.x cannot be shown as renames, because their content changes format.
  4. A manifest and an audit record of type migration are created.
  5. Commit the result as one separate commit, without other flow changes.

redkern-flow-splitter migrate does the same from the command line.

Development

npm test                    # unit tests
npm run test:integration    # real Node-RED 5 in child processes (+ Playwright editor test when installed)
npm run bench               # section 6 budgets on a 300-tab / 30,350-node project
npm run check               # everything, as in CI

To run the same scenarios against a sanitized flow file on a mounted EFS directory, run the benchmark on the master pod and set REDKERN_SPLITTER_BENCH_FLOW to the flow JSON array and REDKERN_SPLITTER_BENCH_ROOT to an existing dedicated directory on the EFS mount. Each run creates and removes a uniquely named temporary project under that directory; it never uses the live project src/. REDKERN_SPLITTER_CONCURRENCY selects the benchmark's file-operation limit (1-64, default 8):

REDKERN_SPLITTER_BENCH_FLOW=/bench/flows-sanitized.json \
REDKERN_SPLITTER_BENCH_ROOT=/mnt/efs/splitter-bench \
REDKERN_SPLITTER_CONCURRENCY=8 \
npm run bench

Use a flow export with credentials and sensitive values removed. Run it in staging or a dedicated master pod, not during production traffic; this benchmark performs a full split and repeated EFS scans.

Security and support

Report vulnerabilities through GitHub Private Vulnerability Reporting; do not open a public issue for an unpatched vulnerability. For general support use GitHub issues. See SECURITY.md.

License and attribution

Apache-2.0. Based on the original node-red-contrib-flow-splitter-extended by vdwpsmt and its fork by Yehor Roshcha; see NOTICE.

Node Info

Version: 1.0.0
Updated 5 days ago
License: Apache-2.0
Rating: not yet rated

Categories

Actions

Rate:

Downloads

0 in the last week

Keywords

  • node-red
  • node-red-contrib
  • redkern
  • flows
  • split
  • git
  • diff
  • sox
  • audit
  • version-control

Maintainers

Contributors

  • vdwpsmt
  • Yehor Roshcha