# Kubernetes Deployment Contracts
#
# Type definitions for K8s deployments
# Migrated from provisioning/kcl/k8s_deploy.k

{
  K8sPort = {
    name | String,
    typ | String | optional | default = "TCP",
    container | Number | optional,
    nodePort | Number | optional,
    target | Number | optional,
  },

  K8sKeyVal = {
    key | String,
    value | String,
  },

  K8sKeyPath = {
    key | String,
    path | String,
  },

  K8sVolumeMount = {
    name | String,
    readOnly | Bool | default = false,
    mountPath | String,
    subPath | String | optional,
  },

  K8sVolumeClaim = {
    name | String,
    storageClassName | String | default = "manual",
    modes | Array String | default = ["ReadWriteOnce"],
    abbrev_mode | Array String | optional | default = ["RWO"],
    reclaimPolicy | String | optional | default = "Retain",
    storage | String | optional,
    typ | String | default = "",
    pvMode | String | optional,
    pvcMode | String | optional,
    hostPath | String | optional,
  },

  K8sConfigMap = {
    name | String,
  },

  K8sSecret = {
    name | String,
    items | Array K8sKeyPath,
  },

  K8sVolume = {
    name | String,
    typ | String | default = "volumeClaim",
    persistentVolumeClaim | K8sVolumeClaim | optional,
    items | Array K8sKeyPath | optional,
    configMap | K8sConfigMap | optional,
    secret | K8sSecret | optional,
  },

  K8sService = {
    name | String,
    typ | String | default = "ClusterIP",
    externalName | String | optional,
    proto | String | default = "TCP",
    ports | Array K8sPort,
    selector | Array K8sKeyVal | optional,
    externalIPs | Array String | optional,
  },

  K8sResources = {
    memory | String,
    cpu | String,
  },

  K8sContainers = {
    name | String | default = "main",
    resources_requests | K8sResources | optional,
    resources_limits | K8sResources | optional,
    image | String,
    cmd | String | optional,
    imagePull | String | default = "IfNotPresent",
    env | Array K8sKeyVal | optional,
    ports | Array K8sPort | optional,
    volumeMounts | Array K8sVolumeMount | optional,
  },

  K8sBackup = {
    name | String,
    typ | String,
    mount_path | String,
  },

  K8sAffinityMatch = {
    key | String,
    operator | String,
    values | Array String,
  },

  K8sAffinityLabelSelector = {
    typ | String | default = "requiredDuringSchedulingIgnoredDuringExecution",
    labelSelector | Array K8sAffinityMatch,
    topologyKey | String | optional,
    matchLabelKeys | Array String | optional,
  },

  K8sAntyAffinityLabelSelector = {
    typ | String | default = "requiredDuringSchedulingIgnoredDuringExecution",
    labelSelector | Array K8sAffinityMatch,
    topologyKey | String | optional,
    matchLabelKeys | Array String | optional,
    weight | Number | default = 100,
  },

  K8sAffinity = {
    affinity | K8sAffinityLabelSelector | optional,
    antiAffinity | K8sAntyAffinityLabelSelector | optional,
  },

  K8sDeploySpec = {
    replicas | Number | default = 1,
    hostUsers | Bool | optional | default = true,
    containers | Array K8sContainers,
    imagePullSecret | String | optional,
    nodeSelector | Array K8sKeyVal | optional,
    nodeName | String | optional,
    affinity | K8sAffinity | optional,
    volumes | Array K8sVolume | optional,
    secrets | Array K8sSecret | optional,
  },

  K8sPrxyTLS = {
    httpsRedirect | Bool | optional | default = false,
    mode | String | optional | default = "SIMPLE",
    credentialName | String | optional,
  },

  K8sPrxyPort = {
    name | String,
    number | Number | optional,
    proto | String | default = "HTTPS",
  },

  K8sPrxyGatewayServer = {
    port | K8sPrxyPort,
    tls | K8sPrxyTLS | optional,
    hosts | Array String | optional,
  },

  K8sPrxyVirtualServiceRoute = {
    port_number | Number,
    host | String,
  },

  K8sPrxyVirtualServiceMatchURL = {
    port | Number | optional,
    sniHost | Array String | optional,
  },

  K8sPrxyVirtualServiceMatch = {
    typ | String,
    location | Array K8sPrxyVirtualServiceMatchURL | optional,
    route_destination | Array K8sPrxyVirtualServiceRoute | optional,
  },

  K8sPrxyVirtualService = {
    hosts | Array String,
    gateways | Array String,
    matches | Array K8sPrxyVirtualServiceMatch | optional,
  },

  K8sDefs = {
    name | String,
    ns | String,
    domain | String,
    full_domain | String,
    primary_dom | String,
    cluster_domain | String,
  },

  K8sServiceMeshConfig = {
    mtls_enabled | Bool | optional | default = true,
    tracing_enabled | Bool | optional | default = true,
  },

  K8sIngressConfig = {
    tls_enabled | Bool | optional | default = true,
    default_backend | String | optional,
  },

  K8sDeploy = {
    name | String,
    name_in_files | String,
    namespace | String,
    create_ns | Bool | default = false,
    full_domain | String | optional,
    labels | Array K8sKeyVal,
    sel_labels | Array K8sKeyVal,
    tpl_labels | Array K8sKeyVal,
    spec | K8sDeploySpec,
    service_mesh | String | optional,
    service_mesh_ns | String | optional,
    service_mesh_config | K8sServiceMeshConfig | optional,
    ingress_controller | String | optional,
    ingress_ns | String | optional,
    ingress_config | K8sIngressConfig | optional,
    prxy | String | optional,
    prxy_ns | String | optional | default = "istio-system",
    prxyGatewayServers | Array K8sPrxyGatewayServer | optional,
    prxyVirtualService | K8sPrxyVirtualService | optional,
    tls_path | String | optional | default = "ssl",
    bin_apply | Bool | default = true,
    service | K8sService | optional,
    backups | Array K8sBackup | optional,
  },
}
