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 be able to create a minimal ControlPlaneMachineSet
    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: {}
    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: {}
  - name: Should reject a missing machineType
    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:
          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: {}
    expectedError: "spec.template.machineType: Required value"
  - name: Should reject a missing machines_v1beta1_machine_openshift_io
    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
    expectedError: "spec.template: Invalid value: \"object\": machines_v1beta1_machine_openshift_io configuration is required when machineType is machines_v1beta1_machine_openshift_io, and forbidden otherwise"
  - name: Should reject a worker role label
    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: worker
                machine.openshift.io/cluster-api-machine-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.metadata.labels: Invalid value: \"object\": label 'machine.openshift.io/cluster-api-machine-role' is required, and must have value 'master'"
  - name: Should reject a missing role label
    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-type: master
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.metadata.labels: Invalid value: \"object\": label 'machine.openshift.io/cluster-api-machine-role' is required, and must have value 'master'"
  - name: Should reject a worker type label
    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: worker
                machine.openshift.io/cluster-api-cluster: cluster
            spec:
              providerSpec: {}
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.metadata.labels: Invalid value: \"object\": label 'machine.openshift.io/cluster-api-machine-type' is required, and must have value 'master'"
  - name: Should reject a missing type label
    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-cluster: cluster
            spec:
              providerSpec: {}
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.metadata.labels: Invalid value: \"object\": label 'machine.openshift.io/cluster-api-machine-type' is required, and must have value 'master'"
  - name: Should reject a missing cluster ID label
    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
            spec:
              providerSpec: {}
    expectedError: "spec.template.machines_v1beta1_machine_openshift_io.metadata.labels: Invalid value: \"object\": label 'machine.openshift.io/cluster-api-cluster' is required"
  - name: Should be able to create an Active ControlPlaneMachineSet
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        state: Active
        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: {}
    expected: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Active
        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: {}
  onUpdate:
  - name: Replicas should be immutable
    initial: |
      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: {}
    updated: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 5
        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: {}
    expectedError: "spec.replicas: Invalid value: \"integer\": replicas is immutable"
  - name: Selector should be immutable
    initial: |
      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: {}
    updated: |
      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
            foo: bar
        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: {}
    expectedError: "spec.selector: Invalid value: \"object\": selector is immutable"
  - name: Should default the strategy when removed
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Inactive
        strategy:
          type: OnDelete
        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: {}
    updated: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Inactive
        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: {}
    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: {}
  - name: Should allow the state to change to Active
    initial: |
      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: {}
    updated: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Active
        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: {}
    expected: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Active
        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: {}
  - name: Should not allow the state to change from Active
    initial: |
      apiVersion: machine.openshift.io/v1
      kind: ControlPlaneMachineSet
      spec:
        replicas: 3
        state: Active
        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: {}
    updated: |
      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: {}
    expectedError: "spec.state: Invalid value: \"string\": state cannot be changed once Active"
