apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
kind: KubeadmConfigTemplate
metadata:
  name: {{.workloadkubeadmconfigTemplateName}}
  namespace: {{.eksaSystemNamespace}}
spec:
  template:
    spec:
      joinConfiguration:
        nodeRegistration:
          criSocket: /var/run/containerd/containerd.sock
{{- if .workerNodeGroupTaints }}
          taints:{{ range .workerNodeGroupTaints}}
            - key: {{ .Key }}
              value: {{ .Value }}
              effect: {{ .Effect }}
{{- if .TimeAdded }}
              timeAdded: {{ .TimeAdded }}
{{- end }}
{{- end }}
{{- else}}
          taints: []
{{- end }}
          kubeletExtraArgs:
            eviction-hard: nodefs.available<0%,nodefs.inodesFree<0%,imagefs.available<0%
{{- if .kubeletExtraArgs }}
{{ .kubeletExtraArgs.ToYaml | indent 12 }}
{{- end }}
{{- if .registryMirrorMap }}
      files:
{{- end }}
{{- if .registryCACert }}
      - content: |
{{ .registryCACert | indent 10 }}
        owner: root:root
        path: "/etc/containerd/certs.d/{{ .mirrorBase }}/ca.crt"
{{- end }}
{{- if .registryMirrorMap }}
      - content: |
          [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
            {{- range $orig, $mirror := .registryMirrorMap }}
            [plugins."io.containerd.grpc.v1.cri".registry.mirrors."{{ $orig }}"]
              endpoint = ["https://{{ $mirror }}"]
            {{- end }}
            {{- if or .registryCACert .insecureSkip }}
            [plugins."io.containerd.grpc.v1.cri".registry.configs."{{ .mirrorBase }}".tls]
            {{- if .registryCACert }}
              ca_file = "/etc/containerd/certs.d/{{ .mirrorBase }}/ca.crt"
            {{- end }}
            {{- if .insecureSkip }}
              insecure_skip_verify = {{.insecureSkip}}
            {{- end }}
            {{- end }}
            {{- if .registryAuth }}
            [plugins."io.containerd.grpc.v1.cri".registry.configs."{{ .mirrorBase }}".auth]
              username = "{{.registryUsername}}"
              password = "{{.registryPassword}}"
            {{- end }}
        owner: root:root
        path: "/etc/containerd/config_append.toml"
      preKubeadmCommands:
      - cat /etc/containerd/config_append.toml >> /etc/containerd/config.toml
      - systemctl daemon-reload
      - systemctl restart containerd
{{- end }}
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: MachineDeployment
metadata:
  name: {{.workerNodeGroupName}}
  namespace: {{.eksaSystemNamespace}}
{{- if .autoscalingConfig }}
  annotations:
    cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: "{{ .autoscalingConfig.MinCount }}"
    cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: "{{ .autoscalingConfig.MaxCount }}"
{{- end }}
spec:
  clusterName: {{.clusterName}}
  replicas: {{.workerReplicas}}
  selector:
    matchLabels: null
  template:
    spec:
      bootstrap:
        configRef:
          apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
          kind: KubeadmConfigTemplate
          name: {{.workloadkubeadmconfigTemplateName}}
          namespace: {{.eksaSystemNamespace}}
      clusterName: {{.clusterName}}
      infrastructureRef:
        apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
        kind: DockerMachineTemplate
        name: {{.workloadTemplateName}}
        namespace: {{.eksaSystemNamespace}}
      version: {{.kubernetesVersion}}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: DockerMachineTemplate
metadata:
  name: {{.workloadTemplateName}}
  namespace: {{.eksaSystemNamespace}}
spec:
  template:
    spec:
      extraMounts:
      - containerPath: /var/run/docker.sock
        hostPath: /var/run/docker.sock
      customImage: {{.kindNodeImage}}