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 \
    {{if eq .IPFamilies "IPv6" -}}
    --prefer-ipv6 \
    {{end -}}
    --retry-on-failure; \
    do \
    sleep 5; \
    done"
  ExecStart=/bin/systemctl daemon-reload

  {{if .Proxy -}}
  EnvironmentFile=/etc/mco/proxy.env
  {{end -}}

  [Install]
  RequiredBy=kubelet.service
