Skip to content

Commit

Permalink
use IP for MDS (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
hopkiw authored Jun 29, 2021
1 parent 0fa7703 commit 6223e90
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
5 changes: 0 additions & 5 deletions google_guest_agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ func run(ctx context.Context) {
opts.Writers = []io.Writer{&serialPort{"COM1"}}
}

setMetadataURL()

var err error
newMetadata, err = getMetadata(ctx, false)
if err == nil {
Expand Down Expand Up @@ -173,9 +171,6 @@ func run(ctx context.Context) {
// not to spam the log on network failures.
if webError == 1 {
if urlErr, ok := err.(*url.Error); ok {
if _, ok := urlErr.Err.(*net.DNSError); ok {
logger.Errorf("DNS error when requesting metadata, check DNS settings and ensure metadata.internal.google is setup in your hosts file.")
}
if _, ok := urlErr.Err.(*net.OpError); ok {
logger.Errorf("Network error when requesting metadata, make sure your instance has an active network and can reach the metadata server.")
}
Expand Down
14 changes: 1 addition & 13 deletions google_guest_agent/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/http"
"strconv"
"strings"
Expand All @@ -32,24 +31,13 @@ import (
const defaultEtag = "NONE"

var (
metadataURL = ""
metadataHost = "metadata.google.internal"
metadataFallback = "169.254.169.254"
metadataPath = "/computeMetadata/v1/"
metadataURL = "http://169.254.169.254/computeMetadata/v1/"
metadataRecursive = "/?recursive=true&alt=json"
metadataHang = "&wait_for_change=true&timeout_sec=60"
defaultTimeout = 70 * time.Second
etag = defaultEtag
)

func setMetadataURL() {
host := metadataHost
if _, err := net.LookupIP(host); err != nil {
host = metadataFallback
}
metadataURL = "http://" + host + metadataPath
}

type metadata struct {
Instance instance
Project project
Expand Down

0 comments on commit 6223e90

Please sign in to comment.