Unverified Commit 61de23c8 authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #75104 from andyzhangx/automated-cherry-pick-of-#74936-upstream-release-1.13

Automated cherry pick of #74936: Adding a check to make sure UseInstanceMetadata flag is true
parents c2b3c96d 33f85d59
...@@ -1678,6 +1678,7 @@ func TestGetZone(t *testing.T) { ...@@ -1678,6 +1678,7 @@ func TestGetZone(t *testing.T) {
cloud := &Cloud{ cloud := &Cloud{
Config: Config{ Config: Config{
Location: "eastus", Location: "eastus",
UseInstanceMetadata: true,
}, },
} }
testcases := []struct { testcases := []struct {
......
...@@ -19,6 +19,7 @@ package azure ...@@ -19,6 +19,7 @@ package azure
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"strconv" "strconv"
"strings" "strings"
...@@ -49,6 +50,7 @@ func (az *Cloud) GetZoneID(zoneLabel string) string { ...@@ -49,6 +50,7 @@ func (az *Cloud) GetZoneID(zoneLabel string) string {
// GetZone returns the Zone containing the current availability zone and locality region that the program is running in. // GetZone returns the Zone containing the current availability zone and locality region that the program is running in.
// If the node is not running with availability zones, then it will fall back to fault domain. // If the node is not running with availability zones, then it will fall back to fault domain.
func (az *Cloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) { func (az *Cloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) {
if az.UseInstanceMetadata {
metadata, err := az.metadata.GetMetadata() metadata, err := az.metadata.GetMetadata()
if err != nil { if err != nil {
return cloudprovider.Zone{}, err return cloudprovider.Zone{}, err
...@@ -74,6 +76,13 @@ func (az *Cloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) { ...@@ -74,6 +76,13 @@ func (az *Cloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) {
FailureDomain: zone, FailureDomain: zone,
Region: az.Location, Region: az.Location,
}, nil }, nil
}
// if UseInstanceMetadata is false, get Zone name by calling ARM
hostname, err := os.Hostname()
if err != nil {
return cloudprovider.Zone{}, fmt.Errorf("failure getting hostname from kernel")
}
return az.vmSet.GetZoneByNodeName(strings.ToLower(hostname))
} }
// GetZoneByProviderID implements Zones.GetZoneByProviderID // GetZoneByProviderID implements Zones.GetZoneByProviderID
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment