dashboard/buildlet: fix start-up crash when TLS attributes aren't set
I had never run the 44d7ecb402b7c on GCE, and never caught that it
crashed on start-up if TLS attributes weren't defined.
Updated to use the new NotDefinedError from the metadata package in
https://code-review.googlesource.com/#/c/1790/
Change-Id: Iaec8df126e4cef8026c930e8cc0163ae088affb3
Reviewed-on: https://go-review.googlesource.com/2736
Reviewed-by: Burcu Dogan <jbd@google.com>
diff --git a/buildlet/buildlet.go b/buildlet/buildlet.go
index a2d911c..ad65b95 100644
--- a/buildlet/buildlet.go
+++ b/buildlet/buildlet.go
@@ -119,6 +119,7 @@
}
// metadataValue returns the GCE metadata instance value for the given key.
+// If the metadata is not defined, the returned string is empty.
//
// If not running on GCE, it falls back to using environment variables
// for local development.
@@ -126,6 +127,9 @@
// The common case:
if metadata.OnGCE() {
v, err := metadata.InstanceAttributeValue(key)
+ if _, notDefined := err.(metadata.NotDefinedError); notDefined {
+ return ""
+ }
if err != nil {
log.Fatalf("metadata.InstanceAttributeValue(%q): %v", key, err)
}