-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OCPBUGS-48469: GCP: Update /etc/hosts file when ClusterHostedDNS is enabled #4800
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: "machineconfigurations.openshift.io/v1" | ||
kind: "ControllerConfig" | ||
spec: | ||
clusterDNSIP: "10.3.0.10" | ||
cloudProviderConfig: "" | ||
etcdInitialCount: 3 | ||
etcdCAData: ZHVtbXkgZXRjZC1jYQo= | ||
rootCAData: ZHVtbXkgcm9vdC1jYQo= | ||
pullSecret: | ||
data: ZHVtbXkgZXRjZC1jYQo= | ||
images: | ||
etcd: image/etcd:1 | ||
setupEtcdEnv: image/setupEtcdEnv:1 | ||
infraImage: image/infraImage:1 | ||
kubeClientAgentImage: image/kubeClientAgentImage:1 | ||
infra: | ||
apiVersion: config.openshift.io/v1 | ||
kind: Infrastructure | ||
status: | ||
apiServerInternalURI: https://api-int.my-test-cluster.installer.team.coreos.systems:6443 | ||
apiServerURL: https://api.my-test-cluster.installer.team.coreos.systems:6443 | ||
etcdDiscoveryDomain: my-test-cluster.installer.team.coreos.systems | ||
infrastructureName: my-test-cluster | ||
platformStatus: | ||
type: "GCP" | ||
gcp: | ||
cloudLoadBalancerConfig: | ||
dnsType: "ClusterHosted" | ||
clusterHosted: | ||
apiLoadBalancerIPs: | ||
- 20.20.20.20 | ||
apiIntLoadBalancerIPs: | ||
- 10.10.10.10 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: "machineconfigurations.openshift.io/v1" | ||
kind: "ControllerConfig" | ||
spec: | ||
clusterDNSIP: "10.3.0.10" | ||
cloudProviderConfig: "" | ||
etcdInitialCount: 3 | ||
etcdCAData: ZHVtbXkgZXRjZC1jYQo= | ||
rootCAData: ZHVtbXkgcm9vdC1jYQo= | ||
pullSecret: | ||
data: ZHVtbXkgZXRjZC1jYQo= | ||
images: | ||
etcd: image/etcd:1 | ||
setupEtcdEnv: image/setupEtcdEnv:1 | ||
infraImage: image/infraImage:1 | ||
kubeClientAgentImage: image/kubeClientAgentImage:1 | ||
infra: | ||
apiVersion: config.openshift.io/v1 | ||
kind: Infrastructure | ||
status: | ||
apiServerInternalURI: https://api-int.my-test-cluster.installer.team.coreos.systems:6443 | ||
apiServerURL: https://api.my-test-cluster.installer.team.coreos.systems:6443 | ||
etcdDiscoveryDomain: my-test-cluster.installer.team.coreos.systems | ||
infrastructureName: my-test-cluster | ||
platformStatus: | ||
type: "GCP" | ||
gcp: | ||
cloudLoadBalancerConfig: | ||
dnsType: "PlatformDefault" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
mode: 0755 | ||
path: "/usr/local/bin/update-etc-hosts" | ||
contents: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potentially a simpler way, avoiding the script and systemd service:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The systemd service is providing us a way to time the running of this script before kubelet. |
||
inline: | | ||
#!/bin/bash | ||
apiLBIP=${1} | ||
apiURL=${2} | ||
apiIntLBIP=${3} | ||
apiIntURL=${4} | ||
if [ -z "$apiLBIP" ]; then | ||
# apiLBIPs are not expected to be set on private clusters | ||
apiLBIP=$apiIntLBIP | ||
fi | ||
mkdir -p /etc/conf.d | ||
etc_hosts_config_filename="/etc/conf.d/etc-hosts.conf" | ||
echo "${apiLBIP} ${apiURL%:*}" >> ${etc_hosts_config_filename} | ||
echo "${apiIntLBIP} ${apiIntURL%:*}" >> ${etc_hosts_config_filename} | ||
cat /etc/conf.d/etc-hosts.conf | ||
cat /etc/conf.d/etc-hosts.conf >> /etc/hosts | ||
echo "Done updating /etc/hosts" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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 (cloudPlatformLBIPAvailable .) (gt (len (cloudPlatformAPIIntLoadBalancerIPs .)) 0) }} \ | ||
apiIntLBIP={{ index (cloudPlatformAPIIntLoadBalancerIPs .) 0 }} \ | ||
{{ end }} \ | ||
{{ if and (cloudPlatformLBIPAvailable .) (gt (len (cloudPlatformAPILoadBalancerIPs .)) 0) }} \ | ||
apiLBIP={{ index (cloudPlatformAPILoadBalancerIPs .) 0 }} \ | ||
{{ end }} \ | ||
apiServerURL={{ .Infra.Status.APIServerURL }} \ | ||
apiServerIntURL={{ .Infra.Status.APIServerInternalURL }} \ | ||
/usr/local/bin/update-etc-hosts ${apiLBIP} ${apiServerURL} ${apiIntLBIP} ${apiServerIntURL}" | ||
|
||
[Install] | ||
RequiredBy=kubelet-dependencies.target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, based on the comment I'd expect some check for clusterhosted in the function. I guess it's implicit since the service enablement is dependent on this field?
(I know we do the same elsewhere in the template rendering, so I'm fine with it as is)