suite: vpa validation test
templates:
  - common.yaml
release:
  name: test-release-name
  namespace: test-release-namespace
tests:
  - it: should fail with name longer than 63 characters
    set:
      workload: &workload
        workload-name:
          enabled: true
          primary: true
          type: Deployment
          podSpec: {}
      vpa:
        ? other-vertical-pod-autoscale-name-super-long-name-that-is-longer-than-63-characters
        : enabled: true
    asserts:
      - failedTemplate:
          errorMessage: Name [other-vertical-pod-autoscale-name-super-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters.

  - it: should fail with name starting with underscore
    set:
      workload: *workload
      vpa:
        _other-vpa-name:
          enabled: true
    asserts:
      - failedTemplate:
          errorMessage: Name [_other-vpa-name] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters.

  - it: should fail with labels not a dict
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          labels: "not a dict"
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Expected [labels] to be a dictionary, but got [string]

  - it: should fail with annotations not a dict
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          annotations: "not a dict"
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Expected [annotations] to be a dictionary, but got [string]

  - it: should fail with updatePolicy not a dict
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          updatePolicy: "not a dict"
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.updatePolicy] to be a dictionary, but got [string]

  - it: should fail with updatePolicy.updateMode not valid
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          updatePolicy:
            updateMode: invalid
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value [invalid] on [vpa.vpa-name.updatePolicy.updateMode] is not valid. Must be one of [Auto, Off, Initial, Recreate]

  - it: should fail with updatePolicy.minReplicas not a number
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          updatePolicy:
            minReplicas: "some-number"
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value [some-number] on [vpa.vpa-name.updatePolicy.minReplicas] must be greater than 0.

  - it: should fail with updatePolicy.minReplicas not a positive number
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          updatePolicy:
            minReplicas: -1
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value [-1] on [vpa.vpa-name.updatePolicy.minReplicas] must be greater than 0.

  - it: should fail with evictionRequirements not a list
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          updatePolicy:
            evictionRequirements: "not a list"
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value on [vpa.vpa-name.updatePolicy.evictionRequirements] must be a list, but got [string]

  - it: should fail with evictionRequirements.resources not a list
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          updatePolicy:
            evictionRequirements:
              - resources: "not a list"
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value on [vpa.vpa-name.updatePolicy.evictionRequirements.0.resources] must be a list, but got [string]

  - it: should fail with evictionRequirements.resources.0 not a valid resource
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          updatePolicy:
            evictionRequirements:
              - resources:
                  - cpu
                  - memory
                  - some-resource
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value [some-resource] on [vpa.vpa-name.updatePolicy.evictionRequirements.0.resources.2] is not valid. Must be one of [cpu, memory]

  - it: should fail with evictionRequirements.changeRequirement not a valid change requirement
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          updatePolicy:
            evictionRequirements:
              - resources:
                  - cpu
                changeRequirement: some-change-requirement
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value [some-change-requirement] on [vpa.vpa-name.updatePolicy.evictionRequirements.0.changeRequirement] is not valid. Must be one of [TargetHigherThanRequests, TargetLowerThanRequests]

  - it: should fail with resourcePolicy.containerPolicies not a list
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies: not-a-list
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value on [vpa.vpa-name.resourcePolicy.containerPolicies] must be a list, but got [string]

  - it: should fail with resourcePolicy.containerPolicies item not a dict
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies:
              - item
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0] to be a dictionary, but got [string]

  - it: should fail with invalid resourcePolicy.containerPolicies.#.containerName
    set:
      workload:
        workload-name:
          enabled: true
          primary: true
          type: Deployment
          podSpec:
            containers:
              some-container:
                enabled: true
                primary: true
                probes: &probes
                  readiness:
                    enabled: false
                  liveness:
                    enabled: false
                  startup:
                    enabled: false
              some-other-container:
                enabled: true
                probes: *probes
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies:
              - containerName: invalid
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value [invalid] on [vpa.vpa-name.resourcePolicy.containerPolicies.0.containerName] is not valid. Must be one of [some-container, some-other-container, *]

  - it: should fail with invalid resourcePolicy.containerPolicies.#.mode
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies:
              - containerName: "*"
                mode: invalid
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value [invalid] on [vpa.vpa-name.resourcePolicy.containerPolicies.0.mode] is not valid. Must be one of [Auto, Off]

  - it: should fail with resourcePolicy.containerPolicies.controlledResources not a list
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies:
              - containerName: "*"
                mode: Auto
                controlledResources: not-a-list
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0.controlledResources] to be a list, but got [string]

  - it: should fail with invalid item in resourcePolicy.containerPolicies.#.controlledResources
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies:
              - containerName: "*"
                mode: Auto
                controlledResources:
                  - invalid
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value [invalid] on [vpa.vpa-name.resourcePolicy.containerPolicies.0.controlledResources.0] is not valid. Must be one of [cpu, memory]

  - it: should fail with invalid value in resourcePolicy.containerPolicies.#.controlledValues
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies:
              - containerName: "*"
                mode: Auto
                controlledValues: invalid
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Value [invalid] on [vpa.vpa-name.resourcePolicy.containerPolicies.0.controlledValues] is not valid. Must be one of [RequestsAndLimits, RequestsOnly]

  - it: should fail with invalid cpu in minAllowed
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies:
              - containerName: "*"
                mode: Auto
                minAllowed:
                  cpu: invalid
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0.minAllowed.cpu] to have one of the following formats [(Plain Integer - eg. 1), (Float - eg. 0.5), (Milicpu - eg. 500m)], but got [invalid]

  - it: should fail with invalid memory in minAllowed
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies:
              - containerName: "*"
                mode: Auto
                minAllowed:
                  cpu: 1
                  memory: invalid
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0.minAllowed.memory] to have one of the following formats [(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)], but got [invalid]

  - it: should fail with invalid cpu in maxAllowed
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies:
              - containerName: "*"
                mode: Auto
                maxAllowed:
                  cpu: invalid
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0.maxAllowed.cpu] to have one of the following formats [(Plain Integer - eg. 1), (Float - eg. 0.5), (Milicpu - eg. 500m)], but got [invalid]

  - it: should fail with invalid memory in maxAllowed
    set:
      workload: *workload
      vpa:
        vpa-name:
          enabled: true
          resourcePolicy:
            containerPolicies:
              - containerName: "*"
                mode: Auto
                maxAllowed:
                  cpu: 1500m
                  memory: invalid
    asserts:
      - failedTemplate:
          errorMessage: Vertical Pod Autoscaler - Expected [vpa.vpa-name.resourcePolicy.containerPolicies.0.maxAllowed.memory] to have one of the following formats [(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)], but got [invalid]
