diff --git a/templates/common/gcp/files/usr-local-bin-update-etc-hosts.yaml b/templates/common/gcp/files/usr-local-bin-update-etc-hosts.yaml new file mode 100644 index 0000000000..28f1e46d3e --- /dev/null +++ b/templates/common/gcp/files/usr-local-bin-update-etc-hosts.yaml @@ -0,0 +1,11 @@ +mode: 0755 +path: "/usr/local/bin/update-etc-hosts" +contents: + inline: | + #!/bin/bash + etc_hosts_config_filename="/etc/hosts/conf.d/etc-hosts.conf" + if [ ! -f "$etc_hosts_config_filename" ]; then + exit 0 + fi + cat /etc/hosts/conf.d/etc-hosts.conf >> /etc/hosts + echo "Done updating /etc/hosts" diff --git a/templates/common/gcp/units/gcp-update-etc-hosts.service.yaml b/templates/common/gcp/units/gcp-update-etc-hosts.service.yaml new file mode 100644 index 0000000000..d1211bb139 --- /dev/null +++ b/templates/common/gcp/units/gcp-update-etc-hosts.service.yaml @@ -0,0 +1,44 @@ +name: gcp-update-etc-hosts.service +enabled: {{if and (eq .Infra.Status.PlatformStatus.Type "GCP") (.Infra.Status.PlatformStatus.GCP) (.Infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig) (eq .Infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig.DNSType "ClusterHosted") }}true{{else}}false{{end}} +contents: | + [Unit] + Description=Update Default GCP /etc/hosts + # We don't need to do this on the firstboot + After=firstboot-osupdate.target + # Wait for NetworkManager to report it's online + After=NetworkManager-wait-online.service + # Run before kubelet + Before=kubelet-dependencies.target + + [Service] + # Need oneshot to delay kubelet + Type=oneshot + ExecStart=/bin/bash -c " \ +{{ if and (eq .Infra.Status.PlatformStatus.Type "GCP") (.Infra.Status.PlatformStatus.GCP) (.Infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig) (eq .Infra.Status.PlatformStatus.GCP.CloudLoadBalancerConfig.DNSType "ClusterHosted") }} + apiLBIPs={{.cloudPlatformAPILoadBalancerIPs}} + apiIntLBIPs={{.cloudPlatformAPIIntLoadBalancerIPs}} +{{ else }} + exit 0 +{{ end }} + if [ -z "${apiIntLBIPs}" ]; then + # We don't have API-Int LB IPs. Nothing to do here. + exit 0 + fi + if [ -z "${apiLBIPs}" ]; then + # Private cluster + apiLBIPs=${apiIntLBIPs} + fi + apiServerURL={{ .Infra.Status.APIServerURL }} + apiServerIntURL={{ .Infra.Status.APIServerInternalURL }} + # Add the/etc/hosts configuration file + mkdir -p /etc/hosts/conf.d + cat <