# helm_charts_spark-master-deployment.yaml
apiVersion: v1
kind: Service
metadata:
  name: {{ template "master-fullname" . }}
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    component: "{{ .Release.Name }}-{{ .Values.Master.Component }}"
spec:
  ports:
    - port: {{ .Values.Master.ServicePort }}
      targetPort: {{ .Values.Master.ContainerPort }}
  selector:
    component: "{{ .Release.Name }}-{{ .Values.Master.Component }}"
---
apiVersion: v1
kind: Service
metadata:
  name: {{ template "webui-fullname" . }}
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    component: "{{ .Release.Name }}-{{ .Values.Master.Component }}"
spec:
  ports:
    - port: {{ .Values.WebUi.ServicePort }}
      targetPort: {{ .Values.WebUi.ContainerPort }}
  selector:
    component: "{{ .Release.Name }}-{{ .Values.Master.Component }}"
  type: {{ .Values.Master.ServiceType }}
---
apiVersion: {{ template "deployment.apiVersion" . }}
kind: Deployment
metadata:
  name: {{ template "master-fullname" . }}
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    component: "{{ .Release.Name }}-{{ .Values.Master.Component }}"
spec:
  replicas: {{ default 1 .Values.Master.Replicas }}
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      component: "{{ .Release.Name }}-{{ .Values.Master.Component }}"
  template:
    metadata:
      labels:
        heritage: {{ .Release.Service | quote }}
        release: {{ .Release.Name | quote }}
        chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
        component: "{{ .Release.Name }}-{{ .Values.Master.Component }}"
    spec:
      containers:
        - name: {{ template "master-fullname" . }}
          image: "{{ .Values.Master.Image }}:{{ .Values.Master.ImageTag }}"
          command: ["/bin/sh","-c"]
          args: ["echo $(hostname -i) {{ template "master-fullname" . }} >> /etc/hosts; {{ .Values.Spark.Path }}/bin/spark-class org.apache.spark.deploy.master.Master"]
          ports:
            - containerPort: {{ .Values.Master.ContainerPort }}
            - containerPort: {{ .Values.WebUi.ContainerPort }}
          resources:
            requests:
              cpu: "{{ .Values.Master.Cpu }}"
              memory: "{{ .Values.Master.Memory }}"
          env:
          - name: SPARK_DAEMON_MEMORY
            value: {{ default "1g" .Values.Master.DaemonMemory | quote }}
          - name: SPARK_MASTER_HOST
            value: {{ template "master-fullname" . }}
          - name: SPARK_MASTER_PORT
            value: {{ .Values.Master.ServicePort | quote }}
          - name: SPARK_MASTER_WEBUI_PORT
            value: {{ .Values.WebUi.ContainerPort | quote }}