-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a workaround for the IPv6 issue
We observed intermittent failures during deployment, due to Go resolving Google API domains into IPv6 addresses, even though the Cloud Shell environment has IPv6 disabled. Until the Go issue (golang/go#25321) has been resolved, we have to patch the `/etc/hosts` file on the Cloud Shell machine to ensure that these domains are resolved using IPv4 only. PiperOrigin-RevId: 495598377
- Loading branch information
1 parent
0e6aa28
commit 737b9b0
Showing
5 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
*.swp | ||
__pycache__ | ||
*.pyc | ||
crmint.egg-info/ | ||
|
||
# System Files | ||
.DS_Store | ||
|
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
*.egg-info | ||
stages/*.py | ||
build/ | ||
dist/ |
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
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
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,59 @@ | ||
#!/bin/bash | ||
# | ||
# IPv6 is disabled in Google Cloud Shell, though the DNS resolution in Go | ||
# does not always comply with this setting and from time to time resolves to | ||
# an IPv6 address. | ||
# | ||
# The following workaround as been described proposes, waiting for the Go team | ||
# to solve this properly (https://github.com/golang/go/issues/25321). | ||
# | ||
# See: https://github.com/hashicorp/terraform-provider-google/issues/6782 | ||
# | ||
|
||
# Checks that we run inside a Google VM. | ||
GMETADATA_ADDR=`dig +short metadata.google.internal` | ||
if [[ "${GMETADATA_ADDR}" == "" ]]; then | ||
echo "Not on a Google VM, no need to patch the /etc/hosts file." | ||
exit 0 | ||
fi | ||
|
||
# Backup existing /etc/hosts. | ||
if [ ! -f /etc/hosts.backup ]; then | ||
sudo cp /etc/hosts /etc/hosts.backup | ||
fi | ||
|
||
read -r -d '' APIS << EOM | ||
aiplatform.googleapis.com | ||
analytics.googleapis.com | ||
analyticsadmin.googleapis.com | ||
analyticsreporting.googleapis.com | ||
cloudbuild.googleapis.com | ||
cloudresourcemanager.googleapis.com | ||
cloudscheduler.googleapis.com | ||
compute.googleapis.com | ||
container.googleapis.com | ||
googleapis.com | ||
iam.googleapis.com | ||
logging.googleapis.com | ||
monitoring.googleapis.com | ||
pubsub.googleapis.com | ||
secretmanager.googleapis.com | ||
servicenetworking.googleapis.com | ||
sqladmin.googleapis.com | ||
storage-api.googleapis.com | ||
storage-component.googleapis.com | ||
storage.googleapis.com | ||
www.googleapis.com | ||
EOM | ||
|
||
# Restores the backup content. | ||
sudo sh -c "cat /etc/hosts.backup > /etc/hosts" | ||
|
||
# Adds IPv4 addresses for each Google Cloud API. | ||
sudo sh -c "echo -e '\n# Forcing IPv4 to workaround a Go issue: https://github.com/golang/go/issues/25321' >> /etc/hosts" | ||
for name in $APIS | ||
do | ||
ipv4=$(getent ahostsv4 "$name" | head -n 1 | awk '{ print $1 }') | ||
sudo sh -c "echo '$ipv4 $name' >> /etc/hosts" | ||
echo "Forced IPv4 for $name: $ipv4" | ||
done |