{{/*
Licensed 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.
*/}}

{{- if .Values.manifests.deployment_ironic_agent }}
{{- $envAll := . }}

{{- $dependencyOpts := dict "envAll" $envAll "dependencyMixinParam" $envAll.Values.network.backend "dependencyKey" "ironic_agent" -}}
{{- $_ := include "helm-toolkit.utils.dependency_resolver" $dependencyOpts | toString | fromYaml }}

{{- $mounts_neutron_ironic_agent := .Values.pod.mounts.neutron_ironic_agent.neutron_ironic_agent }}
{{- $mounts_neutron_ironic_agent_init := .Values.pod.mounts.neutron_ironic_agent.init_container }}
{{- $etcSources := .Values.pod.etcSources.neutron_ironic_agent }}
{{- if .Values.manifests.secret_ks_etc }}
{{- $etcSources = append $etcSources (dict "secret" (dict "name" "neutron-ks-etc")) }}
{{- end }}

{{- $serviceAccountName := "neutron-ironic-agent" }}
{{ tuple $envAll "pod_dependency" $serviceAccountName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: neutron-ironic-agent
  annotations:
    {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }}
  labels:
{{ tuple $envAll "neutron" "ironic-agent" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 4 }}
spec:
  replicas: {{ .Values.pod.replicas.ironic_agent }}
  selector:
    matchLabels:
{{ tuple $envAll "neutron" "ironic-agent" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 6 }}
{{ tuple $envAll | include "helm-toolkit.snippets.kubernetes_upgrades_deployment" | indent 2 }}
  template:
    metadata:
      labels:
{{ tuple $envAll "neutron" "ironic-agent" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }}
      annotations:
{{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" | indent 8 }}
        configmap-bin-hash: {{ tuple "configmap-bin.yaml" . | include "helm-toolkit.utils.hash" }}
        configmap-etc-hash: {{ tuple "configmap-etc.yaml" . | include "helm-toolkit.utils.hash" }}
{{ tuple "neutron_ironic_agent" . | include "helm-toolkit.snippets.custom_pod_annotations" | indent 8 }}
    spec:
{{ dict "envAll" $envAll "application" "neutron_ironic_agent" | include "helm-toolkit.snippets.kubernetes_pod_security_context" | indent 6 }}
{{ tuple "neutron_ironic_agent" . | include "helm-toolkit.snippets.kubernetes_pod_priority_class" | indent 6 }}
{{ tuple "neutron_ironic_agent" . | include "helm-toolkit.snippets.kubernetes_pod_runtime_class" | indent 6 }}
      serviceAccountName: {{ $serviceAccountName }}
      affinity:
{{ tuple $envAll "neutron" "ironic_agent" | include "helm-toolkit.snippets.kubernetes_pod_anti_affinity" | indent 8 }}
      nodeSelector:
        {{ .Values.labels.ironic_agent.node_selector_key }}: {{ .Values.labels.ironic_agent.node_selector_value }}
{{ if $envAll.Values.pod.tolerations.neutron.enabled }}
{{ tuple $envAll "neutron" | include "helm-toolkit.snippets.kubernetes_tolerations" | indent 8 }}
{{ end }}
      terminationGracePeriodSeconds: {{ .Values.pod.lifecycle.termination_grace_period.ironic_agent.timeout | default "30" }}
      initContainers:
{{ tuple $envAll "pod_dependency" $mounts_neutron_ironic_agent_init | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 8 }}
        - name: neutron-ironic-agent-init
{{ tuple $envAll "neutron_ironic_agent_init" | include "helm-toolkit.snippets.image" | indent 10 }}
{{ tuple $envAll $envAll.Values.pod.resources.ironic_agent | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
{{ dict "envAll" $envAll "application" "neutron_ironic_agent" "container" "neutron_ironic_agent_init" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }}
          command:
            - /tmp/neutron-ironic-agent-init.sh
          volumeMounts:
            - name: pod-shared
              mountPath: /tmp/pod-shared
            - name: neutron-bin
              mountPath: /tmp/neutron-ironic-agent-init.sh
              subPath: neutron-ironic-agent-init.sh
              readOnly: true
      containers:
        - name: neutron-ironic-agent
{{ tuple $envAll "neutron_ironic_agent" | include "helm-toolkit.snippets.image" | indent 10 }}
{{ tuple $envAll $envAll.Values.pod.resources.ironic_agent | include "helm-toolkit.snippets.kubernetes_resources" | indent 10 }}
{{ dict "envAll" $envAll "application" "neutron_ironic_agent" "container" "neutron_ironic_agent" | include "helm-toolkit.snippets.kubernetes_container_security_context" | indent 10 }}
          command:
            - /tmp/neutron-ironic-agent.sh
            - start
          lifecycle:
            preStop:
              exec:
                command:
                  - /tmp/neutron-ironic-agent.sh
                  - stop
          volumeMounts:
            - name: pod-tmp
              mountPath: /tmp
            - name: oslo-lock-path
              mountPath: {{ .Values.conf.neutron.oslo_concurrency.lock_path }}
            - name: pod-var-neutron
              mountPath: {{ .Values.conf.neutron.DEFAULT.state_path }}
            - name: pod-shared
              mountPath: /tmp/pod-shared
            - name: neutron-bin
              mountPath: /tmp/neutron-ironic-agent.sh
              subPath: neutron-ironic-agent.sh
              readOnly: true
            - name: neutron-etc
              mountPath: /etc/neutron/neutron.conf
              subPath: neutron.conf
              readOnly: true
            - name: neutron-etc-snippets
              mountPath: /etc/neutron/neutron.conf.d/
              readOnly: true
            {{- if .Values.conf.neutron.DEFAULT.log_config_append }}
            - name: neutron-etc
              mountPath: {{ .Values.conf.neutron.DEFAULT.log_config_append }}
              subPath: {{ base .Values.conf.neutron.DEFAULT.log_config_append }}
              readOnly: true
            {{- end }}
            - name: neutron-etc
              mountPath: /etc/neutron/plugins/ml2/ml2_conf.ini
              subPath: ml2_conf.ini
              readOnly: true
{{- dict "enabled" $envAll.Values.manifests.certificates "name" $envAll.Values.endpoints.oslo_messaging.auth.admin.secret.tls.internal "path" "/etc/rabbitmq/certs" | include "helm-toolkit.snippets.tls_volume_mount" | indent 12 }}
{{ if $mounts_neutron_ironic_agent.volumeMounts }}{{ toYaml $mounts_neutron_ironic_agent.volumeMounts | indent 12 }}{{ end }}
      volumes:
        - name: pod-tmp
          emptyDir: {}
        - name: oslo-lock-path
          emptyDir: {}
        - name: pod-var-neutron
          emptyDir: {}
        - name: pod-shared
          emptyDir: {}
        - name: neutron-bin
          configMap:
            name: neutron-bin
            defaultMode: 0555
        - name: neutron-etc
          secret:
            secretName: neutron-etc
            defaultMode: 0444
        - name: neutron-etc-snippets
{{- if $etcSources }}
          projected:
            sources:
{{ toYaml $etcSources | indent 14 }}
{{- else }}
          emptyDir: {}
{{ end }}
{{- dict "enabled" $envAll.Values.manifests.certificates "name" $envAll.Values.endpoints.oslo_messaging.auth.admin.secret.tls.internal | include "helm-toolkit.snippets.tls_volume" | indent 8 }}
{{ if $mounts_neutron_ironic_agent.volumes }}{{ toYaml $mounts_neutron_ironic_agent.volumes | indent 8 }}{{ end }}
{{- end }}
