{{- if .Values.apiServer.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "kubevela.fullname" . }}-apiserver
  namespace: {{ .Release.Namespace }}
  labels:
  {{- include "kubevela.labels" . | nindent 4 }}
spec:
  replicas: {{ .Values.apiServer.replicaCount }}
  selector:
    matchLabels:
  {{- include "kubevela-apiserver.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
    {{- include "kubevela-apiserver.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
      {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "kubevela.serviceAccountName" . }}
      securityContext:
      {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ include "kubevela.fullname" . }}-apiserver
          securityContext:
          {{- toYaml .Values.securityContext | nindent 12 }}
          args:
            - "apiserver"
            - "--bind-addr=0.0.0.0:{{ .Values.apiServer.port }}"
          image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
          imagePullPolicy: {{ quote .Values.image.pullPolicy }}
          resources:
          {{- toYaml .Values.resources | nindent 12 }}
          ports:
            - containerPort: {{ .Values.apiServer.port }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
      {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
      {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
  {{- toYaml . | nindent 8 }}
  {{- end }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "kubevela.fullname" . }}-apiserver
  namespace: {{ .Release.Namespace }}
  labels:
  {{- include "kubevela.labels" . | nindent 4 }}
spec:
  type: {{ .Values.apiServer.Service.type }}
  ports:
    - port: 80
      targetPort: {{ .Values.apiServer.port }}
      protocol: TCP
      name: http
  selector:
  {{- include "kubevela-apiserver.selectorLabels" . | nindent 6 }}
{{- end -}}