backstage-cilium-render
About 685 words
Renders a cluster's network policy from local catalog files, the way Backstage would. It ships in @spechtlabs/backstage-plugin-cilium-backend. Check a change locally shows it in use.
Synopsis
backstage-cilium-render [--policy <name>] [--out <file>] [--json <file>] [--flows] <catalog dir>...Run it without installing:
npx -p @spechtlabs/backstage-plugin-cilium-backend backstage-cilium-render …The package also exports the command's module as @spechtlabs/backstage-plugin-cilium-backend/cli; running that file does the same.
Arguments
| Argument | Meaning |
|---|---|
<catalog dir>... | One or more directories with catalog YAML. Each must be inside a git working tree. |
Relative paths resolve against the directory you run the command from. Under yarn they resolve against INIT_CWD, the directory yarn was started in.
Flags
| Flag | Meaning |
|---|---|
--policy <name> | The metadata.name of the policy entity to render. Default: the first policy by name. |
--flows | List every flow except those within an endpoint. |
--out <file> | Write the rendered manifests here. |
--json <file> | Write the rendered overview here, every policy included, as GET /api/cilium/overview serves it but without publish. |
-h, --help | Print the usage line and exit with status 2. |
What it reads
In each directory, every file git ls-files --cached --others --exclude-standard lists that ends in .yaml or .yml. That's tracked and untracked files, without the ones git ignores. A file is only parsed if it has a line starting with apiVersion: backstage.io/ or apiVersion: specht-labs.de/.
Each YAML document with such an apiVersion, a kind and a metadata.name is an entity, except kind: Location. metadata.namespace defaults to default. A document that doesn't parse is skipped with a warning, and so is the second definition of an entity.
It then adds the relations the catalog would: consumesApi and apiConsumedBy from spec.consumesApis (default kind API), providesApi and apiProvidedBy from spec.providesApis (default kind API), dependsOn and dependencyOf from spec.dependsOn (default kind Component), and the Cilium relations. It doesn't validate kind: Cilium entities the way the catalog module does.
Output
<policy title or name>: <n> entities, <n> endpoints (<n> under the default deny), <n> flows, <n> policies, <n> lines[ -> <out file>]
[(open) ]<endpoint ref> <namespaces>/<selector> in <n> / out <n>
flows:
<from> -> <to> [<ports or *>] <reason>
problems:
<error|warning|info>: [<entity ref>: ]<message>- The counts: every entity read, the endpoints, the endpoints whose namespaces aren't all excluded, every flow (each endpoint's flow to its own pods included), the
CiliumClusterwideNetworkPolicydocuments, and the lines of the manifests. - Endpoints are sorted by the name of their policy.
<namespaces>is the one namespace,{a,b}for several, or*for none;<selector>is the label selector, or*for every pod.inandoutcount the flows that reach and leave it, its own included. - The
flows:section is only there with--flows. Endpoints show as their short reference (component:shop), peers outside the cluster asentity:…,cidr:…,fqdn:…ortailnet <destination>. - The
problems:section is only there when there are problems: first rule entities without a policy, then the rendered policy's diagnostics, errors first.
For example, on docs/examples/first-policy:
Production cluster: 6 entities, 3 endpoints (3 under the default deny), 5 flows, 4 policies, 172 lines
component:default/orders orders/app=orders in 2 / out 1
component:default/shop shop/app=shop in 1 / out 3
resource:default/shop-db shop/cnpg.io/cluster=shop-db in 2 / out 1
flows:
component:shop -> component:orders [tcp:9000] component:shop consumes api:orders-api
component:shop -> resource:shop-db [tcp:5432] component:shop depends on resource:shop-dbExit status
| Status | Meaning |
|---|---|
| 0 | The policy, and every rule entity without a policy, is free of errors. Warnings and notes don't count. |
| 1 | There's an error. |
| 2 | Bad arguments: no directory, a path that doesn't exist or isn't a directory, a --policy that doesn't exist, no policy at all; or an unexpected failure, such as a directory outside a git working tree. |
