{{- $vsphereConfig := (lookup "v1" "ConfigMap" "openshift-machine-api" "vsphere-machines-config") }}
apiVersion: machine.openshift.io/v1beta1
kind: MachineSet
metadata:
  annotations: {}
  name: {{ .Values.cluster_prefix }}-{{ .Release.Namespace }}
  namespace: openshift-machine-api
  labels:
    machine.openshift.io/cluster-api-cluster: {{ .Values.cluster_prefix }}
spec:
  deletePolicy: Oldest
  replicas: {{ .Values.global.computeResources.instanceCount }}
  selector:
    matchLabels:
      machine.openshift.io/cluster-api-cluster: {{ .Values.cluster_prefix }}
      machine.openshift.io/cluster-api-machineset: {{ .Values.cluster_prefix }}-{{ .Release.Namespace }}
  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 }}-{{ .Release.Namespace }}
    spec:
      taints:
        - effect: NoSchedule
          key: node/{{ .Release.Namespace }}
          value: 'true'
        - effect: NoExecute
          key: node/{{ .Release.Namespace }}
          value: 'true'
      metadata:
        labels:
          node: {{ .Release.Namespace }}
      providerSpec:
        value:
          numCoresPerSocket: {{ .Values.global.computeResources.vSphereInstanceCoresPerCPUCount }}
          diskGiB: {{ .Values.global.computeResources.instanceVolumeSize }}
          snapshot: ''
          userDataSecret:
            name: worker-user-data
          memoryMiB: {{ .Values.global.computeResources.vSphereInstanceRAMSize }}
          credentialsSecret:
            name: vsphere-cloud-credentials
          network:
            devices:
              - networkName: {{ $vsphereConfig.data.networkName }}
          metadata:
            creationTimestamp: null
          numCPUs: {{ .Values.global.computeResources.vSphereInstanceCPUCount }}
          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
