runtime: Fail when GCE metadata is inaccessible
When V23_EXPECT_GOOGLE_COMPUTE_ENGINE is set and non-empty, the runtime
will fail to initialize when the GCE metadata server is inaccessible or
some of its data cannot be retrieved.
When V23_EXPECT_GOOGLE_COMPUTE_ENGINE is not set (or is empty), the
previous behavior is preserved, i.e. we give up after 1 second and
assume we're not on GCE.
Production services cannot function properly when the metadata isn't
there. It's better to abort immediately than to keep running in a bad
state.
While at it, clean up the code around cloud VM metadata.
Fixes https://github.com/vanadium/issues/issues/1267
Change-Id: I933f97179b994c83460b2efe6658c8f098689531
diff --git a/runtime/factories/roaming/roaming.go b/runtime/factories/roaming/roaming.go
index 32b596d..7c84342 100644
--- a/runtime/factories/roaming/roaming.go
+++ b/runtime/factories/roaming/roaming.go
@@ -50,6 +50,10 @@
return nil, nil, nil, err
}
+ if err := internal.InitCloudVM(); err != nil {
+ return nil, nil, nil, err
+ }
+
ac := appcycle.New()
discoveryFactory, err := dfactory.New(ctx)
if err != nil {