Vary logic based on the existence of GCE metadata.
@@ -358,22 +358,29 @@ func CreateStackdriverSink(uri *url.URL) (core.DataSink, error) {
}
}
- if err := gce_util.EnsureOnGCE(); err != nil {
- return nil, err
- }
+ var projectId, heapsterZone string
+ if gce.OnGCE() {
// Detect project ID
- projectId, err := gce.ProjectID()
+ projectId, err = gce.ProjectID()
if err != nil {
return nil, err
}
// Detect zone for old resource model
- heapsterZone, err := gce.Zone()
+ heapsterZone, err = gce.Zone()
+ if err != nil {
+ return nil, err
+ }
+ } else {
+ projectId, err = gce_util.GetProjectId()
if err != nil {
return nil, err
}
+ heapsterZone = opts["zone"][0]
+ }
+
clusterLocation := heapsterZone
if len(opts["cluster_location"]) >= 1 {
clusterLocation = opts["cluster_location"][0]
