Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 46 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
# backstage-plugin
A Backstage Plugin for supporting Runtime Conditions Profiles

Adds a "Runtime Conditions" tab to a Component's page. A `RuntimeConditionsProfile`
describes one codebase, independent of where it's deployed, so a single profile
can exist as a resource in more than one cluster (dev, prod, federal, and so
on). The tab shows one card per cluster where a matching profile is found,
each is a distinct deployment of that codebase.
A Backstage plugin for Runtime Conditions Profiles.

Each card shows the profile's workload, its extensions, and its declared
conditions, alongside which resource fulfilled each condition, if a platform
adapter (see `runtimeconditions/rc-demos/tree/main/cilium-policy/adapter` for
an example) has reported one through the fulfillment API below. Fulfillment
is never inferred by this plugin, only reported by an adapter.
A `RuntimeConditionsProfile` is a portable, machine-readable list of what one workload needs at runtime. This plugin adds a **Runtime Conditions** tab to a Component's page. The tab shows one card per cluster where a matching profile is found, with the profile's workload, extensions, declared conditions, and which resources fulfilled each condition, as reported by platform adapters. Fulfillment is never inferred by this plugin. Only an adapter reports it.

## Install
## The mental model

Add the package to your app's `packages/app`:
| Concept | What it is | Where it lives |
| --- | --- | --- |
| **Profile** (`RuntimeConditionsProfile`) | A description of one codebase, independent of where it runs: its `workload.uri`, the `extensions` it uses, and the `conditions` it declares. Each condition has a `kind`, an `interface.type`, and an optional `optional` flag. | A custom resource (`runtimeconditions.io/v1alpha1`) in a cluster. Conceptually it could live anywhere; only the current fetch is Kubernetes. |
| **Deployment** | One cluster where a matching profile exists. The same profile in dev, prod, and federal means three deployments, shown as three cards on the Component page. | Derived: profile found in cluster X. |
| **Condition** | A capability the workload needs (e.g. `available-stock-capability`) with an interface contract. | `profile.conditions[]`. |
| **Fulfillment** | A report from a platform adapter that a condition is satisfied in an environment, and by which concrete resources. Never inferred by the plugin. Only reported. | Stored by the companion backend plugin via `POST /api/runtime-conditions/fulfillments`. |
| **Extension** | A pluggable capability the workload consumes. Extension URLs of the form `https://runtimeconditions.io/extensions/<ns>/<name>/runtimeconditions.extension.yaml` are linked by the UI to their definition in the `runtimeconditions/extensions` repo. | `profile.extensions[]`. |

**Correlation rule (important):** a profile belongs to a Component when the profile's `workload.uri` equals the Component's `backstage.io/source-location` annotation, with the `url:` prefix stripped. Matching is by identity (repo URL), not by Kubernetes labels.

Profile YAML doesn't have to live in Kubernetes at all. It can just as well live in a Git repo or a file server. This plugin only reads it from Kubernetes today because that's the only source wired up so far. The correlation and rendering logic doesn't assume Kubernetes. Only the current fetch does.

## Quickstart

Prerequisites: the Kubernetes plugin configured in your Backstage app with at least one cluster registered, and the CRD `runtimeconditionsprofiles.runtimeconditions.io` installed in each cluster you want scanned. Profiles are listed from every configured cluster through the Kubernetes plugin's proxy API. No per-entity Kubernetes annotation or `kubernetes.customResources` config is needed.

Frontend:

```
yarn --cwd packages/app add @runtimeconditions/plugin-runtime-conditions
Expand All @@ -38,33 +45,7 @@ import {
</EntityLayout.Route>
```

Requires the Kubernetes plugin already configured in the app, with at least
one cluster registered, since profiles are currently read as
`RuntimeConditionsProfile` custom resources from every configured cluster.
No per-entity Kubernetes annotation or `kubernetes.customResources` config is
needed: this plugin lists profiles directly through the Kubernetes plugin's
proxy API rather than the entity-scoped fetch.

## Correlating a Profile to a Component

A profile describes a codebase, not a deployment, so it's matched by
identity, not by Kubernetes labels. A `RuntimeConditionsProfile` is shown on
a Component's page when its `workload.uri` equals that Component's
`backstage.io/source-location` annotation (with the `url:` prefix stripped).
The same profile can be found in more than one cluster; each is shown as its
own deployment.

Profile YAML doesn't have to live in Kubernetes at all, it can just as well
live in a Git repo or a file server. This plugin only reads it from
Kubernetes today because that's the only source wired up so far; the
correlation and rendering logic here doesn't assume Kubernetes, only the
current fetch does.

## Fulfillment API

`backend/` is `@runtimeconditions/plugin-runtime-conditions-backend`, a
companion backend plugin an adapter reports fulfillment to. Add it to your
app's `packages/backend`:
Backend, only if adapters will report fulfillments:

```
yarn --cwd packages/backend add @runtimeconditions/plugin-runtime-conditions-backend
Expand All @@ -74,66 +55,30 @@ yarn --cwd packages/backend add @runtimeconditions/plugin-runtime-conditions-bac
backend.add(import('@runtimeconditions/plugin-runtime-conditions-backend'));
```

An adapter registers a fulfillment with:
Open any Component with a `backstage.io/source-location` annotation. A "Runtime Conditions" tab appears.

```
POST /api/runtime-conditions/fulfillments
{
"profileName": "request-coordinator",
"condition": "available-stock-capability",
"environment": "dev",
"resources": [
{
"kind": "CiliumNetworkPolicy",
"provider": "kubernetes",
"reference": "rc-cilium/applications/request-coordinator-egress",
"componentRef": "component:default/inventory-service",
"automation": { "tool": "kratix", "reference": "cnp-promise" }
}
]
}
```
## Documentation

- [Usage: critical-path workflows](docs/usage.md)
- [Architecture and API reference](docs/architecture.md)
- [Fulfillment API for adapters](docs/fulfillment-api.md)
- [Releases](docs/releases.md)

## Ecosystem

Part of the Runtime Conditions org, https://github.com/runtimeconditions:

- [spec](https://github.com/runtimeconditions/spec): the Runtime Conditions specification
- [extensions](https://github.com/runtimeconditions/extensions): first-party extension definitions; profile extension URLs link here
- [rc-demos](https://github.com/runtimeconditions/rc-demos): demos, including the `cilium-policy/adapter` fulfillment adapter
- [rc-cli](https://github.com/runtimeconditions/rc-cli): CLI that generates and validates profiles
- [go-rc-profiler](https://github.com/runtimeconditions/go-rc-profiler), [java-rc-profiler](https://github.com/runtimeconditions/java-rc-profiler), [python-rc-profiler](https://github.com/runtimeconditions/python-rc-profiler): language profilers
- https://runtimeconditions.github.io: public reader guide

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).

## License

- A condition is often fulfilled by more than one resource, e.g. a
`CiliumNetworkPolicy` plus a cert-manager `Certificate` for an API
condition, or a database plus a `CiliumNetworkPolicy` plus a `Secret` for a
datastore condition, so `resources` is always an array, never a single
object.
- Each resource's `reference` is whatever uniquely identifies it in its
environment, e.g. `cluster/namespace/kind/name` for Kubernetes or an ARN
for a cloud resource.
- `resource.provider` and `resource.automation.tool` are free-form strings,
not an enum, since the set of platforms and automation tools isn't fixed.
- `resource.componentRef` and `resource.automation` are optional. When a
resource's `provider` is `"kubernetes"` and it carries a `componentRef`,
the frontend links its reference to that component's Kubernetes tab in the
Kubernetes Backstage plugin.
- `automation` lives on each resource, not on the fulfillment as a whole,
because a single POST doesn't have to come from one adapter's work: a
platform composed of several independent adapters (say, separate Kratix
Promises for network policy, certificates, and secrets) can each POST
their own resources for the same condition and environment, and each
resource keeps its own automation provenance.

Every POST is purely additive, nothing is ever looked up by key and
overwritten, so multiple adapters can post to the same profile, condition,
and even the same environment concurrently without racing or clobbering
each other; each POST's resources simply show up alongside whatever else
has already been reported for that condition.

The frontend reads `GET /api/runtime-conditions/fulfillments?profileName=...`.
A single condition can be fulfilled in more than one environment (dev, prod,
federal), each independently, so the conditions table shows how many
distinct environments have reported a fulfillment for that condition, even
if multiple adapters posted to the same one; expanding a row shows a table
of every environment, resource, and automation tool involved. A condition
with no reported fulfillment shows none, it is never inferred.

## Releases

Merging a `feat`, `fix`, `perf`, `revert`, or breaking change to `main`
publishes both packages to npm at the same version, tags the merge commit
`vX.Y.Z`, and creates a GitHub release. Other changes, such as docs or CI, do
not release. Versions follow semantic versioning and come from the PR titles
described in `CONTRIBUTING.md`. Publishing uses npm trusted publishing, so no
token is stored; `CONTRIBUTING.md` lists the one-time setup.
[MIT](LICENSE)
8 changes: 8 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Documentation

- [Usage: critical-path workflows](./usage.md): publish a profile, correlate it to a Component, report and read fulfillments
- [Architecture and API reference](./architecture.md): data flow, internals, `POST`/`GET /api/runtime-conditions/fulfillments`
- [Fulfillment API for adapters](./fulfillment-api.md): backend install, POST/GET contract, validation rules, storage caveat
- [Releases](./releases.md): how versions and npm publishing work

Install and ecosystem links live in the [README](../README.md).
91 changes: 91 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Architecture and API reference

## Data flow

The adapter only writes. The browser only reads. The store is not a separate actor; it is just the backend plugin's memory.

```
Adapter ──POST /fulfillments──▶ backend plugin ──▶ in-memory store (append-only)
▲
Browser ──▶ frontend plugin ────┘── GET /fulfillments?profileName=...
│
└──▶ Kubernetes plugin proxy ──GET /apis/runtimeconditions.io/v1alpha1/runtimeconditionsprofiles
│ (once per configured cluster)
▼
profiles matched to the current entity (workload.uri == source-location)
│
▼
one card per cluster; conditions table joined with fulfillments by condition name
```

## How the pieces work

### Profile fetch

- File: `src/profiles.ts`, function `fetchAllProfiles`
- Calls `kubernetesApi.getClusters()` to list configured clusters.
- Per cluster, calls `kubernetesApi.proxy()` with path `/apis/runtimeconditions.io/v1alpha1/runtimeconditionsprofiles` (the `PROFILES_PATH` constant).
- Non-OK responses are skipped, so clusters without the CRD installed simply contribute nothing.
- Returns one `ProfileDeployment` per profile: `{ cluster, profile }`.

### Correlation

- File: `src/profiles.ts`, functions `entitySourceLocationUrl` and `deploymentsForEntity`
- The Component's `backstage.io/source-location` annotation is parsed with `parseLocationRef`, which strips the `url:` prefix. The result is compared to `profile.workload.uri`.
- Entities without the annotation match nothing. The tab is hidden for them via `isRuntimeConditionsAvailable`.
- Matching is by identity (repo URL), not by Kubernetes labels.

### Fulfillment store

- File: `backend/src/router.ts`
- A plain in-memory array. `POST /fulfillments` validates and appends (returns `201`). `GET /fulfillments` filters by optional `profileName` and `condition` query params.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A plain in-memory array -> This makes me a sad panda. We'll have to address this in the future.

- Ephemeral: a backend restart loses all fulfillments. Adapters should treat POST as "report current state" and re-post after a restart.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is why. We need a durable fulfillment store so that these can survive restarts. Otherwise this is just demoware. I'm glad your documentation effort flagged this.

- File: `backend/src/plugin.ts` registers an auth policy with `allow: 'unauthenticated'` for path `/fulfillments`, so adapters can call without a Backstage session.

### Rendering

- File: `src/components/RuntimeConditionsContent.tsx`
- Extension links: URLs matching `https://runtimeconditions.io/extensions/<ns>/<name>/runtimeconditions.extension.yaml` are rewritten to `https://github.com/runtimeconditions/extensions/blob/main/catalog/rc/<ns>/<ns>-<name>.yaml`. Other URLs are shown as-is.
- Kubernetes deep links: fulfillments with `provider: "kubernetes"` and a `componentRef` render the reference as a link to `/catalog/<namespace>/<kind>/<name>/kubernetes`.
- Conditions table columns: Name, Kind, Interface, Optional, "Fulfilled in". The count is the number of distinct environments that reported a fulfillment for the condition; `none` when zero.
- Expanding a condition row shows a table of every fulfillment resource: Environment, Kind, Provider, Reference (linked as above), Automation.

## API reference

Base path: `/api/runtime-conditions` (backend plugin id `runtime-conditions`).

### `POST /fulfillments`

Registers a fulfillment. Body:

```ts
interface FulfillmentRecord {
profileName: string; // required
profileNamespace?: string; // optional
condition: string; // required; matches profile.conditions[].name
environment: string; // required, e.g. "dev", "prod", "federal"
resources: FulfillingResource[]; // required, non-empty
}
interface FulfillingResource {
kind: string; // required, e.g. "CiliumNetworkPolicy"
provider: string; // required, free-form, e.g. "kubernetes"
reference: string; // required; unique id in its environment
componentRef?: string; // optional, e.g. "component:default/inventory-service"
automation?: { tool: string; reference?: string }; // optional provenance
}
```

Responses:

- `201` with the stored record
- `400` with an error message if validation fails

### `GET /fulfillments?profileName=...&condition=...`

Returns the array of stored records matching the filters (both optional). Always `200`.

## Frontend exports (`src/index.ts`)

- `runtimeConditionsPlugin`: the plugin object created with `createPlugin`. Id: `runtime-conditions`. It registers one route, `entityContent`, which is the mount point for the entity tab.
- `EntityRuntimeConditionsContent`: the routable extension rendered inside the tab. Fetches profiles via the Kubernetes API, correlates them to the current entity, and renders one card per matching cluster.
- `isRuntimeConditionsAvailable(entity)`: route guard for `EntityLayout.Route`. Returns true when the entity has a `backstage.io/source-location` annotation.
64 changes: 64 additions & 0 deletions docs/fulfillment-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Fulfillment API (for adapters)

`backend/` ships as `@runtimeconditions/plugin-runtime-conditions-backend`, a companion backend plugin that adapters report fulfillment to. Install it in `packages/backend`:

```
yarn --cwd packages/backend add @runtimeconditions/plugin-runtime-conditions-backend
```

```ts
backend.add(import('@runtimeconditions/plugin-runtime-conditions-backend'));
```

The plugin registers an auth policy allowing **unauthenticated** access to `/fulfillments`, because adapters call it without a Backstage user session. Restrict this at your ingress or API gateway if the endpoint should not be public.

## Register a fulfillment

```
POST /api/runtime-conditions/fulfillments
{
"profileName": "request-coordinator",
"condition": "available-stock-capability",
"environment": "dev",
"resources": [
{
"kind": "CiliumNetworkPolicy",
"provider": "kubernetes",
"reference": "rc-cilium/applications/request-coordinator-egress",
"componentRef": "component:default/inventory-service",
"automation": { "tool": "kratix", "reference": "cnp-promise" }
}
]
}
```
Comment thread
lasomethingsomething marked this conversation as resolved.
Resolved

Validation rules (the backend returns `400` otherwise):

- Required fields: `profileName`, `condition`, `environment`, and a non-empty `resources` array.
- Each resource requires `kind`, `provider`, and `reference`.
- `resources` is always an array, never a single object. One condition is often fulfilled by several resources, e.g. a `CiliumNetworkPolicy` plus a cert-manager `Certificate` for an API condition, or a database plus a `CiliumNetworkPolicy` plus a `Secret` for a datastore condition.
- `reference` is whatever uniquely identifies the resource in its environment: `cluster/namespace/kind/name` for Kubernetes, an ARN for a cloud resource.
- `provider` and `automation.tool` are free-form strings, not an enum. The set of platforms and automation tools isn't fixed.
- `componentRef` and `automation` are optional. When a resource's `provider` is `"kubernetes"` and it carries a `componentRef`, the frontend links its reference to that component's Kubernetes tab in the Kubernetes Backstage plugin.
- `automation` lives on each resource, not on the fulfillment as a whole. A platform composed of several independent adapters (separate Kratix Promises for network policy, certificates, and secrets) can each POST their own resources for the same condition and environment. Each resource keeps its own automation provenance.

POSTs are purely additive. Nothing is ever looked up by key and overwritten. Multiple adapters can post to the same profile, condition, and even the same environment concurrently without racing or clobbering each other. Each POST's resources show up alongside whatever else has been reported for that condition.

## Read fulfillments

```
GET /api/runtime-conditions/fulfillments?profileName=request-coordinator
GET /api/runtime-conditions/fulfillments?profileName=request-coordinator&condition=datastore
```

Both query params are optional filters. The frontend uses the `profileName` form.

The conditions table shows how many distinct environments have reported a fulfillment for a condition, even if multiple adapters posted to the same one. Expanding a row shows every environment, resource, and automation tool involved. A condition with no reported fulfillment shows none. It is never inferred.

## Example adapter

See `runtimeconditions/rc-demos`, path `cilium-policy/adapter`, for a working adapter that reports CiliumNetworkPolicy fulfillments.

## Storage caveat

The store is in-memory and ephemeral. A backend restart loses all fulfillments. Treat POST as "report current state" and re-post after a restart.
5 changes: 5 additions & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Releases

Merging a `feat`, `fix`, `perf`, `revert`, or breaking change to `main` publishes both packages to npm at the same version, tags the merge commit `vX.Y.Z`, and creates a GitHub release. Other changes, such as docs or CI, do not release.

Versions follow semantic versioning and come from the PR titles described in [CONTRIBUTING.md](../CONTRIBUTING.md). Publishing uses npm trusted publishing, so no token is stored. `CONTRIBUTING.md` lists the one-time setup.
Loading
Loading