apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
name: "[CustomNoUpgrade] MachineConfiguration"
crd: 0000_80_machine-config-operator_01_config.CustomNoUpgrade.crd.yaml
tests:
  onCreate:
  - name: Should be able to create a minimal MachineConfiguration
    initial: |
      apiVersion: operator.openshift.io/v1
      kind: MachineConfiguration
      spec: {} # No spec is required for a MachineConfiguration
    expected: |
      apiVersion: operator.openshift.io/v1
      kind: MachineConfiguration
      spec:
        logLevel: Normal
        operatorLogLevel: Normal
  - name: Should be able to create an empty ManagedBootImages configuration knob
    initial: |
      apiVersion: operator.openshift.io/v1
      kind: MachineConfiguration
      spec:
        managedBootImages:
          machineManagers: []
    expected: |
      apiVersion: operator.openshift.io/v1
      kind: MachineConfiguration
      spec:
        logLevel: Normal
        operatorLogLevel: Normal
        managedBootImages:
          machineManagers: []
  - name: Should be able to create a ManagedBootImages configuration knob that opts in all MachineSets
    initial: |
      apiVersion: operator.openshift.io/v1
      kind: MachineConfiguration
      spec:
        managedBootImages:
          machineManagers:
            - resource: machinesets
              apiGroup: machine.openshift.io
              selection:
                mode: All
    expected: |
      apiVersion: operator.openshift.io/v1
      kind: MachineConfiguration
      spec:
        logLevel: Normal
        operatorLogLevel: Normal
        managedBootImages:
          machineManagers:
            - resource: machinesets
              apiGroup: machine.openshift.io
              selection:
                mode: All
  - name: Should be able to create a ManagedBootImages configuration knob that opts in MachineSets in partial mode
    initial: |
      apiVersion: operator.openshift.io/v1
      kind: MachineConfiguration
      spec:
        managedBootImages:
          machineManagers:
            - resource: machinesets
              apiGroup: machine.openshift.io                     
              selection:
                mode: Partial
                partial:
                  machineResourceSelector:
                    matchLabels: {}
    expected: |
      apiVersion: operator.openshift.io/v1
      kind: MachineConfiguration
      spec:
        logLevel: Normal
        operatorLogLevel: Normal
        managedBootImages:
          machineManagers:
            - resource: machinesets
              apiGroup: machine.openshift.io             
              selection:
                mode: Partial
                partial:
                  machineResourceSelector:
                    matchLabels: {}
  - name: Should not be able to add partial field if machineManager.selection.mode is not set to Partial
    initial: |
      apiVersion: operator.openshift.io/v1
      kind: MachineConfiguration
      spec:
        managedBootImages:
          machineManagers:
            - resource: machinesets
              apiGroup: machine.openshift.io                     
              selection:
                mode: All
                partial:
                  machineResourceSelector:
                    matchLabels: {}
    expectedError: "Partial is required when type is partial, and forbidden otherwise"
  - name: Only one unique pair of resource/apigroup is allowed in machineManagers
    initial: |
      apiVersion: operator.openshift.io/v1
      kind: MachineConfiguration
      spec:
        managedBootImages:
          machineManagers:
            - resource: machinesets
              apiGroup: machine.openshift.io
              selection:
                mode: Partial
                partial:
                  machineResourceSelector:
                    matchLabels: {}
            - resource: machinesets
              apiGroup: machine.openshift.io
              selection:
                mode: All
    expectedError: "spec.managedBootImages.machineManagers[1]: Duplicate value: map[string]interface {}{\"apiGroup\":\"machine.openshift.io\", \"resource\":\"machinesets\"}"
