Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
e0f51bcc
Commit
e0f51bcc
authored
Mar 04, 2019
by
Rohit Jaini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a check to make sure UseInstanceMetadata flag is true to get data from metadata.
parent
7955a286
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
22 deletions
+32
-22
azure_test.go
pkg/cloudprovider/providers/azure/azure_test.go
+2
-1
azure_zones.go
pkg/cloudprovider/providers/azure/azure_zones.go
+30
-21
No files found.
pkg/cloudprovider/providers/azure/azure_test.go
View file @
e0f51bcc
...
...
@@ -1676,7 +1676,8 @@ func validateEmptyConfig(t *testing.T, config string) {
func
TestGetZone
(
t
*
testing
.
T
)
{
cloud
:=
&
Cloud
{
Config
:
Config
{
Location
:
"eastus"
,
Location
:
"eastus"
,
UseInstanceMetadata
:
true
,
},
}
testcases
:=
[]
struct
{
...
...
pkg/cloudprovider/providers/azure/azure_zones.go
View file @
e0f51bcc
...
...
@@ -19,6 +19,7 @@ package azure
import
(
"context"
"fmt"
"os"
"strconv"
"strings"
...
...
@@ -49,31 +50,39 @@ 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
)
{
metadata
,
err
:=
az
.
metadata
.
GetMetadata
()
if
err
!=
nil
{
return
cloudprovider
.
Zone
{},
err
}
if
az
.
UseInstanceMetadata
{
metadata
,
err
:=
az
.
metadata
.
GetMetadata
()
if
err
!=
nil
{
return
cloudprovider
.
Zone
{},
err
}
if
metadata
.
Compute
==
nil
{
return
cloudprovider
.
Zone
{},
fmt
.
Errorf
(
"failure of getting compute information from instance metadata"
)
}
if
metadata
.
Compute
==
nil
{
return
cloudprovider
.
Zone
{},
fmt
.
Errorf
(
"failure of getting compute information from instance metadata"
)
}
zone
:=
""
if
metadata
.
Compute
.
Zone
!=
""
{
zoneID
,
err
:=
strconv
.
Atoi
(
metadata
.
Compute
.
Zone
)
if
err
!=
nil
{
return
cloudprovider
.
Zone
{},
fmt
.
Errorf
(
"failed to parse zone ID %q: %v"
,
metadata
.
Compute
.
Zone
,
err
)
zone
:=
""
if
metadata
.
Compute
.
Zone
!=
""
{
zoneID
,
err
:=
strconv
.
Atoi
(
metadata
.
Compute
.
Zone
)
if
err
!=
nil
{
return
cloudprovider
.
Zone
{},
fmt
.
Errorf
(
"failed to parse zone ID %q: %v"
,
metadata
.
Compute
.
Zone
,
err
)
}
zone
=
az
.
makeZone
(
zoneID
)
}
else
{
klog
.
V
(
3
)
.
Infof
(
"Availability zone is not enabled for the node, falling back to fault domain"
)
zone
=
metadata
.
Compute
.
FaultDomain
}
zone
=
az
.
makeZone
(
zoneID
)
}
else
{
klog
.
V
(
3
)
.
Infof
(
"Availability zone is not enabled for the node, falling back to fault domain"
)
zone
=
metadata
.
Compute
.
FaultDomain
}
return
cloudprovider
.
Zone
{
FailureDomain
:
zone
,
Region
:
az
.
Location
,
},
nil
return
cloudprovider
.
Zone
{
FailureDomain
:
zone
,
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment