@@ -21,6 +21,7 @@ limitations under the License.
2121package gce
2222
2323import (
24+ "fmt"
2425 "strconv"
2526
2627 "google.golang.org/api/compute/v1"
@@ -44,7 +45,9 @@ const (
4445
4546// googleInstance implements instance.Instance for the Google compute instance.
4647type googleInstance struct {
47- ci * compute.Instance
48+ ci * compute.Instance
49+ projectID string
50+ zone string
4851}
4952
5053// Name implements instance.Instance.
@@ -66,7 +69,25 @@ func (gi *googleInstance) Addresses() map[string]v1.NodeAddressType {
6669 addrs [ac .NatIP ] = v1 .NodeExternalIP
6770 }
6871 }
69- addrs [gi .ci .Hostname ] = v1 .NodeInternalDNS
72+
73+ // GCE has two types of the internal DNS, so we need to take both
74+ // into the account:
75+ // https://cloud.google.com/compute/docs/internal-dns#instance-fully-qualified-domain-names
76+ // Zonal DNS is present for newer projects and has the following FQDN format:
77+ // [INSTANCE_NAME].[ZONE].c.[PROJECT_ID].internal
78+ zonalDNS := fmt .Sprintf ("%s.%s.c.%s.internal" , gi .ci .Name , gi .zone , gi .projectID )
79+ addrs [zonalDNS ] = v1 .NodeInternalDNS
80+
81+ // Global DNS is present for older projects and has the following FQDN format:
82+ // [INSTANCE_NAME].c.[PROJECT_ID].internal
83+ globalDNS := fmt .Sprintf ("%s.c.%s.internal" , gi .ci .Name , gi .projectID )
84+ addrs [globalDNS ] = v1 .NodeInternalDNS
85+
86+ // GCP provides the search paths to resolve the machine's name,
87+ // so we add is as a DNS name
88+ // https://cloud.google.com/compute/docs/internal-dns#resolv.conf
89+ addrs [gi .ci .Name ] = v1 .NodeInternalDNS
90+
7091 return addrs
7192}
7293
0 commit comments