{{ if eq .Values.cloudProvider "AWS" }}
{{- range .Values.cluster_zones }}
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
  annotations: {}
  name: {{ $.Values.cluster_prefix }}-{{ $.Values.node_name_prefix }}-{{ . }}
  namespace: openshift-machine-api
  labels:
    machine.openshift.io/cluster-api-cluster: {{ $.Values.cluster_prefix }}
spec:
  deletePolicy: Oldest
  replicas: {{ $.Values.instance_count_per_region }}
  selector:
    matchLabels:
      machine.openshift.io/cluster-api-cluster: {{ $.Values.cluster_prefix }}
      machine.openshift.io/cluster-api-machineset: {{ $.Values.cluster_prefix }}-{{ $.Values.node_name_prefix }}-{{ . }}
  template:
    metadata:
      labels:
        machine.openshift.io/cluster-api-cluster: {{ $.Values.cluster_prefix }}
        machine.openshift.io/cluster-api-machine-role: worker
        machine.openshift.io/cluster-api-machine-type: worker
        machine.openshift.io/cluster-api-machineset: {{ $.Values.cluster_prefix }}-{{ $.Values.node_name_prefix }}-{{ . }}
    spec:
      taints:
          - effect: NoSchedule
            key: platform/logging
            value: 'true'
      metadata:
        labels:
          platform/logging: 'true'
      providerSpec:
        value:
          userDataSecret:
            name: worker-user-data
          placement:
            availabilityZone: {{ . }}
            region: {{ substr 0 ((sub (len .) 1) | int) . }}
          credentialsSecret:
            name: aws-cloud-credentials
          instanceType: m5.2xlarge
          metadata:
            creationTimestamp: null
          blockDevices:
            - ebs:
                encrypted: true
                iops: 0
                kmsKey:
                  arn: ''
                volumeSize: 80
                volumeType: gp3
          securityGroups:
            - filters:
                - name: 'tag:Name'
                  values:
                    - {{ $.Values.cluster_prefix }}-worker-sg
          kind: AWSMachineProviderConfig
          tags:
            - name: kubernetes.io/cluster/{{ $.Values.cluster_prefix }}
              value: owned
            - name: 'user:tag'
              value: {{ $.Values.cluster_prefix }}
          deviceIndex: 0
          ami:
            id: ami-094fe1584439e91dd
          subnet:
            filters:
              - name: 'tag:Name'
                values:
                  - {{ $.Values.cluster_prefix }}-private-{{ . }}
          apiVersion: machine.openshift.io/v1beta1
          iamInstanceProfile:
            id: {{ $.Values.cluster_prefix }}-worker-profile
---
{{- end }}
{{ else if eq .Values.cloudProvider "VSphere" }}
{{- $vsphereConfig := (lookup "v1" "ConfigMap" "openshift-machine-api" "vsphere-machines-config") }}
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
  annotations: {}
  name: {{ .Values.cluster_prefix }}-{{ .Values.node_name_prefix }}
  namespace: openshift-machine-api
  labels:
    machine.openshift.io/cluster-api-cluster: {{ .Values.cluster_prefix }}
spec:
  deletePolicy: Oldest
  replicas: {{ .Values.instance_count_per_region }}
  selector:
    matchLabels:
      machine.openshift.io/cluster-api-cluster: {{ .Values.cluster_prefix }}
      machine.openshift.io/cluster-api-machineset: {{ .Values.cluster_prefix }}-{{ .Values.node_name_prefix }}
  template:
    metadata:
      labels:
        machine.openshift.io/cluster-api-cluster: {{ .Values.cluster_prefix }}
        machine.openshift.io/cluster-api-machine-role: worker
        machine.openshift.io/cluster-api-machine-type: worker
        machine.openshift.io/cluster-api-machineset: {{ .Values.cluster_prefix }}-{{ .Values.node_name_prefix }}
    spec:
      taints:
          - effect: NoSchedule
            key: platform/logging
            value: 'true'
      metadata:
        labels:
          platform/logging: 'true'
      providerSpec:
        value:
          numCoresPerSocket: 1
          diskGiB: 120
          snapshot: ''
          userDataSecret:
            name: worker-user-data
          memoryMiB: 32768
          credentialsSecret:
            name: vsphere-cloud-credentials
          network:
            devices:
              - networkName: {{ $vsphereConfig.data.networkName }}
          metadata:
            creationTimestamp: null
          numCPUs: 8
          kind: VSphereMachineProviderSpec
          workspace:
            datacenter: {{ $vsphereConfig.data.datacenter }}
            datastore: {{ $vsphereConfig.data.datastore }}
            {{- if $vsphereConfig.data.folder }}
            folder: /{{ $vsphereConfig.data.datacenter }}/vm/{{ $vsphereConfig.data.folder }}
            {{- else }}
            folder: /{{ $vsphereConfig.data.datacenter }}/vm/{{ .Values.cluster_prefix }}
            {{- end }}
            {{- if $vsphereConfig.data.resourcePool }}
            resourcePool: /{{ $vsphereConfig.data.datacenter }}/host/{{ $vsphereConfig.data.cluster }}/Resources/{{ $vsphereConfig.data.resourcePool }}
            {{- else }}
            resourcePool: /{{ $vsphereConfig.data.datacenter }}/host/{{ $vsphereConfig.data.cluster }}/Resources
            {{- end }}
            server: {{ $vsphereConfig.data.server }}
          template: {{ .Values.cluster_prefix }}-rhcos
          apiVersion: vsphereprovider.openshift.io/v1beta1
{{ else }}
{{ end }}

