-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GCP: Update /etc/hosts file when ClusterHostedDNS is enable
Append /etc/hosts files with entries to resolve cluster api and api-int URLS. /etc/hosts will provide resolution for these URLs until kubelet joins the cluster and runs its CoreDNS pod which will then take over resolution of those 2 URLs
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
templates/common/gcp/files/usr-local-bin-update-etc-hosts.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
44 changes: 44 additions & 0 deletions
44
templates/common/gcp/units/gcp-update-etc-hosts.service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <<EOF | tee /etc/hosts/conf.d/etc-hosts.conf | ||
# Added by OpenShift | ||
${apiLBIPs[0]} ${apiServerURL} | ||
${apiIntLBIPs[0]} ${apiServerIntURL} | ||
EOF | ||
# Update /etc/hosts | ||
/usr/local/bin/update-etc-hosts" | ||
|
||
[Install] | ||
RequiredBy=kubelet-dependencies.target |