kubernetes.networkpolicy.ensure ​
Create or replace a namespaced Kubernetes NetworkPolicy (networking.k8s.io/v1)
Creates a NetworkPolicy in the given namespace; replaces it in full if it already exists. Accepts a pre-built policy_spec dict matching the Kubernetes V1NetworkPolicySpec schema (networking.k8s.io/v1) so callers build the spec however they want.
Why replace and not patch ​
Unlike most *.ensure primitives, this one uses replace_namespaced_network_policy rather than a strategic-merge patch. A NetworkPolicy is a security boundary, and merge semantics silently widen it: spec.podSelector.matchLabels is a map[string]string, so a patch merges it key-by-key and a key removed from the declared spec would linger on the cluster. The resulting policy would select more pods than declared. Full replacement guarantees the live object matches policy_spec exactly, which is what an isolation reconcile has to be able to promise.
An empty spec.podSelector ({}) selects every pod in the namespace — the usual way to express a namespace-wide default-deny. Omitting an ingress or egress rule list while naming that direction in policyTypes denies all traffic in that direction.
Inputs:
- connection_uuid: Cloud connection UUID (required)
- namespace: Target namespace (required)
- name: NetworkPolicy name (required)
- policy_spec: Full V1NetworkPolicySpec dict (required). Supports
podSelector,policyTypes,ingress,egress. - labels: Optional dict of metadata labels set on the object.
Outputs:
- existed: True if an existing NetworkPolicy was replaced, False if created.
Plugin required: context.get_plugin("connection").kubernetes_runner_clients(connection_uuid, organization_uuid) must expose networking_v1 (NetworkingV1Api) with read_namespaced_network_policy, replace_namespaced_network_policy, create_namespaced_network_policy.
Overview ​
| Property | Value |
|---|---|
| Workflow type | Atomic |
| Library | App-kubernetes |
| Version | 1.0 |
Input Schema ​
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
connection_uuid | uuid | Yes | — | — |
namespace | string | Yes | — | — |
name | string | Yes | — | — |
policy_spec | json | Yes | — | — |
labels | json | No | — | — |
organization_uuid | uuid | No | — | — |
Output Schema ​
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
connection_uuid | uuid | No | — | — |
organization_uuid | uuid | No | — | — |
namespace | string | No | — | — |
name | string | No | — | — |
policy_spec | json | No | — | — |
labels | json | No | — | — |
existed | boolean | No | — | — |
failure_reason | string | No | — | — |
failure_type | string | No | — | — |
failed_action | string | No | — | — |
failed_at_state | string | No | — | — |
failed_step | string | No | — | — |
failed_layer | string | No | — | — |
error | string | No | — | — |
error_type | string | No | — | — |
States ​
| State | Initial | Terminal | Success | Auto-advance | Description |
|---|---|---|---|---|---|
pending | Yes | No | — | execute | — |
completed | No | Yes | Yes | — | — |
failed | No | Yes | No | — | — |
State Diagram ​
Transitions ​
| From | Action | To | Description |
|---|---|---|---|
pending | execute | completed | — |
* (any state) | fail | failed | — |
API Usage ​
POST /api/workflows/start
Content-Type: application/json
{
"workflow_type": "kubernetes.networkpolicy.ensure",
"initial_data": {
"connection_uuid": "value",
"namespace": "value",
"name": "value",
"policy_spec": "value"
}
}