mirror of https://github.com/k3s-io/k3s
Adding a check to make sure UseInstanceMetadata flag is true to get data from metadata.
parent
7955a2865c
commit
e0f51bcc2e
|
@ -1677,6 +1677,7 @@ func TestGetZone(t *testing.T) {
|
|||
cloud := &Cloud{
|
||||
Config: Config{
|
||||
Location: "eastus",
|
||||
UseInstanceMetadata: true,
|
||||
},
|
||||
}
|
||||
testcases := []struct {
|
||||
|
|
|
@ -19,6 +19,7 @@ package azure
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -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.
|
||||
// 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) {
|
||||
if az.UseInstanceMetadata {
|
||||
metadata, err := az.metadata.GetMetadata()
|
||||
if err != nil {
|
||||
return cloudprovider.Zone{}, err
|
||||
|
@ -75,6 +77,13 @@ func (az *Cloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) {
|
|||
Region: az.Location,
|
||||
}, 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
|
||||
// This is particularly useful in external cloud providers where the kubelet
|
||||
|
|
Loading…
Reference in New Issue