diff --git a/content/blog/sovereignty-rehydrate-demo/index.md b/content/blog/sovereignty-rehydrate-demo/index.md index 389d287..ebc3abe 100644 --- a/content/blog/sovereignty-rehydrate-demo/index.md +++ b/content/blog/sovereignty-rehydrate-demo/index.md @@ -17,9 +17,9 @@ images: It is 2 a.m. when your on-call team gets an alert that a Region A datacenter is down. The application holding customer data is unreachable, customers are waiting, and someone in leadership is already asking for an ETA. The engineer on -duty opens the provider list and finds a healthy datacenter in Region B at the -top. If you are only looking at infrastructure health, that is where you would -send the workload next. +duty opens the agent list and finds a healthy datacenter in Region B at the top. +If you are only looking at infrastructure health, that is where you would send +the workload next. The workload was never supposed to leave Region A. Whether the constraint comes from GDPR, a data residency requirement, a customer contract, or an internal @@ -52,8 +52,8 @@ We run the scenario on three datacenters split across two regions: | **Region B** | `dc-demo-1` | Healthy, but off limits for this workload | All three start healthy. Here is the twist: **Region B sorts first.** If DCM -only picked the first available provider, every new deployment would land there -by default. That is exactly the trap the sovereignty policy is meant to prevent. +only picked the first available agent, every new deployment would land there by +default. That is exactly the trap the sovereignty policy is meant to prevent. ![Two regions: Region B with dc-demo-1 (sorts first), Region A with dc-demo-2 and dc-demo-3](setup-regions.png) @@ -76,34 +76,39 @@ If the request does not specify a target region, the policy rejects it. Sovereignty is mandatory from day one, not something you bolt on after an audit finding. -### Only healthy providers in the right region +### Only healthy agents in the right region -The policy asks the provider registry what is available, then filters the list. -Providers in the wrong region drop out, even if they are healthy. Providers in -the right region must also be `ready`. Region B never makes the shortlist for a +The policy asks the agent registry what is available, then filters the list. +Agents in the wrong region drop out, even if they are healthy. Agents in the +right region must also be `ready`. Region B never makes the shortlist for a Region A workload. ### First match wins (within the region) -Among the survivors, the policy picks the first provider alphabetically. That is +Among the survivors, the policy picks the first agent alphabetically. That is why the initial deploy lands on `dc-demo-2`, and why failover moves to `dc-demo-3` when `dc-demo-2` fails. {{< callout type="warning" >}} **What if an entire region goes down?** -If no healthy provider exists in the requested region, the request is rejected -with a clear error. DCM will not silently fail over across a regional boundary -to "help." That is the point. A hard failure is easier to explain to a -compliance officer than a quiet data residency violation. {{< /callout >}} +If no healthy agent exists in the requested region, the request is rejected with +a clear error. DCM will not silently fail over across a regional boundary to +"help." That is the point. A hard failure is easier to explain to a compliance +officer than a quiet data residency violation. {{< /callout >}} + +> **Setup note:** Each environment agent's `environment` field must be set to +> its region code at registration time (for example `AGENT_ENVIRONMENT=region-a` +> in the compose `.env`). This is the value the policy reads to enforce +> sovereignty placement. {{% details title="View the full Rego policy" closed="true" %}} ```rego -package provider.sovereignty +package agent.sovereignty import rego.v1 -spm_url := "http://control-plane:8080/api/v1alpha1/providers" +agents_url := "http://control-plane:8080/api/v1alpha1/agents" main := {"rejected": true, "rejection_reason": "spec.service_type is required"} if { not input.spec.service_type @@ -120,30 +125,31 @@ main := result if { response := http.send({ "method": "GET", - "url": sprintf("%s?type=%s", [spm_url, service_type]), + "url": agents_url, "headers": {"Accept": "application/json"}, }) - providers := response.body.providers + agents := response.body.agents - region_providers := [p | - some p in providers - p.health_status == "ready" - p.metadata.region_code == requested_region + region_agents := [a | + some a in agents + a.health_status == "ready" + service_type in a.service_types + a.environment == requested_region ] - result := _providers_result(region_providers, service_type, requested_region) + result := _agents_result(region_agents, service_type, requested_region) } -_providers_result(providers, service_type, region) := {"rejected": true, "rejection_reason": msg} if { - count(providers) == 0 - msg := sprintf("no ready providers in region '%s' for service type '%s'", [region, service_type]) +_agents_result(agents, service_type, region) := {"rejected": true, "rejection_reason": msg} if { + count(agents) == 0 + msg := sprintf("no ready agents in environment '%s' for service type '%s'", [region, service_type]) } -_providers_result(providers, _, _) := {"rejected": false, "selected_provider": provider} if { - count(providers) > 0 - sorted_names := sort([p.name | some p in providers]) - provider := sorted_names[0] +_agents_result(agents, _, _) := {"rejected": false, "selected_agent": agent} if { + count(agents) > 0 + sorted_names := sort([a.name | some a in agents]) + agent := sorted_names[0] } ``` @@ -164,7 +170,7 @@ source of truth for everything that follows. ### 2. Simulate the outage -Take `dc-demo-2` offline (`podman stop` on the provider containers). Region B is +Take `dc-demo-2` offline (`podman stop` on the agent containers). Region B is still healthy and still first on the list. In a typical setup, that is where the story ends and the compliance review begins. @@ -216,7 +222,7 @@ it holds on a quiet Tuesday. The rules do not relax because the pager is loud. The best way to get a feel for the flow is our [interactive walkthrough](https://interact.redhat.com/share/yFwS2KKEs4Zvjc3USx5j). -Click through the DCM UI at your own pace: explore the providers, create the +Click through the DCM UI at your own pace: explore the agents, create the policy, deploy Pet Clinic, and watch where the app lands. The walkthrough covers almost the entire scenario in the browser, including diff --git a/content/docs/getting-started/_index.md b/content/docs/getting-started/_index.md index d0ec069..07c0edf 100644 --- a/content/docs/getting-started/_index.md +++ b/content/docs/getting-started/_index.md @@ -15,7 +15,7 @@ Get up and running with DCM. - **[Create Small VM Catalog Item](create-small-vm-catalog-item/)** — Define and create a catalog item for a small virtual machine. - **[Create Placement Policy](create-placement-policy/)** — Define a placement - policy to route instances to the KubeVirt service provider. + policy to route instances to the local environment agent. - **[Create Instance of Small VM Catalog Item](create-small-vm-instance/)** — Deploy a VM by creating an instance of the catalog item. - **[Register Another Provider](register-another-provider/)** — Register a diff --git a/content/docs/getting-started/architecture.md b/content/docs/getting-started/architecture.md index 3fa3fac..11967f8 100644 --- a/content/docs/getting-started/architecture.md +++ b/content/docs/getting-started/architecture.md @@ -5,8 +5,8 @@ weight: 1 --- DCM (Data Center Management) is a control plane for managing infrastructure -services across multiple providers. This page gives a high-level overview of how -the components fit together. +services across multiple environment agents. This page gives a high-level +overview of how the components fit together. ## Components @@ -18,7 +18,8 @@ graph TD CM["Catalog Manager"] PM["Policy Manager"] PLM["Placement Manager"] - SPM["Service Provider Manager"] + AM["Agent Manager"] + RM["SP Resource Manager"] end subgraph Infrastructure @@ -26,9 +27,9 @@ graph TD NATS["NATS"] end - subgraph Providers - SP1["KubeVirt SP 1"] - SP2["KubeVirt SP 2"] + subgraph Agents + EA1["Environment Agent 1"] + EA2["Environment Agent 2"] end User --> CP @@ -36,31 +37,33 @@ graph TD CM --> PG PM --> PG PLM --> PG - SPM --> PG + AM --> PG + RM --> PG PLM --> PM - PLM --> SPM + PLM --> AM CM --> PLM - SPM --> NATS - SP1 --> NATS - SP2 --> NATS - SP1 -->|self-register| SPM - SP2 -->|self-register| SPM + RM --> NATS + EA1 --> NATS + EA2 --> NATS + EA1 -->|register| AM + EA2 -->|register| AM ``` ## Component Responsibilities -| Component | Role | -| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | -| **Control Plane** | Single process that exposes all DCM APIs on `:8080`. Hosts the catalog, policy, placement, and service provider managers in one binary. | -| **Catalog Manager** | Manages service types, catalog items, and catalog item instances. Triggers placement when an instance is created. | -| **Policy Manager** | Stores placement policies (Rego) and evaluates them via an embedded OPA engine. | -| **Placement Manager** | Selects a service provider for a new instance by evaluating policies against available providers. | -| **Service Provider Manager** | Tracks registered service providers and their health status. | -| **PostgreSQL** | Persistent storage for the control plane. | -| **NATS** | Message bus for communication between the Service Provider Manager and service providers. | -| **Service Providers** | External systems (e.g., KubeVirt) that create and manage the actual resources (VMs, containers, etc.). | +| Component | Role | +| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| **Control Plane** | Single process that exposes all DCM APIs on `:8080`. Hosts the catalog, policy, placement, agent, and SP resource managers in one binary. | +| **Catalog Manager** | Manages service types, catalog items, and catalog item instances. Triggers placement when an instance is created. | +| **Policy Manager** | Stores placement policies (Rego) and evaluates them via an embedded OPA engine. | +| **Placement Manager** | Selects an environment agent for a new instance by evaluating policies against available agents. | +| **Agent Manager** | Tracks registered environment agents and their health status. | +| **SP Resource Manager** | Manages the lifecycle of resources on service providers through environment agents. | +| **PostgreSQL** | Persistent storage for the control plane. | +| **NATS** | Message bus for communication between the SP Resource Manager and environment agents. | +| **Environment Agents** | Agents that bridge the control plane and service providers (e.g., KubeVirt). They register with the control plane and manage the actual resources (VMs, containers, etc.). | ## Request Flow @@ -73,22 +76,25 @@ sequenceDiagram participant CM as Catalog Manager participant PLM as Placement Manager participant PM as Policy Manager - participant SPM as SP Manager + participant RM as SP Resource Manager + participant EA as Environment Agent participant SP as KubeVirt SP User->>CP: Create catalog item instance CP->>CM: POST /catalog-item-instances CM->>PLM: Request placement PLM->>PM: Evaluate policies (embedded OPA) - PM-->>PLM: Placement decision - PLM->>SPM: Create resource on provider - SPM->>SP: Create VM + PM-->>PLM: Placement decision (selected agent) + PLM->>RM: Create resource on agent + RM->>EA: Provision via NATS + EA->>SP: Create VM SP-->>User: VM scheduling ``` 1. The **Catalog Manager** receives the request and asks the **Placement - Manager** to find a suitable provider. + Manager** to find a suitable agent. 2. The **Placement Manager** evaluates placement policies through the **Policy Manager**, which uses an embedded OPA engine to evaluate Rego. -3. Once a provider is selected, the resource is created on that provider through - the **Service Provider Manager**. +3. Once an agent is selected, the resource is created through the **SP Resource + Manager**, which sends the request to the **environment agent** via NATS. The + agent provisions the resource on the underlying service provider. diff --git a/content/docs/getting-started/create-placement-policy.md b/content/docs/getting-started/create-placement-policy.md index 5f9abfb..8dd1f04 100644 --- a/content/docs/getting-started/create-placement-policy.md +++ b/content/docs/getting-started/create-placement-policy.md @@ -4,11 +4,11 @@ type: docs weight: 4 --- -Placement policies control how DCM decides which service provider should handle +Placement policies control how DCM decides which environment agent should handle a catalog item instance. Policies are written in [Rego](https://www.openpolicyagent.org/docs/latest/policy-language/), the policy language used by Open Policy Agent (OPA). Each policy can accept or reject a -placement request and optionally select a specific provider. +placement request and optionally select a specific agent. Policies have a `priority` — lower values are evaluated first. @@ -17,24 +17,28 @@ Policies have a `priority` — lower values are evaluated first. Create a file called `kubevirt-policy.yaml` with the following content: ```yaml -display_name: kubevirt-provider +display_name: local-agent policy_type: GLOBAL priority: 1 rego_code: | - package kubevirt + package local main := { "rejected": false, - "selected_provider": "kubevirt-service-provider" + "selected_agent": "local-agent" } ``` This policy: - Has the highest priority (`1`) -- Always selects `kubevirt-service-provider` as the target service provider +- Always selects `local-agent` as the target agent - Never rejects a request (`rejected: false`) +> **Note:** The `selected_agent` value must match the name the environment agent +> registered under. The compose stack defaults to `local-agent` (`AGENT_NAME` in +> `.env`). Verify with `curl http://localhost:8080/api/v1alpha1/agents | jq`. + ## Create the Policy ```bash diff --git a/content/docs/getting-started/local-setup.md b/content/docs/getting-started/local-setup.md index 532a412..f10e46a 100644 --- a/content/docs/getting-started/local-setup.md +++ b/content/docs/getting-started/local-setup.md @@ -16,12 +16,26 @@ Learn how to set up and run DCM on your local machine. ## Quick Start Clone the [control-plane](https://github.com/dcm-project/control-plane) -repository and start the core platform (postgres, nats, control-plane, and -dcm-ui): +repository, prepare the environment file, and start the core platform (postgres, +nats, control-plane, and dcm-ui): ```bash git clone https://github.com/dcm-project/control-plane.git cd control-plane/deploy +cp .env.example .env +``` + +To use the m2 release images, add the following to your `.env` file: + +```ini +CONTROL_PLANE_VERSION=m2 +ENVIRONMENT_AGENT_VERSION=m2 +DCM_UI_VERSION=m2 +``` + +Then start the stack: + +```bash podman-compose up -d ``` diff --git a/content/docs/getting-started/register-another-provider.md b/content/docs/getting-started/register-another-provider.md index 3a82abc..80cfb03 100644 --- a/content/docs/getting-started/register-another-provider.md +++ b/content/docs/getting-started/register-another-provider.md @@ -4,6 +4,12 @@ type: docs weight: 6 --- +> **Note:** This page describes the legacy service-provider model where +> providers register directly with the control plane. With the environment-agent +> architecture, providers register with the +> [environment agent](/docs/getting-started/architecture/) instead, and the +> control plane manages agents. A rewrite of this guide is planned. + In DCM, service providers self-register by calling the Service Provider Manager API. When you started the KubeVirt service provider in the [Local Setup](../local-setup/), it automatically registered itself. In this @@ -58,14 +64,14 @@ rego_code: | import rego.v1 - providers := ["kubevirt-service-provider", "another-kubevirt-provider"] + agents := ["kubevirt-service-provider", "another-kubevirt-provider"] main := { "rejected": false, - "selected_provider": providers[idx] + "selected_agent": agents[idx] } - idx := round(rand.intn("seed", count(providers))) + idx := round(rand.intn("seed", count(agents))) ``` This Rego policy: diff --git a/content/docs/user-guide/catalog-item-instances.md b/content/docs/user-guide/catalog-item-instances.md index 243dd00..b0910b7 100644 --- a/content/docs/user-guide/catalog-item-instances.md +++ b/content/docs/user-guide/catalog-item-instances.md @@ -37,25 +37,29 @@ display_name: "My Dev VM" spec: catalog_item_id: small-vm user_values: - - path: metadata + - resource: main + path: metadata value: name: "demo" labels: env: "dev" - - path: vcpu.count + - resource: main + path: vcpu.count value: 1 - - path: guest_os.type + - resource: main + path: guest_os.type value: fedora ``` ### Key Fields -| Field | Purpose | -| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -| `display_name` | An optional human-readable name shown in listings and the UI. | -| `spec.catalog_item_id` | References the UID of an existing catalog item to deploy from. | -| `spec.user_values` | Sets of overrides for fields allowed by the catalog item's `fields` array. Only fields with `editable: true` can be customized here. | -| `spec.user_values[].path` | Path corresponding to the `path` key in the `catalog_item`'s `fields` item | +| Field | Purpose | +| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | +| `display_name` | An optional human-readable name shown in listings and the UI. | +| `spec.catalog_item_id` | References the UID of an existing catalog item to deploy from. | +| `spec.user_values` | Sets of overrides for fields allowed by the catalog item's `fields` array. Only fields with `editable: true` can be customized here. | +| `spec.user_values[].resource` | Name of the resource within the catalog item this override applies to (e.g., `main`). | +| `spec.user_values[].path` | Path corresponding to the `path` key in the catalog item resource's `fields` item. | > **Note:** Each value provided in `user_values` will be validated against its > corresponding item in the catalog item's `fields` list. If the `field` is not @@ -147,6 +151,7 @@ Example JSON output: "catalog_item_id": "small-vm", "user_values": [ { + "resource": "main", "path": "metadata", "value": { "labels": { @@ -156,10 +161,12 @@ Example JSON output: } }, { + "resource": "main", "path": "vcpu.count", "value": 1 }, { + "resource": "main", "path": "guest_os.type", "value": "fedora" } diff --git a/content/docs/user-guide/catalog-items.md b/content/docs/user-guide/catalog-items.md index 7a21412..46b8b8b 100644 --- a/content/docs/user-guide/catalog-items.md +++ b/content/docs/user-guide/catalog-items.md @@ -33,63 +33,68 @@ Below is a complete catalog item definition for a small virtual machine: api_version: v1alpha1 display_name: "Small VM" spec: - service_type: vm - fields: - - path: metadata - editable: true - - path: vcpu.count - display_name: "CPU Count" - editable: true - default: 2 - validation_schema: - type: integer - minimum: 1 - maximum: 4 - - path: memory.size - display_name: "Memory (GB)" - editable: false - default: "2GB" - - path: storage.disks - display_name: "Storage (GB)" - editable: false - default: - - name: boot - capacity: "20GB" - validation_schema: - type: array - - path: guest_os.type - display_name: "Guest OS" - editable: true - validation_schema: - type: string - enum: - - fedora - - centos - - ubuntu + resources: + - name: main + service_type: vm + fields: + - path: metadata + editable: true + - path: vcpu.count + display_name: "CPU Count" + editable: true + default: 2 + validation_schema: + type: integer + minimum: 1 + maximum: 4 + - path: memory.size + display_name: "Memory (GB)" + editable: false + default: "2GB" + - path: storage.disks + display_name: "Storage (GB)" + editable: false + default: + - name: boot + capacity: "20GB" + validation_schema: + type: array + - path: guest_os.type + display_name: "Guest OS" + editable: true + validation_schema: + type: string + enum: + - fedora + - centos + - ubuntu ``` ### Key Sections -| Section | Purpose | -| --------------------------------- | ------------------------------------------------------------------------------------- | -| `api_version` | Ties the catalog item to a specific schema version (e.g., `v1alpha1`). | -| `display_name` | A human-readable name shown in listings and the UI. | -| `spec.service_type` | Corresponding service type | -| `spec.fields` | List of fields with const or user values | -| `spec.fields[].path` | Path of the field within the `service_type` specification | -| `spec.fields[].display_name` | A human-readable name shown in listings and the UI | -| `spec.fields[].editable` | Specify whether the user may edit the value | -| `spec.fields[].default` | Default value for the field. When `editable` is `false` this becomes the actual value | -| `spec.fields[].validation_schema` | JSON Schema rules to validate input. See: https://json-schema.org/ | +| Section | Purpose | +| --------------------------------------------- | -------------------------------------------------------------------------------------- | +| `api_version` | Ties the catalog item to a specific schema version (e.g., `v1alpha1`). | +| `display_name` | A human-readable name shown in listings and the UI. | +| `spec.resources` | List of resources the catalog item defines. | +| `spec.resources[].name` | Unique name for the resource within this catalog item (e.g., `main`). | +| `spec.resources[].service_type` | Corresponding service type for this resource. | +| `spec.resources[].fields` | List of fields with const or user values. | +| `spec.resources[].fields[].path` | Path of the field within the `service_type` specification. | +| `spec.resources[].fields[].display_name` | A human-readable name shown in listings and the UI. | +| `spec.resources[].fields[].editable` | Specify whether the user may edit the value. | +| `spec.resources[].fields[].default` | Default value for the field. When `editable` is `false` this becomes the actual value. | +| `spec.resources[].fields[].validation_schema` | JSON Schema rules to validate input. See: https://json-schema.org/ | ### Fields and Policy Evaluation Catalog item fields define the governance boundary for placement policies. When DCM builds the resource spec that policies evaluate, it includes **only** two -sources: +sources for each resource: -1. **Field defaults** declared in the catalog item -2. **user_values** overrides provided at instance creation +1. **Field defaults** declared in the catalog item resource +2. **user_values** overrides provided at instance creation (scoped by resource + name) Anything not declared as a catalog item field is invisible to the policy engine, even if set elsewhere on the instance request. This means labels must be exposed @@ -170,52 +175,57 @@ Example JSON output: "display_name": "Small VM", "path": "catalog-items/small-vm", "spec": { - "fields": [ + "resources": [ { - "editable": true, - "path": "metadata" - }, - { - "default": 2, - "display_name": "CPU Count", - "editable": true, - "path": "vcpu.count", - "validation_schema": { - "maximum": 4, - "minimum": 1, - "type": "integer" - } - }, - { - "default": "2GB", - "display_name": "Memory (GB)", - "path": "memory.size" - }, - { - "default": [ + "name": "main", + "service_type": "vm", + "fields": [ + { + "editable": true, + "path": "metadata" + }, { - "capacity": "20GB", - "name": "boot" + "default": 2, + "display_name": "CPU Count", + "editable": true, + "path": "vcpu.count", + "validation_schema": { + "maximum": 4, + "minimum": 1, + "type": "integer" + } + }, + { + "default": "2GB", + "display_name": "Memory (GB)", + "path": "memory.size" + }, + { + "default": [ + { + "capacity": "20GB", + "name": "boot" + } + ], + "display_name": "Storage (GB)", + "path": "storage.disks", + "validation_schema": { + "type": "array" + } + }, + { + "default": "fedora", + "display_name": "Guest OS", + "editable": true, + "path": "guest_os.type", + "validation_schema": { + "enum": ["fedora", "centos", "ubuntu"], + "type": "string" + } } - ], - "display_name": "Storage (GB)", - "path": "storage.disks", - "validation_schema": { - "type": "array" - } - }, - { - "default": "fedora", - "display_name": "Guest OS", - "editable": true, - "path": "guest_os.type", - "validation_schema": { - "enum": ["fedora", "centos", "ubuntu"], - "type": "string" - } + ] } - ], - "service_type": "vm" + ] }, "uid": "small-vm", "update_time": "2026-04-15T18:06:02.434302Z" diff --git a/content/docs/user-guide/policies.md b/content/docs/user-guide/policies.md index c3e021f..20887bc 100644 --- a/content/docs/user-guide/policies.md +++ b/content/docs/user-guide/policies.md @@ -6,10 +6,10 @@ weight: 5 Policies are [Rego](https://www.openpolicyagent.org/docs/latest/policy-language/) rules (the -OPA policy language) that validate service provider resources and control where -they are placed. During the placement flow, DCM evaluates all enabled policies -in priority order (lower number = evaluated first). A policy can reject a -request or select a specific provider for it. It may also alter or set values. +OPA policy language) that validate resources and control where they are placed. +During the placement flow, DCM evaluates all enabled policies in priority order +(lower number = evaluated first). A policy can reject a request or select a +specific environment agent for it. It may also alter or set values. ## Creating a Policy @@ -19,15 +19,15 @@ Here is an example policy file: ```yaml # policy.yaml -display_name: Provider +display_name: Agent Selector policy_type: GLOBAL priority: 1 rego_code: | - package provider.selector + package agent.selector import rego.v1 - spm_url := "http://control-plane:8080/api/v1alpha1/providers" + agents_url := "http://control-plane:8080/api/v1alpha1/agents" main := {"rejected": true, "rejection_reason": "spec.service_type is required"} if { not input.spec.service_type @@ -37,40 +37,44 @@ rego_code: | service_type := input.spec.service_type response := http.send({ "method": "GET", - "url": sprintf("%s?type=%s", [spm_url, service_type]), + "url": agents_url, "headers": {"Accept": "application/json"}, }) - providers := response.body.providers - ready_providers := [p | some p in providers; p.health_status == "ready"] - result := _providers_result(ready_providers, service_type) + agents := response.body.agents + ready_agents := [a | + some a in agents + a.health_status == "ready" + service_type in a.service_types + ] + result := _agents_result(ready_agents, service_type) } - _providers_result(providers, service_type) := {"rejected": true, "rejection_reason": msg} if { - count(providers) == 0 - msg := sprintf("no ready providers found for service type '%s'", [service_type]) + _agents_result(agents, service_type) := {"rejected": true, "rejection_reason": msg} if { + count(agents) == 0 + msg := sprintf("no ready agents found for service type '%s'", [service_type]) } - _providers_result(providers, _) := {"rejected": false, "selected_provider": provider} if { - count(providers) > 0 - sorted_names := sort([p.name | some p in providers]) - provider := sorted_names[0] + _agents_result(agents, _) := {"rejected": false, "selected_agent": agent} if { + count(agents) > 0 + sorted_names := sort([a.name | some a in agents]) + agent := sorted_names[0] } ``` -> **Note:** This Rego code assumes it can access the control-plane provider API -> to get the list of providers. Then, it filters only the `ready` ones, sorts -> alphabetically and returns the first one +> **Note:** This Rego code calls the control-plane agent API, filters for agents +> that are `ready` and support the requested service type, sorts alphabetically, +> and returns the first one ### Field Reference -| Field | Description | -| ---------------- | ----------------------------------------------------------------------------------------------------------------------------- | -| `display_name` | A human-readable name for the policy. | -| `policy_type` | The scope of policy (e.g., `GLOBAL`). | -| `priority` | Evaluation order. Lower numbers are evaluated first. | -| `enabled` | Whether the policy is active (`true` or `false`). | -| `rego_code` | The Rego source code. Must define a `main` rule with `rejected`, and either `rejection_reason` or `selected_provider` fields. | -| `label_selector` | `key:value` pairs used to match between the policy and the `metadata.labels` field of the provisioned resource | +| Field | Description | +| ---------------- | -------------------------------------------------------------------------------------------------------------------------- | +| `display_name` | A human-readable name for the policy. | +| `policy_type` | The scope of policy (e.g., `GLOBAL`). | +| `priority` | Evaluation order. Lower numbers are evaluated first. | +| `enabled` | Whether the policy is active (`true` or `false`). | +| `rego_code` | The Rego source code. Must define a `main` rule with `rejected`, and either `rejection_reason` or `selected_agent` fields. | +| `label_selector` | `key:value` pairs used to match between the policy and the `metadata.labels` field of the provisioned resource | > **Note:** `label_selector` may also use the `service_type` key to match based > on the resource's `service_type` @@ -83,12 +87,12 @@ The `main` rule receives an `input` object and must return an output object. The `input` object includes: -| Field | Description | -| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ | -| `spec` | The current (patched) request payload. While policies do not have to be specific for service types, they will need to know the expected content. | -| `constraints` | The accumulated constraints context from prior policies in the chain. | -| `provider` | The currently selected service provider (empty string initially, populated as policies are evaluated). | -| `service_provider_constraints` | The accumulated service-provider constraints from prior policies. | +| Field | Description | +| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | +| `spec` | The current (patched) request payload. While policies do not have to be specific for service types, they will need to know the expected content. | +| `constraints` | The accumulated constraints context from prior policies in the chain. | +| `agent` | The currently selected environment agent (empty string initially, populated as policies are evaluated). | +| `agent_constraints` | The accumulated agent constraints from prior policies. | ##### How `input.spec` is Constructed @@ -113,26 +117,31 @@ for more on declaring fields. The following end-to-end example shows how a `region` label flows from a catalog item field declaration through an instance and into a Rego policy. -**1. Catalog item field** — declares `metadata.labels.region` with allowed -values: +**1. Catalog item resource field** — declares `metadata.labels.region` with +allowed values: ```yaml -fields: - - path: metadata.labels.region - display_name: "Deployment Region" - editable: true - validation_schema: - type: string - enum: - - region-a - - region-b +spec: + resources: + - name: main + service_type: vm + fields: + - path: metadata.labels.region + display_name: "Deployment Region" + editable: true + validation_schema: + type: string + enum: + - region-a + - region-b ``` **2. Instance user_values** — sets the region at deployment time: ```yaml user_values: - - path: metadata.labels.region + - resource: main + path: metadata.labels.region value: region-a ``` @@ -147,9 +156,9 @@ main := {"rejected": true, "rejection_reason": "region label is required"} if { not input.spec.metadata.labels.region } -main := {"rejected": false, "selected_provider": provider} if { +main := {"rejected": false, "selected_agent": agent} if { region := input.spec.metadata.labels.region - provider := sprintf("provider-%s", [region]) + agent := sprintf("agent-%s", [region]) } ``` @@ -161,16 +170,16 @@ main := {"rejected": false, "selected_provider": provider} if { The `main` rule must return an object with the following fields: -| Field | Type | Required | Description | -| ------------------------------ | ------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `rejected` | boolean | Yes | Set to `true` to reject the placement request. Requests are approved by default. | -| `rejection_reason` | string | No | A human-readable reason when the request is rejected. | -| `selected_provider` | string | No | The name of the service provider chosen to fulfill the request. | -| `service_provider_constraints` | object | No | Constraints on which service providers are allowed. Contains `allow_list` (list of allowed provider names) and `patterns` (list of regex patterns for matching allowed providers). | -| `patch` | map | No | A dictionary of values to set or override in the request payload. | -| `constraints` | map | No | Field constraints for subsequent policies, following [JSON Schema (draft 2020-12)](https://json-schema.org/draft/2020-12/json-schema-validation). Supports `const` (immutable), numeric constraints (`minimum`, `maximum`, `multipleOf`), string patterns (`pattern`, `minLength`, `maxLength`), enumerations (`enum`), array constraints (`minItems`, `maxItems`), and conditional logic (`if`/`then`/`else`). | +| Field | Type | Required | Description | +| ------------------- | ------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `rejected` | boolean | Yes | Set to `true` to reject the placement request. Requests are approved by default. | +| `rejection_reason` | string | No | A human-readable reason when the request is rejected. | +| `selected_agent` | string | No | The name of the environment agent chosen to fulfill the request. | +| `agent_constraints` | object | No | Constraints on which environment agents are allowed. Contains `allow_list` (list of allowed agent names), `patterns` (list of regex patterns for matching allowed agents), and `environment_constraints` (list of allowed environment values, matched against each agent's `environment` field, intersected across policies). | +| `patch` | map | No | A dictionary of values to set or override in the request payload. | +| `constraints` | map | No | Field constraints for subsequent policies, following [JSON Schema (draft 2020-12)](https://json-schema.org/draft/2020-12/json-schema-validation). Supports `const` (immutable), numeric constraints (`minimum`, `maximum`, `multipleOf`), string patterns (`pattern`, `minLength`, `maxLength`), enumerations (`enum`), array constraints (`minItems`, `maxItems`), and conditional logic (`if`/`then`/`else`). | -> **Note:** While no single policy is required to set the `selected_provider` +> **Note:** While no single policy is required to set the `selected_agent` > field, the combination of all processed policies must set one; otherwise, > placement will fail. @@ -255,13 +264,13 @@ dcm policy get prefer-provider-a -o json ```json { "create_time": "2026-04-15T18:38:13.990296Z", - "display_name": "Provider", + "display_name": "Agent Selector", "enabled": true, "id": "7eff7e73-4c14-4311-8673-e03916b00ece", "path": "policies/7eff7e73-4c14-4311-8673-e03916b00ece", "policy_type": "GLOBAL", "priority": 1, - "rego_code": "package provider.selector\n\nimport rego.v1\n\nspm_url := \"http://control-plane:8080/api/v1alpha1/providers\"\n\nmain := {\"rejected\": true, \"rejection_reason\": \"spec.service_type is required\"} if {\n not input.spec.service_type\n}\n\nmain := result if {\n service_type := input.spec.service_type\n response := http.send({\n \"method\": \"GET\",\n \"url\": sprintf(\"%s?type=%s\", [spm_url, service_type]),\n \"headers\": {\"Accept\": \"application/json\"},\n })\n providers := response.body.providers\n ready_providers := [p | some p in providers; p.health_status == \"ready\"]\n result := _providers_result(ready_providers, service_type)\n}\n\n_providers_result(providers, service_type) := {\"rejected\": true, \"rejection_reason\": msg} if {\n count(providers) == 0\n msg := sprintf(\"no ready providers found for service type '%s'\", [service_type])\n}\n\n_providers_result(providers, _) := {\"rejected\": false, \"selected_provider\": provider} if {\n count(providers) \u003e 0\n sorted_names := sort([p.name | some p in providers])\n provider := sorted_names[0]\n}\n", + "rego_code": "package agent.selector\n\nimport rego.v1\n\nagents_url := \"http://control-plane:8080/api/v1alpha1/agents\"\n\nmain := {\"rejected\": true, \"rejection_reason\": \"spec.service_type is required\"} if {\n not input.spec.service_type\n}\n\nmain := result if {\n service_type := input.spec.service_type\n response := http.send({\n \"method\": \"GET\",\n \"url\": agents_url,\n \"headers\": {\"Accept\": \"application/json\"},\n })\n agents := response.body.agents\n ready_agents := [a | some a in agents; a.health_status == \"ready\"; service_type in a.service_types]\n result := _agents_result(ready_agents, service_type)\n}\n\n_agents_result(agents, service_type) := {\"rejected\": true, \"rejection_reason\": msg} if {\n count(agents) == 0\n msg := sprintf(\"no ready agents found for service type '%s'\", [service_type])\n}\n\n_agents_result(agents, _) := {\"rejected\": false, \"selected_agent\": agent} if {\n count(agents) \u003e 0\n sorted_names := sort([a.name | some a in agents])\n agent := sorted_names[0]\n}\n", "update_time": "2026-04-15T18:38:13.990296Z" } ``` @@ -328,9 +337,8 @@ number = evaluated first). For each policy in order, the engine performs the following steps: 1. **Evaluate** the policy's Rego code. The `input` object includes the current - patched `spec`, the accumulated `constraints`, the currently - `selected_provider` (empty string initially), and the accumulated - `service_provider_constraints`. + patched `spec`, the accumulated `constraints`, the currently selected `agent` + (empty string initially), and the accumulated `agent_constraints`. 2. **Check rejection.** If the policy sets `rejected` to `true`, the placement request is denied immediately and the `rejection_reason` is returned to the caller. No further policies are evaluated. @@ -344,12 +352,12 @@ For each policy in order, the engine performs the following steps: immutable using a `const` constraint, any attempt to patch that field causes a policy conflict error. 6. **Apply patch.** Valid patches are applied to the request payload. -7. **Validate service provider.** If the policy returned a `selected_provider` - and `service_provider_constraints` exist from prior policies, the selected - provider is validated against those constraints. +7. **Validate agent.** If the policy returned a `selected_agent` and + `agent_constraints` exist from prior policies, the selected agent is + validated against those constraints. After all policies have been evaluated, the engine returns the final payload, -the selected provider, and the evaluation status to the Placement Manager. The +the selected agent, and the evaluation status to the Placement Manager. The status is `APPROVED` if the payload was not modified, or `MODIFIED` if any patches were applied. diff --git a/layouts/shortcodes/remoteMD.html b/layouts/shortcodes/remoteMD.html index f6930b6..158c0c7 100644 --- a/layouts/shortcodes/remoteMD.html +++ b/layouts/shortcodes/remoteMD.html @@ -1,6 +1,12 @@ {{ $url := .Get "url" }} +{{ $browseBase := "" }} {{ with .Get "base" }} - {{ $url = printf "%s/%s" (index site.Params .) $url }} + {{ $rawBase := index site.Params . }} + {{ $url = printf "%s/%s" $rawBase $url }} + {{/* Derive the GitHub browse URL from the raw-content URL so relative + cross-references inside the fetched Markdown can be rewritten to + point at the source repository instead of the generated site. */}} + {{ $browseBase = replaceRE "raw\\.githubusercontent\\.com/([^/]+)/([^/]+)/([^/]+)" "github.com/$1/$2/blob/$3" $rawBase }} {{ end }} {{ $resource := resources.GetRemote $url }} {{ if $resource }} @@ -15,6 +21,15 @@ {{/* Fix card shape syntax that breaks Mermaid - only within mermaid blocks */}} {{ $content = replaceRE "(```mermaid[\\s\\S]*?)@\\{[^}]+\\}([\\s\\S]*?```)" "${1}${2}" $content }} + {{/* Rewrite cross-reference links to point to the source repository. + Enhancement files sit one directory deep, so ../ resolves to the + enhancements root. Some files also use root-absolute paths like + /enhancements/other/other.md — rewrite those too. */}} + {{ if $browseBase }} + {{ $content = replaceRE "\\]\\(\\.\\./" (printf "](%s/" $browseBase) $content }} + {{ $content = replaceRE "\\]\\(/enhancements/" (printf "](%s/" $browseBase) $content }} + {{ end }} + {{/* Use RenderString instead of markdownify so that render hooks (including Mermaid) are applied */}} {{ .Page.RenderString $content }} {{ else }}