Skip to content
Proud to collaborate with Microsoft for Startups

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 ​

PropertyValue
Workflow typeAtomic
LibraryApp-kubernetes
Version1.0

Input Schema ​

FieldTypeRequiredDefaultDescription
connection_uuiduuidYes——
namespacestringYes——
namestringYes——
policy_specjsonYes——
labelsjsonNo——
organization_uuiduuidNo——

Output Schema ​

FieldTypeRequiredDefaultDescription
connection_uuiduuidNo——
organization_uuiduuidNo——
namespacestringNo——
namestringNo——
policy_specjsonNo——
labelsjsonNo——
existedbooleanNo——
failure_reasonstringNo——
failure_typestringNo——
failed_actionstringNo——
failed_at_statestringNo——
failed_stepstringNo——
failed_layerstringNo——
errorstringNo——
error_typestringNo——

States ​

StateInitialTerminalSuccessAuto-advanceDescription
pendingYesNo—execute—
completedNoYesYes——
failedNoYesNo——

State Diagram ​

Transitions ​

FromActionToDescription
pendingexecutecompleted—
* (any state)failfailed—

API Usage ​

bash
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"
  }
}