name: nodeip-configuration.service
enabled: {{if eq .Infra.Status.PlatformStatus.Type "None"}}true{{else}}false{{end}}
contents: |
  [Unit]
  Description=Writes IP address configuration so that kubelet and crio services select a valid node IP
  Wants=network-online.target
  After=network-online.target ignition-firstboot-complete.service
  Before=kubelet.service crio.service

  [Service]
  # Need oneshot to delay kubelet
  Type=oneshot
  # Would prefer to do Restart=on-failure instead of this bash retry loop, but
  # the version of systemd we have right now doesn't support it. It should be
  # available in systemd v244 and higher.
  ExecStart=/bin/bash -c " \
    until \
    /usr/bin/podman run --rm \
    --authfile /var/lib/kubelet/config.json \
    --net=host \
    --volume /etc/systemd/system:/etc/systemd/system:z \
    {{ .Images.baremetalRuntimeCfgImage }} \
    node-ip \
    set --retry-on-failure; \
    do \
    sleep 5; \
    done"

  {{if .Proxy -}}
  {{if .Proxy.HTTPProxy -}}
  Environment=HTTP_PROXY={{.Proxy.HTTPProxy}}
  {{end -}}
  {{if .Proxy.HTTPSProxy -}}
  Environment=HTTPS_PROXY={{.Proxy.HTTPSProxy}}
  {{end -}}
  {{if .Proxy.NoProxy -}}
  Environment=NO_PROXY={{.Proxy.NoProxy}}
  {{end -}}
  {{end -}}

  [Install]
  RequiredBy=kubelet.service
