{
  "description": "Plugin defines a KubeVirt extension that can modify VM domain XML,\nhook into VM lifecycle events, and reference admission objects.",
  "properties": {
    "apiVersion": {
      "description": "APIVersion defines the versioned schema of this representation of an object.\nServers should convert recognized schemas to the latest internal value, and\nmay reject unrecognized values.\nMore info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
      "type": "string"
    },
    "kind": {
      "description": "Kind is a string value representing the REST resource this object represents.\nServers may infer this from the endpoint the client submits requests to.\nCannot be updated.\nIn CamelCase.\nMore info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
      "type": "string"
    },
    "metadata": {
      "type": "object"
    },
    "spec": {
      "description": "Spec defines the plugin's hooks and admission references.",
      "properties": {
        "condition": {
          "description": "Condition is a CEL expression that determines whether this plugin applies to a given VM.\nThe expression may reference only 'vmi' and must evaluate to a bool.\nWhen set, this acts as a baseline filter for all hooks in the plugin.\nIndividual hooks may further narrow the scope with their own Condition fields.\nAn empty condition always matches.",
          "type": "string"
        },
        "failureStrategy": {
          "description": "FailureStrategy specifies the default behavior when one of the plugin's launcher or node hooks fails\n(e.g. its socket is unreachable, the call times out, or the hook returns an error).\nIndividual hooks may override this with their own FailureStrategy.\nDefaults to Fail.\nErrors evaluating a plugin or hook Condition always fail the operation, regardless of FailureStrategy.",
          "type": "string",
          "x-kubernetes-validations": [
            {
              "message": "failureStrategy must be one of: Fail, Ignore",
              "rule": "self in ['Fail','Ignore']"
            }
          ]
        },
        "launcherHooks": {
          "description": "LauncherHooks defines hooks that run inside the virt-launcher pod at well-defined\npoints in the VM lifecycle.\nHooks are applied in declaration order within each plugin.\nAcross plugins, hooks are applied in alphabetical order by plugin name.\nThe bound gives the CEL cost estimator a finite cardinality; it is not a user-facing limit.",
          "items": {
            "description": "LauncherHook defines a hook that runs inside the virt-launcher pod at a specific point in the VM lifecycle.\nExactly one of cel or sidecar must be specified.",
            "properties": {
              "cel": {
                "description": "CEL defines a CEL expression hook.",
                "properties": {
                  "expression": {
                    "description": "Expression is the CEL expression applied at the specified hook point.",
                    "minLength": 1,
                    "type": "string"
                  },
                  "hookPoint": {
                    "description": "HookPoint specifies which launcher hook point this CEL expression applies to.\nGuestDefinition is the only currently supported launcher hook point for CEL.",
                    "type": "string",
                    "x-kubernetes-validations": [
                      {
                        "message": "CEL is only supported for the GuestDefinition hook point",
                        "rule": "self == 'GuestDefinition'"
                      },
                      {
                        "message": "hook point must be one of: GuestDefinition, PreBoot, PreMigrationSource",
                        "rule": "self in ['GuestDefinition','PreBoot','PreMigrationSource']"
                      }
                    ]
                  }
                },
                "required": [
                  "expression",
                  "hookPoint"
                ],
                "type": "object",
                "additionalProperties": false
              },
              "condition": {
                "description": "Condition is a CEL expression that determines whether this hook applies to a given VM.\nThe expression may reference only 'vmi' and must evaluate to a bool.",
                "type": "string"
              },
              "failureStrategy": {
                "description": "FailureStrategy specifies how to handle failures of this hook (Fail or Ignore).\nDefaults to the plugin-level FailureStrategy, or Fail if neither is set.",
                "type": "string",
                "x-kubernetes-validations": [
                  {
                    "message": "failureStrategy must be one of: Fail, Ignore",
                    "rule": "self in ['Fail','Ignore']"
                  }
                ]
              },
              "sidecar": {
                "description": "Sidecar defines a sidecar-based hook that communicates via a Unix socket.",
                "properties": {
                  "permittedHooks": {
                    "description": "PermittedHooks lists the launcher hook points this sidecar handles.\nThe bound gives the CEL cost estimator a finite cardinality; it is not a user-facing limit.",
                    "items": {
                      "description": "LauncherHookPoint identifies a point in the VM lifecycle where a launcher hook can run.\nGuestDefinition accepts CEL and sidecar hooks; PreBoot and PreMigrationSource are sidecar-only.",
                      "type": "string",
                      "x-kubernetes-validations": [
                        {
                          "message": "hook point must be one of: GuestDefinition, PreBoot, PreMigrationSource",
                          "rule": "self in ['GuestDefinition','PreBoot','PreMigrationSource']"
                        }
                      ]
                    },
                    "maxItems": 64,
                    "minItems": 1,
                    "type": "array",
                    "x-kubernetes-list-type": "set"
                  },
                  "socketPath": {
                    "description": "SocketPath is the path to the Unix socket used to communicate with the sidecar.\nThe CEL rule enforces the 108-byte sun_path limit; this MaxLength marker bounds the cost estimate.",
                    "maxLength": 108,
                    "minLength": 1,
                    "type": "string"
                  }
                },
                "required": [
                  "permittedHooks",
                  "socketPath"
                ],
                "type": "object",
                "x-kubernetes-validations": [
                  {
                    "message": "socketPath must be no longer than 108 bytes",
                    "rule": "size(bytes(self.socketPath)) <= 108"
                  },
                  {
                    "message": "socketPath must be a clean path: no '..' segments, repeated separators or trailing separator",
                    "rule": "!self.socketPath.contains('..') && !self.socketPath.contains('//') && !self.socketPath.endsWith('/')"
                  },
                  {
                    "message": "sidecar socketPath must end with .sock",
                    "rule": "self.socketPath.endsWith('.sock')"
                  }
                ],
                "additionalProperties": false
              },
              "timeout": {
                "description": "Timeout specifies the maximum duration to wait for the hook to complete.",
                "type": "string"
              }
            },
            "type": "object",
            "x-kubernetes-validations": [
              {
                "message": "a launcher hook must define exactly one of cel or sidecar",
                "rule": "has(self.cel) != has(self.sidecar)"
              },
              {
                "message": "timeout must be greater than zero",
                "rule": "!has(self.timeout) || duration(self.timeout) > duration('0s')"
              }
            ],
            "additionalProperties": false
          },
          "maxItems": 64,
          "type": "array",
          "x-kubernetes-list-type": "atomic"
        },
        "mutatingAdmissionPolicies": {
          "description": "MutatingAdmissionPolicies references MutatingAdmissionPolicy objects managed by the plugin.",
          "items": {
            "description": "AdmissionReference is a reference to an admission object by name.",
            "properties": {
              "name": {
                "description": "Name is the name of the admission object.",
                "minLength": 1,
                "type": "string"
              }
            },
            "required": [
              "name"
            ],
            "type": "object",
            "additionalProperties": false
          },
          "type": "array",
          "x-kubernetes-list-type": "atomic"
        },
        "mutatingAdmissionWebhooks": {
          "description": "MutatingAdmissionWebhooks references MutatingWebhookConfiguration objects managed by the plugin.",
          "items": {
            "description": "AdmissionReference is a reference to an admission object by name.",
            "properties": {
              "name": {
                "description": "Name is the name of the admission object.",
                "minLength": 1,
                "type": "string"
              }
            },
            "required": [
              "name"
            ],
            "type": "object",
            "additionalProperties": false
          },
          "type": "array",
          "x-kubernetes-list-type": "atomic"
        },
        "nodeHooks": {
          "description": "NodeHooks defines hooks that execute during VM lifecycle events.\nHooks are applied in declaration order within each plugin.\nAcross plugins, hooks are applied in alphabetical order by plugin name.\nThe bound gives the CEL cost estimator a finite cardinality; it is not a user-facing limit.",
          "items": {
            "description": "NodeHook defines a hook that runs an executable on the hosting node during VM lifecycle events.\nUnlike LauncherHooks which run inside the virt-launcher pod, NodeHooks perform node-level operations\nsuch as configuring networking, storage preparation, or device management.\nHooks may fire multiple times for the same lifecycle event due to reconciliation retries.\nImplementations must be idempotent.",
            "properties": {
              "condition": {
                "description": "Condition is a CEL expression that determines whether this hook applies to a given VM.\nThe expression may reference only 'vmi' and must evaluate to a bool.",
                "type": "string"
              },
              "failureStrategy": {
                "description": "FailureStrategy specifies how to handle failures of this hook (Fail or Ignore).\nDefaults to the plugin-level FailureStrategy, or Fail if neither is set.",
                "type": "string",
                "x-kubernetes-validations": [
                  {
                    "message": "failureStrategy must be one of: Fail, Ignore",
                    "rule": "self in ['Fail','Ignore']"
                  }
                ]
              },
              "permittedHooks": {
                "description": "PermittedHooks lists the VM lifecycle events this hook handles.\nThe bound gives the CEL cost estimator a finite cardinality; it is not a user-facing limit.",
                "items": {
                  "description": "NodeHookPoint identifies a VM lifecycle event for node-level hooks.\nThe set is closed and validated at the API boundary. It is append-only across versions:\nnew hook points may be added, existing ones must never be removed.",
                  "type": "string",
                  "x-kubernetes-validations": [
                    {
                      "message": "hook point must be one of: PreVMStart, PostVMStart, OnVMStop, PostVMStop, PreMigrationSource, PreMigrationTarget, PostMigrationTarget",
                      "rule": "self in ['PreVMStart','PostVMStart','OnVMStop','PostVMStop','PreMigrationSource','PreMigrationTarget','PostMigrationTarget']"
                    }
                  ]
                },
                "maxItems": 64,
                "minItems": 1,
                "type": "array",
                "x-kubernetes-list-type": "atomic"
              },
              "socket": {
                "description": "Socket is the path to the Unix socket for hook communication.\nThe CEL rule enforces the 108-byte sun_path limit; this MaxLength marker bounds the cost estimate.",
                "maxLength": 108,
                "minLength": 1,
                "type": "string"
              },
              "timeout": {
                "description": "Timeout specifies the maximum duration to wait for the hook to complete.",
                "type": "string"
              }
            },
            "required": [
              "permittedHooks",
              "socket"
            ],
            "type": "object",
            "x-kubernetes-validations": [
              {
                "message": "socket must be no longer than 108 bytes",
                "rule": "size(bytes(self.socket)) <= 108"
              },
              {
                "message": "socket must be a clean path: no '..' segments, repeated separators or trailing separator",
                "rule": "!self.socket.contains('..') && !self.socket.contains('//') && !self.socket.endsWith('/')"
              },
              {
                "message": "timeout must be greater than zero",
                "rule": "!has(self.timeout) || duration(self.timeout) > duration('0s')"
              }
            ],
            "additionalProperties": false
          },
          "maxItems": 64,
          "type": "array",
          "x-kubernetes-list-type": "atomic"
        },
        "validatingAdmissionPolicies": {
          "description": "ValidatingAdmissionPolicies references ValidatingAdmissionPolicy objects managed by the plugin.",
          "items": {
            "description": "AdmissionReference is a reference to an admission object by name.",
            "properties": {
              "name": {
                "description": "Name is the name of the admission object.",
                "minLength": 1,
                "type": "string"
              }
            },
            "required": [
              "name"
            ],
            "type": "object",
            "additionalProperties": false
          },
          "type": "array",
          "x-kubernetes-list-type": "atomic"
        },
        "validatingAdmissionWebhooks": {
          "description": "ValidatingAdmissionWebhooks references ValidatingWebhookConfiguration objects managed by the plugin.",
          "items": {
            "description": "AdmissionReference is a reference to an admission object by name.",
            "properties": {
              "name": {
                "description": "Name is the name of the admission object.",
                "minLength": 1,
                "type": "string"
              }
            },
            "required": [
              "name"
            ],
            "type": "object",
            "additionalProperties": false
          },
          "type": "array",
          "x-kubernetes-list-type": "atomic"
        }
      },
      "type": "object",
      "additionalProperties": false
    },
    "status": {
      "description": "Status reflects the observed state of the plugin.",
      "type": "object"
    }
  },
  "required": [
    "spec"
  ],
  "type": "object",
  "x-kubernetes-validations": [
    {
      "message": "sidecar socketPath must start with /var/run/kubevirt-plugin/<plugin-name>/",
      "rule": "!has(self.spec.launcherHooks) || self.spec.launcherHooks.all(lh, !has(lh.sidecar) || (lh.sidecar.socketPath.startsWith('/var/run/kubevirt-plugin/') && size(lh.sidecar.socketPath.split('/')) > 5 && lh.sidecar.socketPath.split('/')[4] == self.metadata.name))"
    }
  ]
}
