{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "https://github.tools.sap/unified-runtime/content-deployment/blob/main/values.schema.json",
    "type": "object",
    "required": [
        "image", "bindings"
    ],
    "additionalProperties": false,
    "properties": {
        "global": {
            "$id": "#/properties/global",
            "type": "object",
            "x-ignore-untested": true,
            "additionalProperties": true,
            "properties": {
                "imagePullSecret": {
                    "$id": "#/properties/global/imagePullSecret",
                    "additionalProperties": true,
                    "type": "object",
                    "properties": {
                        "name": {
                            "$ref": "#/definitions/KubernetesName"
                        },
                        "dockerconfigjson": {
                            "type": "string"
                        }
                    }
                },
                "image": {
                    "$id": "#/properties/global/image",
                    "title": "Image configuration",
                    "type": "object",
                    "required": [],
                    "additionalProperties": true,
                    "properties": {
                        "tag": {
                            "$id": "#/properties/image/global/properties/tag",
                            "$ref": "#/definitions/ImageTag"
                        },
                        "registry": {
                            "$id": "#/properties/image/global/properties/registry",
                            "$ref": "#/definitions/ImageRegistry"
                        }
                    }
                },
                "imagePullPolicy": {
                    "$ref": "#/definitions/ImagePullPolicy"
                }
            }
        },
        "nameOverride": {
            "$id": "#/properties/nameOverride",
            "type": "string",
            "pattern": "[0-9a-z][0-9a-z-.]*"
        },
        "fullnameOverride": {
            "$id": "#/properties/fullnameOverride",
            "type": "string",
            "pattern": "[0-9a-z][0-9a-z-.]*"
        },
        "serviceAccountName": {
            "$id": "#/properties/serviceAccountName",
            "type": "string"
        },
        "runAsUser": {
            "$id": "#/properties/runAsUser",
            "type": "integer",
            "minimum": 1
        },
        "readOnlyRootFilesystem": {
          "$id": "#/properties/readOnlyRootFilesystem",
          "type": "boolean"
        },
        "image": {
            "$id": "#/properties/image",
            "title": "Image configuration",
            "type": "object",
            "required": [
                "repository"
            ],
            "additionalProperties": false,
            "properties": {
                "repository": {
                    "$id": "#/properties/image/properties/repository",
                    "type": "string",
                    "pattern": "^[\\w-./:]*(@sha256)?$"
                },
                "tag": {
                    "$id": "#/properties/image/properties/tag",
                    "$ref": "#/definitions/ImageTag"
                },
                "registry": {
                    "$id": "#/properties/image/properties/registry",
                    "$ref": "#/definitions/ImageRegistry"
                }
            }
        },
        "imagePullSecret": {
            "$id": "#/properties/imagePullSecret",
            "additionalProperties": false,
            "type": "object",
            "properties": {
                "name": {
                    "$ref": "#/definitions/KubernetesName"
                },
                "dockerconfigjson": {
                    "type": "string"
                }
            },
            "dependencies": {
                "name": {
                    "not": {
                        "required": [
                            "dockerconfigjson"
                        ]
                    }
                },
                "dockerconfigjson": {
                    "not": {
                        "required": [
                            "name"
                        ]
                    }
                }
            }
        },
        "imagePullPolicy": {
            "$ref": "#/definitions/ImagePullPolicy"
        },
        "resources": {
            "$id": "#/properties/resources",
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "requests": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "cpu": {
                            "$id": "#/properties/resources/properties/requests/properties/cpu",
                            "type": ["number", "string"]
                        },
                        "ephemeral-storage": {
                            "$id": "#/properties/resources/properties/requests/properties/ephemeral-storage",
                            "type": "string"
                        },
                        "memory": {
                            "$id": "#/properties/resources/properties/requests/properties/memory",
                            "type": "string"
                        }
                    }
                },
                "limits": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "cpu": {
                            "$id": "#/properties/resources/properties/limits/properties/cpu",
                            "type": ["number", "string"]
                        },
                        "ephemeral-storage": {
                            "$id": "#/properties/resources/properties/limits/properties/ephemeral-storage",
                            "type": "string"
                        },
                        "memory": {
                            "$id": "#/properties/resources/properties/limits/properties/memory",
                            "type": "string"
                        }
                    }
                }
            }
        },
        "env": {
            "$id": "#/properties/env",
            "anyOf": [
                {

                    "type": "object",
                    "patternProperties": {
                        "^[-._a-zA-Z][-._a-zA-Z0-9]*$": {
                            "$comment": "regex above copied from https://github.com/kubernetes/kubernetes/blob/ea0764452222146c47ec826977f49d7001b0ea8c/staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go#L402",
                            "anyOf": [
                                {
                                    "type": ["integer", "string"]
                                },
                                {
                                    "type": "object",
                                    "additionalProperties": false,
                                    "maxProperties": 1,
                                    "properties": {
                                        "configMapKeyRef": {
                                            "type": "object",
                                            "additionalProperties": false,
                                            "properties": {
                                                "name": {
                                                    "type": "string"
                                                },
                                                "key": {
                                                    "type": "string"
                                                }
                                            }
                                        },
                                        "secretKeyRef": {
                                            "type": "object",
                                            "additionalProperties": false,
                                            "properties": {
                                                "name": {
                                                    "type": "string"
                                                },
                                                "key": {
                                                    "type": "string"
                                                }
                                            }
                                        },
                                        "resourceFieldRef": {
                                            "type": "object",
                                            "additionalProperties": false,
                                            "properties": {
                                                "containerName": {
                                                    "type": "string"
                                                },
                                                "resource": {
                                                    "type": "string"
                                                }
                                            }
                                        },
                                        "fieldRef": {
                                            "type": "object",
                                            "additionalProperties": false,
                                            "properties": {
                                                "fieldPath": {
                                                    "type": "string"
                                                }
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    },
                    "additionalProperties": false,
                    "default": {}
                },
                {
                    "type": "array",
                    "uniqueItems": true,
                    "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "maxProperties": 2,
                        "required": [
                            "name"
                        ],
                        "properties": {
                            "name": {
                                "type": "string",
                                "pattern": "^[-._a-zA-Z][-._a-zA-Z0-9]*$"
                            },
                            "value": {
                                "type": ["string", "integer"]
                            },
                            "configMapKeyRef": {
                                "type": "object",
                                "additionalProperties": false,
                                "properties": {
                                    "name": {
                                        "type": "string"
                                    },
                                    "key": {
                                        "type": "string"
                                    }
                                }
                            },
                            "secretKeyRef": {
                                "type": "object",
                                "additionalProperties": false,
                                "properties": {
                                    "name": {
                                        "type": "string"
                                    },
                                    "key": {
                                        "type": "string"
                                    }
                                }
                            },
                            "resourceFieldRef": {
                                "type": "object",
                                "additionalProperties": false,
                                "properties": {
                                    "containerName": {
                                        "type": "string"
                                    },
                                    "resource": {
                                        "type": "string"
                                    }
                                }
                            },
                            "fieldRef": {
                                "type": "object",
                                "additionalProperties": false,
                                "properties": {
                                    "fieldPath": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                }
            ],
            "default": {}
        },
        "envSecretNames": {
            "$id": "#/properties/envSecretNames",
            "type": "array",
            "uniqueItems": true,
            "items": {
                "type": "string",
                "$ref": "#/definitions/KubernetesName"
            }
        },
        "envFrom": {
            "$id": "#/properties/envFrom",
            "type": "array",
            "default": [],
            "items": {
                "type": "object",
                "oneOf": [
                    {
                        "additionalProperties": false,
                        "properties": {
                            "configMapRef": {
                                "properties": {
                                    "name": {
                                        "type": "string"
                                    }
                                },
                                "required": [ "name" ],
                                "additionalProperties": false,
                                "type": "object"
                            }
                        },
                        "required": [ "configMapRef" ]
                    },
                    {
                        "additionalProperties": false,
                        "properties": {
                            "secretRef": {
                                "properties": {
                                    "name": {
                                        "type": "string"
                                    }
                                },
                                "required": [ "name" ],
                                "additionalProperties": false,
                                "type": "object"
                            }
                        },
                        "required": [ "secretRef" ]
                    }
                ]
            }
        },
        "ttlDaysAfterFinished": {
            "$id": "#/properties/ttlDaysAfterFinished",
            "title": "Time to keep the Job after it has finished.",
            "type": "integer",
            "minimum": 0,
            "default": 14
        },
        "bindings": {
            "$id": "#/properties/bindings",
            "title": "Service Binding configuration",
            "type": "object",
            "additionalProperties": false,
            "minProperties": 1,
            "patternProperties": {
                "^[-._a-zA-Z][-._a-zA-Z0-9]*$": {
                    "oneOf": [
                        {
                            "type": "object",
                            "additionalProperties": false,
                            "required": [
                                "fromSecret"
                            ],
                            "properties": {
                                "fromSecret": {
                                    "type": "string"
                                }
                            }
                        },
                        {
                            "type": "object",
                            "additionalProperties": false,
                            "properties": {
                                "serviceInstanceName": {
                                    "type": "string"
                                },
                                "serviceInstanceFullname": {
                                    "type": "string"
                                },
                                "externalName": {
                                    "type": "string"
                                },
                                "secretName": {
                                    "type": "string"
                                },
                                "parameters": {
                                    "type": "object"
                                },
                                "parametersFrom": {
                                    "type": "array",
                                    "items": {
                                        "anyOf": [
                                            {
                                                "type": "object",
                                                "additionalProperties": false,
                                                "properties": {
                                                    "secretKeyRef": {
                                                        "type": "object",
                                                        "additionalProperties": false,
                                                        "required": [
                                                            "name",
                                                            "key"
                                                        ],
                                                        "properties": {
                                                            "name": {
                                                                "type": "string"
                                                            },
                                                            "key": {
                                                                "type": "string"
                                                            }
                                                        }
                                                    }
                                                }
                                            },
                                            {
                                                "type": "object",
                                                "additionalProperties": false,
                                                "properties": {
                                                    "configMapKeyRef": {
                                                        "type": "object",
                                                        "additionalProperties": false,
                                                        "required": [
                                                            "name",
                                                            "key"
                                                        ],
                                                        "properties": {
                                                            "name": {
                                                                "type": "string"
                                                            },
                                                            "key": {
                                                                "type": "string"
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        ]
                                    }
                                },
                                "credentialsRotationPolicy": {
                                    "type": "object"
                                }
                            },
                            "dependencies": {
                                "serviceInstanceName": {
                                    "not": {
                                        "required": [
                                            "serviceInstanceFullname"
                                        ]
                                    }
                                },
                                "serviceInstanceFullname": {
                                    "not": {
                                        "required": [
                                            "serviceInstanceName"
                                        ]
                                    }
                                }
                            }
                        }
                    ]
                }
            }
        },
        "annotations": {
            "$id": "#/properties/annotations",
            "title": "Additional annotations",
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "job": {
                    "type": "object",
                    "title": "Annotations to add to the Job",
                    "patternProperties": {
                        ".*": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "nodeSelector": {
            "$id": "#/properties/nodeSelector",
            "title": "Node selector",
            "type": "object",
            "patternProperties": {
                "^[-._a-zA-Z][-._a-zA-Z0-9]*$": {
                    "type": "string"
                }
            }
        },
        "nodeAffinity": {
            "$id": "#/properties/nodeAffinity",
            "title": "Node affinity",
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "requiredDuringSchedulingIgnoredDuringExecution": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "nodeSelectorTerms": {
                            "type": "array",
                            "description": "A node selector terms, associated with the corresponding weight.",
                            "items": {
                                "$ref": "#/definitions/NodeSelectorTerm"
                            }
                        }
                    },
                    "required": ["nodeSelectorTerms"]
                },
                "preferredDuringSchedulingIgnoredDuringExecution": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "additionalProperties": false,
                        "properties": {
                            "weight": {
                                "type": "integer",
                                "description": "Weight associated with matching the corresponding nodeSelectorTerm, in the range 1-100."
                            },
                            "preference": {
                                "description": "A node selector term, associated with the corresponding weight.",
                                "$ref": "#/definitions/NodeSelectorTerm"
                            }
                        },
                        "required": ["weight", "preference"]
                    }
                }
            }
        },
        "command": {
            "$id": "#/properties/command",
            "title": "Container command",
            "description": "The command to run in the container. Overrides the default image entrypoint.",
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "args": {
            "$id": "#/properties/args",
            "title": "Container args",
            "description": "Arguments to pass to the command. Overrides the default image cmd.",
            "type": "array",
            "items": {
                "type": "string"
            }
        }
    },
    "definitions": {
        "KubernetesName": {
            "type": "string",
            "$comment": "running `kubectl create secret generic invalid_name` will print this regex",
            "pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$"
        },
        "ImageRegistry": {
            "type": "string",
            "title": "Image registry",
            "pattern": "^[\\w-./:]+$"
        },
        "ImageTag": {
            "title": "Image tag",
            "type": "string",
            "$comment": "Copied from https://github.com/containers/image/blob/18d58d29fdc4fc32fb8a8a6d186b829b217f1bf5/docker/reference/regexp.go#L68-L70",
            "pattern": "^((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])(?:(?:\\.(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]))+)?(?::[0-9]+)?/)?[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-zA-Z0-9]+)+)?(?:(?:/[a-z0-9]+(?:(?:(?:[._]|__|[-]*)[a-z0-9]+)+)?)+)?)(?::([\\w][\\w.-]{0,127}))?(?:@([A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][[:xdigit:]]{32,}))?$"
        },
        "ImagePullPolicy": {
            "title": "ImagePullPolicy",
            "type": "string",
            "enum": ["Always", "IfNotPresent", "Never"]
        },
        "NodeSelectorRequirement": {
            "description": "A node selector requirement is a selector that contains values, a key, and an operator that relates the key and values.",
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "key": {
                    "description": "The label key that the selector applies to.",
                    "type": "string"
                },
                "operator": {
                    "description": "Represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists, DoesNotExist. Gt, and Lt.",
                    "type": "string",
                    "enum": ["In", "NotIn", "Exists", "DoesNotExist", "Gt", "Lt"]
                },
                "values": {
                    "description": "An array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. If the operator is Gt or Lt, the values array must have a single element, which will be interpreted as an integer. This array is replaced during a strategic merge patch.",
                    "items": {
                        "type": "string"
                    },
                    "type": "array"
                }
            },
            "required": ["key", "operator"]
        },
        "NodeSelectorTerm": {
            "description": "A null or empty node selector term matches no objects. The requirements of them are ANDed.",
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "matchExpressions": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/NodeSelectorRequirement"
                    }
                }
            }
        }
    }
}
