{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://khook.io/schema/v1/khook.json",
  "$ref": "#/$defs/Document",
  "$defs": {
    "ApplyOp": {
      "properties": {
        "manifests": {
          "items": {
            "$ref": "#/$defs/ManifestSource"
          },
          "type": "array",
          "minItems": 1
        },
        "namespace": {
          "type": "string"
        },
        "createNamespace": {
          "type": "boolean"
        },
        "skipIf": {
          "type": "string",
          "enum": [
            "exists"
          ]
        },
        "serverSide": {
          "type": "boolean"
        },
        "waitFor": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "manifests"
      ]
    },
    "Defaults": {
      "properties": {
        "timeout": {
          "type": "string",
          "pattern": "^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
        },
        "retries": {
          "type": "integer"
        },
        "retryDelay": {
          "type": "string",
          "pattern": "^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
        },
        "onError": {
          "type": "string",
          "enum": [
            "fail",
            "continue"
          ]
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "DeleteOp": {
      "oneOf": [
        {
          "required": [
            "manifests"
          ]
        },
        {
          "required": [
            "resource"
          ]
        },
        {
          "required": [
            "release"
          ]
        }
      ],
      "properties": {
        "manifests": {
          "items": {
            "$ref": "#/$defs/ManifestSource"
          },
          "type": "array",
          "minItems": 1
        },
        "resource": {
          "type": "string"
        },
        "release": {
          "type": "string"
        },
        "namespace": {
          "type": "string"
        },
        "allNamespaces": {
          "type": "boolean"
        },
        "selector": {
          "type": "string"
        },
        "fieldSelector": {
          "type": "string"
        },
        "ignoreNotFound": {
          "type": "boolean"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "Document": {
      "properties": {
        "apiVersion": {
          "type": "string",
          "const": "khook.io/v1"
        },
        "kind": {
          "type": "string",
          "const": "Khook"
        },
        "metadata": {
          "$ref": "#/$defs/Metadata"
        },
        "defaults": {
          "$ref": "#/$defs/Defaults"
        },
        "state": {
          "$ref": "#/$defs/StateSpec"
        },
        "steps": {
          "items": {
            "$ref": "#/$defs/Step"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "apiVersion",
        "kind",
        "metadata",
        "steps"
      ]
    },
    "HelmAuth": {
      "properties": {
        "username": {
          "type": "string"
        },
        "password": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "username",
        "password"
      ]
    },
    "HelmOp": {
      "properties": {
        "chart": {
          "type": "string"
        },
        "repo": {
          "type": "string"
        },
        "version": {
          "type": "string"
        },
        "auth": {
          "$ref": "#/$defs/HelmAuth"
        },
        "release": {
          "type": "string"
        },
        "namespace": {
          "type": "string"
        },
        "createNamespace": {
          "type": "boolean"
        },
        "skipIf": {
          "type": "string",
          "enum": [
            "installed"
          ]
        },
        "atomic": {
          "type": "boolean"
        },
        "wait": {
          "type": "boolean"
        },
        "values": {
          "type": "object"
        },
        "valuesFrom": {
          "items": {
            "$ref": "#/$defs/ValuesSource"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "chart"
      ]
    },
    "JobOp": {
      "properties": {
        "image": {
          "type": "string"
        },
        "command": {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "args": {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "env": {
          "additionalProperties": {
            "type": "string"
          },
          "type": "object"
        },
        "namespace": {
          "type": "string"
        },
        "createNamespace": {
          "type": "boolean"
        },
        "serviceAccount": {
          "type": "string"
        },
        "skipIf": {
          "type": "string",
          "enum": [
            "succeeded"
          ]
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "image"
      ]
    },
    "ManifestSource": {
      "oneOf": [
        {
          "required": [
            "inline"
          ]
        },
        {
          "required": [
            "file"
          ]
        },
        {
          "required": [
            "url"
          ]
        },
        {
          "required": [
            "kustomize"
          ]
        }
      ],
      "properties": {
        "inline": {
          "type": "string"
        },
        "file": {
          "type": "string"
        },
        "url": {
          "type": "string"
        },
        "kustomize": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "Metadata": {
      "properties": {
        "name": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "name"
      ]
    },
    "PatchOp": {
      "properties": {
        "target": {
          "type": "string"
        },
        "namespace": {
          "type": "string"
        },
        "type": {
          "type": "string",
          "enum": [
            "strategic",
            "merge",
            "json"
          ]
        },
        "patch": true
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "target"
      ]
    },
    "RolloutOp": {
      "oneOf": [
        {
          "required": [
            "restart"
          ]
        },
        {
          "required": [
            "status"
          ]
        }
      ],
      "properties": {
        "restart": {
          "type": "string"
        },
        "status": {
          "type": "string"
        },
        "namespace": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "namespace"
      ]
    },
    "StateSpec": {
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "namespace": {
          "type": "string",
          "pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$"
        },
        "name": {
          "type": "string",
          "pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "Step": {
      "oneOf": [
        {
          "required": [
            "helm"
          ]
        },
        {
          "required": [
            "apply"
          ]
        },
        {
          "required": [
            "delete"
          ]
        },
        {
          "required": [
            "patch"
          ]
        },
        {
          "required": [
            "wait"
          ]
        },
        {
          "required": [
            "rollout"
          ]
        },
        {
          "required": [
            "job"
          ]
        }
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "needs": {
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "when": {
          "type": "string"
        },
        "timeout": {
          "type": "string",
          "pattern": "^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
        },
        "retries": {
          "type": "integer"
        },
        "retryDelay": {
          "type": "string",
          "pattern": "^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
        },
        "onError": {
          "type": "string",
          "enum": [
            "fail",
            "continue"
          ]
        },
        "helm": {
          "$ref": "#/$defs/HelmOp"
        },
        "apply": {
          "$ref": "#/$defs/ApplyOp"
        },
        "delete": {
          "$ref": "#/$defs/DeleteOp"
        },
        "patch": {
          "$ref": "#/$defs/PatchOp"
        },
        "wait": {
          "$ref": "#/$defs/WaitOp"
        },
        "rollout": {
          "$ref": "#/$defs/RolloutOp"
        },
        "job": {
          "$ref": "#/$defs/JobOp"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "name"
      ]
    },
    "ValuesSource": {
      "oneOf": [
        {
          "required": [
            "file"
          ]
        },
        {
          "required": [
            "url"
          ]
        }
      ],
      "properties": {
        "file": {
          "type": "string"
        },
        "url": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "WaitOp": {
      "properties": {
        "for": {
          "type": "string"
        },
        "on": {
          "type": "string"
        },
        "namespace": {
          "type": "string"
        },
        "allNamespaces": {
          "type": "boolean"
        },
        "selector": {
          "type": "string"
        },
        "fieldSelector": {
          "type": "string"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "for",
        "on"
      ]
    }
  },
  "title": "Khook"
}
