apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
name: "[Stable] ControlPlaneMachineSet"
crd: 0000_10_controlplanemachineset-Default.crd.yaml
tests:
  onCreate:
  - name: Should reject an OpenStack platform failure domain without any OpenStack config
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains: Invalid value: \"object\": openstack configuration is required when platform is OpenStack"
  - name: Should reject an OpenStack configured failure domain without a platform type
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              openstack:
              - availabilityZone: foo
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.platform: Required value"
  - name: Should reject an OpenStack configured failure domain with an empty OpenStack config
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack: {}
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack in body must be of type array: \"object\""
  - name: Should accept no failureDomains
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: ""
    expected: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Inactive
        strategy:
          type: RollingUpdate
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: ""
  - name: Should reject an OpenStack configured failure domain with the wrong platform type
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: BareMetal
              openstack:
              - availabilityZone: foo
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains: Invalid value: \"object\": openstack configuration is required when platform is OpenStack, and forbidden otherwise"
  - name: Should accept an OpenStack failure domain with only the availabilityZone provided
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - availabilityZone: foo
    expected: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Inactive
        strategy:
          type: RollingUpdate
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - availabilityZone: foo
  - name: Should accept an OpenStack failure domain with only the rootVolume provided
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - rootVolume:
                  availabilityZone: foo
                  volumeType: fast
    expected: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Inactive
        strategy:
          type: RollingUpdate
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - rootVolume:
                  availabilityZone: foo
                  volumeType: fast
  - name: Should accept an OpenStack failure domain with only the root volume type provided
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - rootVolume:
                  volumeType: typeone
    expected: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Inactive
        strategy:
          type: RollingUpdate
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - rootVolume:
                  volumeType: typeone
  - name: Should accept an OpenStack failure domain with both availabilityZone and rootVolume provided
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - availabilityZone: foo
                rootVolume:
                  availabilityZone: foo
                  volumeType: fast
    expected: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Inactive
        strategy:
          type: RollingUpdate
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - availabilityZone: foo
                rootVolume:
                  availabilityZone: foo
                  volumeType: fast
  - name: Should accept an OpenStack failure domain with both availabilityZone and root volume type provided
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - availabilityZone: foo
                rootVolume:
                  availabilityZone: foo
                  volumeType: bar
    expected: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Inactive
        strategy:
          type: RollingUpdate
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - availabilityZone: foo
                rootVolume:
                  availabilityZone: foo
                  volumeType: bar
  - name: Should reject an OpenStack failure domain with no rootVolume volumeType provided
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - rootVolume:
                  availabilityZone: foo
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack[0].rootVolume.volumeType: Required value, <nil>: Invalid value: \"null\": some validation rules were not checked"
  - name: Should reject an OpenStack failure domain with an empty rootVolume volumeType provided
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - rootVolume:
                  volumeType: ""
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack[0].rootVolume.volumeType: Invalid value: \"\": spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack[0].rootVolume.volumeType in body should be at least 1 chars long"
  - name: Should reject an OpenStack failure domain with too long a rootVolume volumeType name
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - availabilityZone: foo
                rootVolume:
                  volumeType: a123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack[0].rootVolume.volumeType: Too long: may not be longer than 255"
  - name: Should reject an OpenStack failure domain with both availabilityZone and root volume provided but with missing root volume availabilityZone
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - availabilityZone: foo
                rootVolume:
                  volumeType: bar
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack[0]: Invalid value: \"object\": rootVolume.availabilityZone is required when availabilityZone is set"
  - name: Should reject an empty OpenStack failure domain
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - availabilityZone: foo
              - {}
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack[1] in body should have at least 1 properties"
  - name: Should reject an OpenStack failure domain with an empty availabilityZone provided
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - availabilityZone: ""
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack[0].availabilityZone in body should be at least 1 chars long"
  - name: Should reject an OpenStack failure domain with an empty rootVolume availabilityZone provided
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
              - rootVolume:
                  availabilityZone: ""
                  volumeType: fast
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack[0].rootVolume.availabilityZone in body should be at least 1 chars long"
  - name: Should reject an OpenStack failure domain with an invalid availabilityZone provided
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
                - availabilityZone: foo:bar
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack[0].availabilityZone in body should match"
  - name: Should reject an OpenStack failure domain with an invalid availabilityZone provided for rootVolume
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        selector:
          matchLabels:
            machine.openshift.io/cluster-api-machine-role: master
            machine.openshift.io/cluster-api-machine-type: master
        template:
          machineType: machines_v1beta1_machine_openshift_io
          machines_v1beta1_machine_openshift_io:
            metadata:
              labels:
                machine.openshift.io/cluster-api-machine-role: master
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
            failureDomains:
              platform: OpenStack
              openstack:
                - rootVolume:
                    availabilityZone: "foo bar"
                    volumeType: fast
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.failureDomains.openstack[0].rootVolume.availabilityZone in body should match"
