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
67069cc1
Commit
67069cc1
authored
Sep 21, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix nodes power state on Azure
parent
0c289331
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
11 deletions
+58
-11
azure_fakes.go
pkg/cloudprovider/providers/azure/azure_fakes.go
+1
-1
azure_instances.go
pkg/cloudprovider/providers/azure/azure_instances.go
+9
-2
azure_standard.go
pkg/cloudprovider/providers/azure/azure_standard.go
+14
-3
azure_vmsets.go
pkg/cloudprovider/providers/azure/azure_vmsets.go
+2
-2
azure_vmss.go
pkg/cloudprovider/providers/azure/azure_vmss.go
+14
-3
azure_vmss_cache.go
pkg/cloudprovider/providers/azure/azure_vmss_cache.go
+18
-0
No files found.
pkg/cloudprovider/providers/azure/azure_fakes.go
View file @
67069cc1
...
@@ -894,6 +894,6 @@ func (f *fakeVMSet) GetDataDisks(nodeName types.NodeName) ([]compute.DataDisk, e
...
@@ -894,6 +894,6 @@ func (f *fakeVMSet) GetDataDisks(nodeName types.NodeName) ([]compute.DataDisk, e
return
nil
,
fmt
.
Errorf
(
"unimplemented"
)
return
nil
,
fmt
.
Errorf
(
"unimplemented"
)
}
}
func
(
f
*
fakeVMSet
)
GetP
rovisioningState
ByNodeName
(
name
string
)
(
string
,
error
)
{
func
(
f
*
fakeVMSet
)
GetP
owerStatus
ByNodeName
(
name
string
)
(
string
,
error
)
{
return
""
,
fmt
.
Errorf
(
"unimplemented"
)
return
""
,
fmt
.
Errorf
(
"unimplemented"
)
}
}
pkg/cloudprovider/providers/azure/azure_instances.go
View file @
67069cc1
...
@@ -28,6 +28,12 @@ import (
...
@@ -28,6 +28,12 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/types"
)
)
const
(
vmPowerStatePrefix
=
"PowerState/"
vmPowerStateStopped
=
"stopped"
vmPowerStateDeallocated
=
"deallocated"
)
// NodeAddresses returns the addresses of the specified instance.
// NodeAddresses returns the addresses of the specified instance.
func
(
az
*
Cloud
)
NodeAddresses
(
ctx
context
.
Context
,
name
types
.
NodeName
)
([]
v1
.
NodeAddress
,
error
)
{
func
(
az
*
Cloud
)
NodeAddresses
(
ctx
context
.
Context
,
name
types
.
NodeName
)
([]
v1
.
NodeAddress
,
error
)
{
// Returns nil for unmanaged nodes because azure cloud provider couldn't fetch information for them.
// Returns nil for unmanaged nodes because azure cloud provider couldn't fetch information for them.
...
@@ -148,12 +154,13 @@ func (az *Cloud) InstanceShutdownByProviderID(ctx context.Context, providerID st
...
@@ -148,12 +154,13 @@ func (az *Cloud) InstanceShutdownByProviderID(ctx context.Context, providerID st
return
false
,
err
return
false
,
err
}
}
p
rovisioningState
,
err
:=
az
.
vmSet
.
GetProvisioningState
ByNodeName
(
string
(
nodeName
))
p
owerStatus
,
err
:=
az
.
vmSet
.
GetPowerStatus
ByNodeName
(
string
(
nodeName
))
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
false
,
err
}
}
glog
.
V
(
5
)
.
Infof
(
"InstanceShutdownByProviderID gets power status %q for node %q"
,
powerStatus
,
nodeName
)
return
strings
.
ToLower
(
p
rovisioningState
)
==
"stopped"
||
strings
.
ToLower
(
provisioningState
)
==
"deallocated"
,
nil
return
strings
.
ToLower
(
p
owerStatus
)
==
vmPowerStateStopped
||
strings
.
ToLower
(
powerStatus
)
==
vmPowerStateDeallocated
,
nil
}
}
// getComputeMetadata gets compute information from instance metadata.
// getComputeMetadata gets compute information from instance metadata.
...
...
pkg/cloudprovider/providers/azure/azure_standard.go
View file @
67069cc1
...
@@ -346,13 +346,24 @@ func (as *availabilitySet) GetInstanceIDByNodeName(name string) (string, error)
...
@@ -346,13 +346,24 @@ func (as *availabilitySet) GetInstanceIDByNodeName(name string) (string, error)
return
*
machine
.
ID
,
nil
return
*
machine
.
ID
,
nil
}
}
func
(
as
*
availabilitySet
)
GetProvisioningStateByNodeName
(
name
string
)
(
provisioningState
string
,
err
error
)
{
// GetPowerStatusByNodeName returns the power state of the specified node.
func
(
as
*
availabilitySet
)
GetPowerStatusByNodeName
(
name
string
)
(
powerState
string
,
err
error
)
{
vm
,
err
:=
as
.
getVirtualMachine
(
types
.
NodeName
(
name
))
vm
,
err
:=
as
.
getVirtualMachine
(
types
.
NodeName
(
name
))
if
err
!=
nil
{
if
err
!=
nil
{
return
p
rovisioning
State
,
err
return
p
ower
State
,
err
}
}
return
*
vm
.
ProvisioningState
,
nil
if
vm
.
InstanceView
!=
nil
&&
vm
.
InstanceView
.
Statuses
!=
nil
{
statuses
:=
*
vm
.
InstanceView
.
Statuses
for
_
,
status
:=
range
statuses
{
state
:=
to
.
String
(
status
.
Code
)
if
strings
.
HasPrefix
(
state
,
vmPowerStatePrefix
)
{
return
strings
.
TrimPrefix
(
state
,
vmPowerStatePrefix
),
nil
}
}
}
return
""
,
fmt
.
Errorf
(
"failed to get power status for node %q"
,
name
)
}
}
// GetNodeNameByProviderID gets the node name by provider ID.
// GetNodeNameByProviderID gets the node name by provider ID.
...
...
pkg/cloudprovider/providers/azure/azure_vmsets.go
View file @
67069cc1
...
@@ -65,6 +65,6 @@ type VMSet interface {
...
@@ -65,6 +65,6 @@ type VMSet interface {
// GetDataDisks gets a list of data disks attached to the node.
// GetDataDisks gets a list of data disks attached to the node.
GetDataDisks
(
nodeName
types
.
NodeName
)
([]
compute
.
DataDisk
,
error
)
GetDataDisks
(
nodeName
types
.
NodeName
)
([]
compute
.
DataDisk
,
error
)
// GetP
rovisioningStateByNodeName gets the provisioning state by node nam
e.
// GetP
owerStatusByNodeName returns the power state of the specified nod
e.
GetP
rovisioningState
ByNodeName
(
name
string
)
(
string
,
error
)
GetP
owerStatus
ByNodeName
(
name
string
)
(
string
,
error
)
}
}
pkg/cloudprovider/providers/azure/azure_vmss.go
View file @
67069cc1
...
@@ -128,13 +128,24 @@ func (ss *scaleSet) getVmssVM(nodeName string) (ssName, instanceID string, vm co
...
@@ -128,13 +128,24 @@ func (ss *scaleSet) getVmssVM(nodeName string) (ssName, instanceID string, vm co
return
ssName
,
instanceID
,
*
(
cachedVM
.
(
*
compute
.
VirtualMachineScaleSetVM
)),
nil
return
ssName
,
instanceID
,
*
(
cachedVM
.
(
*
compute
.
VirtualMachineScaleSetVM
)),
nil
}
}
func
(
ss
*
scaleSet
)
GetProvisioningStateByNodeName
(
name
string
)
(
provisioningState
string
,
err
error
)
{
// GetPowerStatusByNodeName returns the power state of the specified node.
func
(
ss
*
scaleSet
)
GetPowerStatusByNodeName
(
name
string
)
(
powerState
string
,
err
error
)
{
_
,
_
,
vm
,
err
:=
ss
.
getVmssVM
(
name
)
_
,
_
,
vm
,
err
:=
ss
.
getVmssVM
(
name
)
if
err
!=
nil
{
if
err
!=
nil
{
return
p
rovisioning
State
,
err
return
p
ower
State
,
err
}
}
return
*
vm
.
ProvisioningState
,
nil
if
vm
.
InstanceView
!=
nil
&&
vm
.
InstanceView
.
Statuses
!=
nil
{
statuses
:=
*
vm
.
InstanceView
.
Statuses
for
_
,
status
:=
range
statuses
{
state
:=
to
.
String
(
status
.
Code
)
if
strings
.
HasPrefix
(
state
,
vmPowerStatePrefix
)
{
return
strings
.
TrimPrefix
(
state
,
vmPowerStatePrefix
),
nil
}
}
}
return
""
,
fmt
.
Errorf
(
"failed to get power status for node %q"
,
name
)
}
}
// getCachedVirtualMachineByInstanceID gets scaleSetVMInfo from cache.
// getCachedVirtualMachineByInstanceID gets scaleSetVMInfo from cache.
...
...
pkg/cloudprovider/providers/azure/azure_vmss_cache.go
View file @
67069cc1
...
@@ -199,6 +199,24 @@ func (ss *scaleSet) newVmssVMCache() (*timedCache, error) {
...
@@ -199,6 +199,24 @@ func (ss *scaleSet) newVmssVMCache() (*timedCache, error) {
return
nil
,
nil
return
nil
,
nil
}
}
// Get instanceView for vmssVM.
if
result
.
InstanceView
==
nil
{
viewCtx
,
viewCancel
:=
getContextWithCancel
()
defer
viewCancel
()
view
,
err
:=
ss
.
VirtualMachineScaleSetVMsClient
.
GetInstanceView
(
viewCtx
,
resourceGroup
,
ssName
,
instanceID
)
// It is possible that the vmssVM gets removed just before this call. So check whether the VM exist again.
exists
,
message
,
realErr
=
checkResourceExistsFromError
(
err
)
if
realErr
!=
nil
{
return
nil
,
realErr
}
if
!
exists
{
glog
.
V
(
2
)
.
Infof
(
"Virtual machine scale set VM %q not found with message: %q"
,
key
,
message
)
return
nil
,
nil
}
result
.
InstanceView
=
&
view
}
return
&
result
,
nil
return
&
result
,
nil
}
}
...
...
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