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
f753c916
Commit
f753c916
authored
Apr 27, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify vmset acquirement logic
parent
a54cb15d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
47 deletions
+23
-47
azure_controller_common.go
pkg/cloudprovider/providers/azure/azure_controller_common.go
+23
-47
No files found.
pkg/cloudprovider/providers/azure/azure_controller_common.go
View file @
f753c916
...
...
@@ -58,85 +58,61 @@ type controllerCommon struct {
cloud
*
Cloud
}
//
AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI, and lun
.
func
(
c
*
controllerCommon
)
AttachDisk
(
isManagedDisk
bool
,
diskName
,
diskURI
string
,
nodeName
types
.
NodeName
,
lun
int32
,
cachingMode
compute
.
CachingTypes
)
error
{
// 1. vmType is standard,
attach with availabilitySet.AttachDisk
.
//
getNodeVMSet gets the VMSet interface based on config.VMType and the real virtual machine type
.
func
(
c
*
controllerCommon
)
getNodeVMSet
(
nodeName
types
.
NodeName
)
(
VMSet
,
error
)
{
// 1. vmType is standard,
return cloud.vmSet directly
.
if
c
.
cloud
.
VMType
==
vmTypeStandard
{
return
c
.
cloud
.
vmSet
.
AttachDisk
(
isManagedDisk
,
diskName
,
diskURI
,
nodeName
,
lun
,
cachingMode
)
return
c
.
cloud
.
vmSet
,
nil
}
// 2. vmType is Virtual Machine Scale Set (vmss), convert vmSet to scaleSet.
ss
,
ok
:=
c
.
cloud
.
vmSet
.
(
*
scaleSet
)
if
!
ok
{
return
fmt
.
Errorf
(
"error of converting vmSet (%q) to scaleSet with vmType %q"
,
c
.
cloud
.
vmSet
,
c
.
cloud
.
VMType
)
return
nil
,
fmt
.
Errorf
(
"error of converting vmSet (%q) to scaleSet with vmType %q"
,
c
.
cloud
.
vmSet
,
c
.
cloud
.
VMType
)
}
// 3. If the node is managed by availability set, then
attach with availabilitySet.AttachDisk
.
// 3. If the node is managed by availability set, then
return ss.availabilitySet
.
managedByAS
,
err
:=
ss
.
isNodeManagedByAvailabilitySet
(
mapNodeNameToVMName
(
nodeName
))
if
err
!=
nil
{
return
err
return
nil
,
err
}
if
managedByAS
{
// vm is managed by availability set.
return
ss
.
availabilitySet
.
AttachDisk
(
isManagedDisk
,
diskName
,
diskURI
,
nodeName
,
lun
,
cachingMode
)
return
ss
.
availabilitySet
,
nil
}
// 4. Node is managed by vmss
, attach with scaleSet.AttachDisk.
return
ss
.
AttachDisk
(
isManagedDisk
,
diskName
,
diskURI
,
nodeName
,
lun
,
cachingMode
)
// 4. Node is managed by vmss
return
ss
,
nil
}
//
DetachDiskByName detaches a vhd from host. The vhd can be identified by diskName or diskURI
.
func
(
c
*
controllerCommon
)
DetachDiskByName
(
diskName
,
diskURI
string
,
nodeName
types
.
NodeName
)
error
{
// 1. vmType is standard, detach with availabilitySet.DetachDiskByName.
if
c
.
cloud
.
VMType
==
vmTypeStandard
{
return
c
.
cloud
.
vmSet
.
DetachDiskByName
(
diskName
,
diskURI
,
nodeName
)
//
AttachDisk attaches a vhd to vm. The vhd must exist, can be identified by diskName, diskURI, and lun
.
func
(
c
*
controllerCommon
)
AttachDisk
(
isManagedDisk
bool
,
diskName
,
diskURI
string
,
nodeName
types
.
NodeName
,
lun
int32
,
cachingMode
compute
.
CachingTypes
)
error
{
vmset
,
err
:=
c
.
getNodeVMSet
(
nodeName
)
if
err
!=
nil
{
return
err
}
// 2. vmType is Virtual Machine Scale Set (vmss), convert vmSet to scaleSet.
ss
,
ok
:=
c
.
cloud
.
vmSet
.
(
*
scaleSet
)
if
!
ok
{
return
fmt
.
Errorf
(
"error of converting vmSet (%q) to scaleSet with vmType %q"
,
c
.
cloud
.
vmSet
,
c
.
cloud
.
VMType
)
}
return
vmset
.
AttachDisk
(
isManagedDisk
,
diskName
,
diskURI
,
nodeName
,
lun
,
cachingMode
)
}
// 3. If the node is managed by availability set, then detach with availabilitySet.DetachDiskByName.
managedByAS
,
err
:=
ss
.
isNodeManagedByAvailabilitySet
(
mapNodeNameToVMName
(
nodeName
))
// DetachDiskByName detaches a vhd from host. The vhd can be identified by diskName or diskURI.
func
(
c
*
controllerCommon
)
DetachDiskByName
(
diskName
,
diskURI
string
,
nodeName
types
.
NodeName
)
error
{
vmset
,
err
:=
c
.
getNodeVMSet
(
nodeName
)
if
err
!=
nil
{
return
err
}
if
managedByAS
{
// vm is managed by availability set.
return
ss
.
availabilitySet
.
DetachDiskByName
(
diskName
,
diskURI
,
nodeName
)
}
// 4. Node is managed by vmss, detach with scaleSet.DetachDiskByName.
return
ss
.
DetachDiskByName
(
diskName
,
diskURI
,
nodeName
)
return
vmset
.
DetachDiskByName
(
diskName
,
diskURI
,
nodeName
)
}
// getNodeDataDisks invokes vmSet interfaces to get data disks for the node.
func
(
c
*
controllerCommon
)
getNodeDataDisks
(
nodeName
types
.
NodeName
)
([]
compute
.
DataDisk
,
error
)
{
// 1. vmType is standard, get data disks with availabilitySet.GetDataDisks.
if
c
.
cloud
.
VMType
==
vmTypeStandard
{
return
c
.
cloud
.
vmSet
.
GetDataDisks
(
nodeName
)
}
// 2. vmType is Virtual Machine Scale Set (vmss), convert vmSet to scaleSet.
ss
,
ok
:=
c
.
cloud
.
vmSet
.
(
*
scaleSet
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"error of converting vmSet (%q) to scaleSet with vmType %q"
,
c
.
cloud
.
vmSet
,
c
.
cloud
.
VMType
)
}
// 3. If the node is managed by availability set, then get with availabilitySet.GetDataDisks.
managedByAS
,
err
:=
ss
.
isNodeManagedByAvailabilitySet
(
mapNodeNameToVMName
(
nodeName
))
vmset
,
err
:=
c
.
getNodeVMSet
(
nodeName
)
if
err
!=
nil
{
return
nil
,
err
}
if
managedByAS
{
// vm is managed by availability set.
return
ss
.
availabilitySet
.
GetDataDisks
(
nodeName
)
}
// 4. Node is managed by vmss, detach with scaleSet.GetDataDisks.
return
ss
.
GetDataDisks
(
nodeName
)
return
vmset
.
GetDataDisks
(
nodeName
)
}
// GetDiskLun finds the lun on the host that the vhd is attached to, given a vhd's diskName and diskURI.
...
...
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