# helm_charts_yarn-nm-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: {{ include "hadoop.fullname" . }}-yarn-nm
  annotations:
    checksum/config: {{ include (print $.Template.BasePath "/hadoop-configmap.yaml") . | sha256sum }}
  labels:
    app: {{ include "hadoop.name" . }}
    chart: {{ include "hadoop.chart" . }}
    release: {{ .Release.Name }}
    component: yarn-nm
spec:
  serviceName: {{ include "hadoop.fullname" . }}-yarn-nm
  replicas: {{ .Values.yarn.nodeManager.replicas }}
  selector:
    matchLabels:
      app: {{ include "hadoop.name" . }}
      release: {{ .Release.Name }}
      component: yarn-nm
{{- if .Values.yarn.nodeManager.parallelCreate }}
  podManagementPolicy: Parallel
{{- end }}
  template:
    metadata:
      labels:
        app: {{ include "hadoop.name" . }}
        release: {{ .Release.Name }}
        component: yarn-nm
    spec:
      affinity:
        podAntiAffinity:
        {{- if eq .Values.antiAffinity "hard" }}
          requiredDuringSchedulingIgnoredDuringExecution:
          - topologyKey: "kubernetes.io/hostname"
            labelSelector:
              matchLabels:
                app:  {{ include "hadoop.name" . }}
                release: {{ .Release.Name | quote }}
                component: yarn-nm
        {{- else if eq .Values.antiAffinity "soft" }}
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 5
            podAffinityTerm:
              topologyKey: "kubernetes.io/hostname"
              labelSelector:
                matchLabels:
                  app:  {{ include "hadoop.name" . }}
                  release: {{ .Release.Name | quote }}
                  component: yarn-nm
        {{- end }}
      terminationGracePeriodSeconds: 0
      containers:
      - name: yarn-nm
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
        ports:
        - containerPort: 8088
          name: web
        command:
           - "/bin/bash"
           - "/tmp/hadoop-config/bootstrap.sh"
           - "-d"
        resources:
{{ toYaml .Values.yarn.nodeManager.resources | indent 10 }}
        readinessProbe:
          httpGet:
            path: /node
            port: 8042
          initialDelaySeconds: 10
          timeoutSeconds: 2
        livenessProbe:
          httpGet:
            path: /node
            port: 8042
          initialDelaySeconds: 10
          timeoutSeconds: 2
        env:
        - name: MY_CPU_LIMIT
          valueFrom:
            resourceFieldRef:
              containerName: yarn-nm
              resource: limits.cpu
              divisor: 1
        - name: MY_MEM_LIMIT
          valueFrom:
            resourceFieldRef:
              containerName: yarn-nm
              resource: limits.memory
              divisor: 1M
        volumeMounts:
        - name: hadoop-config
          mountPath: /tmp/hadoop-config
      volumes:
      - name: hadoop-config
        configMap:
          name: {{ include "hadoop.fullname" . }}