mode: 0644
path: "/etc/kubernetes/manifests/mdns-publisher.yaml"
contents:
  inline: |
    {{ if .Infra -}}
    {{ if .Infra.Status -}}
    {{ if .Infra.Status.PlatformStatus -}}
    {{ if .Infra.Status.PlatformStatus.VSphere -}}
    {{ if .Infra.Status.PlatformStatus.VSphere.APIServerInternalIP -}}
    kind: Pod
    apiVersion: v1
    metadata:
      name: mdns-publisher
      namespace: openshift-vsphere-infra
      creationTimestamp:
      deletionGracePeriodSeconds: 65
      labels:
        app: vsphere-infra-mdns
    spec:
      volumes:
      - name: resource-dir
        hostPath:
          path: "/etc/kubernetes/static-pod-resources/mdns"
      - name: kubeconfig
        hostPath:
          path: "/etc/kubernetes/kubeconfig"
      - name: conf-dir
        hostPath:
          path: "/etc/mdns"
      initContainers:
      - name: verify-hostname
        image: {{ .Images.baremetalRuntimeCfgImage }}
        env:
          - name: RUNTIMECFG_HOSTNAME_PATH
            value: "/etc/mdns/hostname"
        command:
        - "/bin/bash"
        - "-c"
        - |
          #!/bin/bash
          set -xv
          function get_hostname()
          {
            if [[ -s $RUNTIMECFG_HOSTNAME_PATH ]]; then
              cat $RUNTIMECFG_HOSTNAME_PATH
            else
              # if hostname wasn't updated by NM script, read hostname
              hostname
            fi
          }
          while [[ "$(get_hostname)" =~ ^localhost(.localdomain)?$ ]]; do
            echo "hostname is still set to a default value"
            sleep 1
          done
        volumeMounts:
        - name: conf-dir
          mountPath: "/etc/mdns"
      - name: render-config-mdns-publisher
        image: {{ .Images.baremetalRuntimeCfgImage }}
        env:
          - name: RUNTIMECFG_HOSTNAME_PATH
            value: "/etc/mdns/hostname"
        command:
        - runtimecfg
        - render
        - "/etc/kubernetes/kubeconfig"
        - "--api-vip"
        - "{{ .Infra.Status.PlatformStatus.VSphere.APIServerInternalIP }}"
        - "--ingress-vip"
        - "{{ .Infra.Status.PlatformStatus.VSphere.IngressIP }}"
        - "/config"
        - "--out-dir"
        - "/etc/mdns"
        - "--verbose"
        resources: {}
        volumeMounts:
        - name: kubeconfig
          mountPath: "/etc/kubernetes/kubeconfig"
        - name: resource-dir
          mountPath: "/config"
        - name: conf-dir
          mountPath: "/etc/mdns"
        imagePullPolicy: IfNotPresent
      containers:
      - name: mdns-publisher
        image: {{.Images.mdnsPublisherImage}}
        args:
        - "--debug"
        resources:
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: conf-dir
          mountPath: "/etc/mdns"
        livenessProbe:
          exec:
            command:
            - pgrep
            - mdns-publisher
          initialDelaySeconds: 10
        terminationMessagePolicy: FallbackToLogsOnError
        imagePullPolicy: IfNotPresent
      hostNetwork: true
      tolerations:
      - operator: Exists
      priorityClassName: system-node-critical
    status: {}
    {{ end -}}
    {{ end -}}
    {{ end -}}
    {{ end -}}
    {{ end -}}
