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
e03f02a5
Commit
e03f02a5
authored
Jul 19, 2017
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
metadata improvements.
parent
9af1ff3d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
10 deletions
+49
-10
azure_instance_metadata.go
pkg/cloudprovider/providers/azure/azure_instance_metadata.go
+5
-5
azure_instances.go
pkg/cloudprovider/providers/azure/azure_instances.go
+43
-4
azure_test.go
pkg/cloudprovider/providers/azure/azure_test.go
+1
-1
No files found.
pkg/cloudprovider/providers/azure/azure_instance_metadata.go
View file @
e03f02a5
...
@@ -54,7 +54,7 @@ type Subnet struct {
...
@@ -54,7 +54,7 @@ type Subnet struct {
Prefix
string
`json:"prefix"`
Prefix
string
`json:"prefix"`
}
}
// InstanceMetadata
represents access to
the Azure instance metadata server.
// InstanceMetadata
knows how to query
the Azure instance metadata server.
type
InstanceMetadata
struct
{
type
InstanceMetadata
struct
{
baseURL
string
baseURL
string
}
}
...
@@ -71,8 +71,8 @@ func (i *InstanceMetadata) makeMetadataURL(path string) string {
...
@@ -71,8 +71,8 @@ func (i *InstanceMetadata) makeMetadataURL(path string) string {
return
i
.
baseURL
+
path
return
i
.
baseURL
+
path
}
}
//
QueryMetadataJSON
queries the metadata server and populates the passed in object
//
Object
queries the metadata server and populates the passed in object
func
(
i
*
InstanceMetadata
)
QueryMetadataJSON
(
path
string
,
obj
interface
{})
error
{
func
(
i
*
InstanceMetadata
)
Object
(
path
string
,
obj
interface
{})
error
{
data
,
err
:=
i
.
queryMetadataBytes
(
path
,
"json"
)
data
,
err
:=
i
.
queryMetadataBytes
(
path
,
"json"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -80,8 +80,8 @@ func (i *InstanceMetadata) QueryMetadataJSON(path string, obj interface{}) error
...
@@ -80,8 +80,8 @@ func (i *InstanceMetadata) QueryMetadataJSON(path string, obj interface{}) error
return
json
.
Unmarshal
(
data
,
obj
)
return
json
.
Unmarshal
(
data
,
obj
)
}
}
//
QueryMetadata
Text queries the metadata server and returns the corresponding text
// Text queries the metadata server and returns the corresponding text
func
(
i
*
InstanceMetadata
)
QueryMetadata
Text
(
path
string
)
(
string
,
error
)
{
func
(
i
*
InstanceMetadata
)
Text
(
path
string
)
(
string
,
error
)
{
data
,
err
:=
i
.
queryMetadataBytes
(
path
,
"text"
)
data
,
err
:=
i
.
queryMetadataBytes
(
path
,
"text"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
...
pkg/cloudprovider/providers/azure/azure_instances.go
View file @
e03f02a5
...
@@ -30,14 +30,23 @@ import (
...
@@ -30,14 +30,23 @@ import (
// NodeAddresses returns the addresses of the specified instance.
// NodeAddresses returns the addresses of the specified instance.
func
(
az
*
Cloud
)
NodeAddresses
(
name
types
.
NodeName
)
([]
v1
.
NodeAddress
,
error
)
{
func
(
az
*
Cloud
)
NodeAddresses
(
name
types
.
NodeName
)
([]
v1
.
NodeAddress
,
error
)
{
if
az
.
UseInstanceMetadata
{
if
az
.
UseInstanceMetadata
{
text
,
err
:=
az
.
metadata
.
QueryMetadataText
(
"instance/network/interface/0/ipv4/ipAddress/0/privateIpAddress"
)
ipAddress
:=
IPAddress
{}
err
:=
az
.
metadata
.
Object
(
"instance/network/interface/0/ipv4/ipAddress/0"
,
&
ipAddress
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
[]
v1
.
NodeAddress
{
addresses
:=
[]
v1
.
NodeAddress
{
{
Type
:
v1
.
NodeInternalIP
,
Address
:
text
},
{
Type
:
v1
.
NodeInternalIP
,
Address
:
ipAddress
.
PrivateIP
},
{
Type
:
v1
.
NodeHostName
,
Address
:
string
(
name
)},
{
Type
:
v1
.
NodeHostName
,
Address
:
string
(
name
)},
},
nil
}
if
len
(
ipAddress
.
PublicIP
)
>
0
{
addr
:=
v1
.
NodeAddress
{
Type
:
v1
.
NodeExternalIP
,
Address
:
ipAddress
.
PublicIP
,
}
addresses
=
append
(
addresses
,
addr
)
}
return
addresses
,
nil
}
}
ip
,
err
:=
az
.
getIPForMachine
(
name
)
ip
,
err
:=
az
.
getIPForMachine
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -77,9 +86,27 @@ func (az *Cloud) ExternalID(name types.NodeName) (string, error) {
...
@@ -77,9 +86,27 @@ func (az *Cloud) ExternalID(name types.NodeName) (string, error) {
return
az
.
InstanceID
(
name
)
return
az
.
InstanceID
(
name
)
}
}
func
(
az
*
Cloud
)
isCurrentInstance
(
name
types
.
NodeName
)
(
bool
,
error
)
{
nodeName
:=
mapNodeNameToVMName
(
name
)
metadataName
,
err
:=
az
.
metadata
.
Text
(
"instance/compute/name"
)
return
(
metadataName
==
nodeName
),
err
}
// InstanceID returns the cloud provider ID of the specified instance.
// InstanceID returns the cloud provider ID of the specified instance.
// Note that if the instance does not exist or is no longer running, we must return ("", cloudprovider.InstanceNotFound)
// Note that if the instance does not exist or is no longer running, we must return ("", cloudprovider.InstanceNotFound)
func
(
az
*
Cloud
)
InstanceID
(
name
types
.
NodeName
)
(
string
,
error
)
{
func
(
az
*
Cloud
)
InstanceID
(
name
types
.
NodeName
)
(
string
,
error
)
{
if
az
.
UseInstanceMetadata
{
isLocalInstance
,
err
:=
az
.
isCurrentInstance
(
name
)
if
err
!=
nil
{
return
""
,
err
}
if
isLocalInstance
{
externalInstanceID
,
err
:=
az
.
metadata
.
Text
(
"instance/compute/vmId"
)
if
err
==
nil
{
return
externalInstanceID
,
nil
}
}
}
var
machine
compute
.
VirtualMachine
var
machine
compute
.
VirtualMachine
var
exists
bool
var
exists
bool
var
err
error
var
err
error
...
@@ -119,6 +146,18 @@ func (az *Cloud) InstanceTypeByProviderID(providerID string) (string, error) {
...
@@ -119,6 +146,18 @@ func (az *Cloud) InstanceTypeByProviderID(providerID string) (string, error) {
// (Implementer Note): This is used by kubelet. Kubelet will label the node. Real log from kubelet:
// (Implementer Note): This is used by kubelet. Kubelet will label the node. Real log from kubelet:
// Adding node label from cloud provider: beta.kubernetes.io/instance-type=[value]
// Adding node label from cloud provider: beta.kubernetes.io/instance-type=[value]
func
(
az
*
Cloud
)
InstanceType
(
name
types
.
NodeName
)
(
string
,
error
)
{
func
(
az
*
Cloud
)
InstanceType
(
name
types
.
NodeName
)
(
string
,
error
)
{
if
az
.
UseInstanceMetadata
{
isLocalInstance
,
err
:=
az
.
isCurrentInstance
(
name
)
if
err
!=
nil
{
return
""
,
err
}
if
isLocalInstance
{
machineType
,
err
:=
az
.
metadata
.
Text
(
"instance/compute/vmSize"
)
if
err
==
nil
{
return
machineType
,
nil
}
}
}
machine
,
exists
,
err
:=
az
.
getVirtualMachine
(
name
)
machine
,
exists
,
err
:=
az
.
getVirtualMachine
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"error: az.InstanceType(%s), az.getVirtualMachine(%s) err=%v"
,
name
,
name
,
err
)
glog
.
Errorf
(
"error: az.InstanceType(%s), az.getVirtualMachine(%s) err=%v"
,
name
,
name
,
err
)
...
...
pkg/cloudprovider/providers/azure/azure_test.go
View file @
e03f02a5
...
@@ -879,7 +879,7 @@ func TestMetadataParsing(t *testing.T) {
...
@@ -879,7 +879,7 @@ func TestMetadataParsing(t *testing.T) {
}
}
networkJSON
:=
NetworkMetadata
{}
networkJSON
:=
NetworkMetadata
{}
if
err
:=
metadata
.
QueryMetadataJSON
(
"/some/path"
,
&
networkJSON
);
err
!=
nil
{
if
err
:=
metadata
.
Object
(
"/some/path"
,
&
networkJSON
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
}
...
...
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