# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "skywalking.ui.fullname" . }}
  labels:
    app: {{ template "skywalking.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version }}
    component: "{{ .Values.ui.name }}"
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
spec:
  replicas: {{ .Values.ui.replicas }}
  selector:
    matchLabels:
      app: {{ template "skywalking.name" . }}
      component: "{{ .Values.ui.name }}"
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "skywalking.name" . }}
        component: "{{ .Values.ui.name }}"
        release: {{ .Release.Name }}
        {{- if .Values.ui.podAnnotations }}
      annotations:
{{ toYaml .Values.ui.podAnnotations | indent 8 }}
        {{- end }}
    spec:
      affinity:
      {{- with .Values.ui.nodeAffinity }}
        nodeAffinity:
{{ toYaml . | indent 10 }}
      {{- end }}
{{- if .Values.ui.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.ui.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.ui.tolerations }}
      tolerations:
{{ toYaml .Values.ui.tolerations | indent 8 }}
{{- end }}
{{- if .Values.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.imagePullSecrets | indent 8 }}
{{- end }}
      containers:
      - name: {{ .Values.ui.name }}
        image: {{ .Values.ui.image.repository }}:{{ required "ui.image.tag is required" .Values.ui.image.tag }}
        imagePullPolicy: {{ .Values.ui.image.pullPolicy }}
        ports:
        - containerPort: {{ .Values.ui.service.internalPort }}
          name: page
{{- if .Values.ui.resources }}
        resources:
{{ toYaml .Values.ui.resources | indent 10 }}
{{- end }}
        env:
        - name: SW_OAP_ADDRESS
          value: http://{{ template "skywalking.oap.fullname" . }}:{{ .Values.oap.ports.rest }}
