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
f01c1401
Unverified
Commit
f01c1401
authored
Apr 28, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
Apr 28, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #77179 from feiskyer/vmss-reus
Reuse vmssIPConfigurationRE for getting the NIC's resource group
parents
2dc3509b
1a6c2835
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
13 deletions
+49
-13
azure_vmss.go
...ing/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go
+11
-13
azure_vmss_test.go
...rc/k8s.io/legacy-cloud-providers/azure/azure_vmss_test.go
+38
-0
No files found.
staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss.go
View file @
f01c1401
...
@@ -39,11 +39,10 @@ var (
...
@@ -39,11 +39,10 @@ var (
// ErrorNotVmssInstance indicates an instance is not belongint to any vmss.
// ErrorNotVmssInstance indicates an instance is not belongint to any vmss.
ErrorNotVmssInstance
=
errors
.
New
(
"not a vmss instance"
)
ErrorNotVmssInstance
=
errors
.
New
(
"not a vmss instance"
)
scaleSetNameRE
=
regexp
.
MustCompile
(
`.*/subscriptions/(?:.*)/Microsoft.Compute/virtualMachineScaleSets/(.+)/virtualMachines(?:.*)`
)
scaleSetNameRE
=
regexp
.
MustCompile
(
`.*/subscriptions/(?:.*)/Microsoft.Compute/virtualMachineScaleSets/(.+)/virtualMachines(?:.*)`
)
resourceGroupRE
=
regexp
.
MustCompile
(
`.*/subscriptions/(?:.*)/resourceGroups/(.+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?:.*)/virtualMachines(?:.*)`
)
resourceGroupRE
=
regexp
.
MustCompile
(
`.*/subscriptions/(?:.*)/resourceGroups/(.+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?:.*)/virtualMachines(?:.*)`
)
vmssNicResourceGroupRE
=
regexp
.
MustCompile
(
`.*/subscriptions/(?:.*)/resourceGroups/(.+)/providers/Microsoft.Compute/virtualMachineScaleSets/(?:.*)/virtualMachines/(?:.*)/networkInterfaces/(?:.*)`
)
vmssMachineIDTemplate
=
"/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%s"
vmssMachineIDTemplate
=
"/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%s"
vmssIPConfigurationRE
=
regexp
.
MustCompile
(
`.*/subscriptions/(?:.*)/resourceGroups/(.+)/providers/Microsoft.Compute/virtualMachineScaleSets/(.+)/virtualMachines/(.+)/networkInterfaces(?:.*)`
)
vmssIPConfigurationRE
=
regexp
.
MustCompile
(
`.*/subscriptions/(?:.*)/resourceGroups/(.+)/providers/Microsoft.Compute/virtualMachineScaleSets/(.+)/virtualMachines/(.+)/networkInterfaces(?:.*)`
)
)
)
// scaleSet implements VMSet interface for Azure scale set.
// scaleSet implements VMSet interface for Azure scale set.
...
@@ -515,8 +514,8 @@ func (ss *scaleSet) GetVMSetNames(service *v1.Service, nodes []*v1.Node) (vmSetN
...
@@ -515,8 +514,8 @@ func (ss *scaleSet) GetVMSetNames(service *v1.Service, nodes []*v1.Node) (vmSetN
// extractResourceGroupByVMSSNicID extracts the resource group name by vmss nicID.
// extractResourceGroupByVMSSNicID extracts the resource group name by vmss nicID.
func
extractResourceGroupByVMSSNicID
(
nicID
string
)
(
string
,
error
)
{
func
extractResourceGroupByVMSSNicID
(
nicID
string
)
(
string
,
error
)
{
matches
:=
vmss
NicResourceGroup
RE
.
FindStringSubmatch
(
nicID
)
matches
:=
vmss
IPConfiguration
RE
.
FindStringSubmatch
(
nicID
)
if
len
(
matches
)
!=
2
{
if
len
(
matches
)
!=
4
{
return
""
,
fmt
.
Errorf
(
"error of extracting resourceGroup from nicID %q"
,
nicID
)
return
""
,
fmt
.
Errorf
(
"error of extracting resourceGroup from nicID %q"
,
nicID
)
}
}
...
@@ -579,8 +578,8 @@ func (ss *scaleSet) GetPrimaryInterface(nodeName string) (network.Interface, err
...
@@ -579,8 +578,8 @@ func (ss *scaleSet) GetPrimaryInterface(nodeName string) (network.Interface, err
return
nic
,
nil
return
nic
,
nil
}
}
// getPrimary
n
etworkInterfaceConfiguration gets primary network interface configuration for scale set virtual machine.
// getPrimary
N
etworkInterfaceConfiguration gets primary network interface configuration for scale set virtual machine.
func
(
ss
*
scaleSet
)
getPrimary
n
etworkInterfaceConfiguration
(
networkConfigurations
[]
compute
.
VirtualMachineScaleSetNetworkConfiguration
,
nodeName
string
)
(
*
compute
.
VirtualMachineScaleSetNetworkConfiguration
,
error
)
{
func
(
ss
*
scaleSet
)
getPrimary
N
etworkInterfaceConfiguration
(
networkConfigurations
[]
compute
.
VirtualMachineScaleSetNetworkConfiguration
,
nodeName
string
)
(
*
compute
.
VirtualMachineScaleSetNetworkConfiguration
,
error
)
{
if
len
(
networkConfigurations
)
==
1
{
if
len
(
networkConfigurations
)
==
1
{
return
&
networkConfigurations
[
0
],
nil
return
&
networkConfigurations
[
0
],
nil
}
}
...
@@ -622,8 +621,7 @@ func (ss *scaleSet) EnsureHostInPool(service *v1.Service, nodeName types.NodeNam
...
@@ -622,8 +621,7 @@ func (ss *scaleSet) EnsureHostInPool(service *v1.Service, nodeName types.NodeNam
}
}
// Check scale set name:
// Check scale set name:
// - For basic SKU load balancer, errNotInVMSet should be returned if the node's
// - For basic SKU load balancer, return nil if the node's scale set is mismatched with vmSetName.
// scale set is mismatched with vmSetName.
// - For standard SKU load balancer, backend could belong to multiple VMSS, so we
// - For standard SKU load balancer, backend could belong to multiple VMSS, so we
// don't check vmSet for it.
// don't check vmSet for it.
if
vmSetName
!=
""
&&
!
ss
.
useStandardLoadBalancer
()
&&
!
strings
.
EqualFold
(
vmSetName
,
ssName
)
{
if
vmSetName
!=
""
&&
!
ss
.
useStandardLoadBalancer
()
&&
!
strings
.
EqualFold
(
vmSetName
,
ssName
)
{
...
@@ -633,7 +631,7 @@ func (ss *scaleSet) EnsureHostInPool(service *v1.Service, nodeName types.NodeNam
...
@@ -633,7 +631,7 @@ func (ss *scaleSet) EnsureHostInPool(service *v1.Service, nodeName types.NodeNam
// Find primary network interface configuration.
// Find primary network interface configuration.
networkInterfaceConfigurations
:=
*
vm
.
NetworkProfileConfiguration
.
NetworkInterfaceConfigurations
networkInterfaceConfigurations
:=
*
vm
.
NetworkProfileConfiguration
.
NetworkInterfaceConfigurations
primaryNetworkInterfaceConfiguration
,
err
:=
ss
.
getPrimary
n
etworkInterfaceConfiguration
(
networkInterfaceConfigurations
,
vmName
)
primaryNetworkInterfaceConfiguration
,
err
:=
ss
.
getPrimary
N
etworkInterfaceConfiguration
(
networkInterfaceConfigurations
,
vmName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -784,7 +782,7 @@ func (ss *scaleSet) ensureBackendPoolDeletedFromNode(service *v1.Service, nodeNa
...
@@ -784,7 +782,7 @@ func (ss *scaleSet) ensureBackendPoolDeletedFromNode(service *v1.Service, nodeNa
// Find primary network interface configuration.
// Find primary network interface configuration.
networkInterfaceConfigurations
:=
*
vm
.
NetworkProfileConfiguration
.
NetworkInterfaceConfigurations
networkInterfaceConfigurations
:=
*
vm
.
NetworkProfileConfiguration
.
NetworkInterfaceConfigurations
primaryNetworkInterfaceConfiguration
,
err
:=
ss
.
getPrimary
n
etworkInterfaceConfiguration
(
networkInterfaceConfigurations
,
nodeName
)
primaryNetworkInterfaceConfiguration
,
err
:=
ss
.
getPrimary
N
etworkInterfaceConfiguration
(
networkInterfaceConfigurations
,
nodeName
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
staging/src/k8s.io/legacy-cloud-providers/azure/azure_vmss_test.go
View file @
f01c1401
...
@@ -374,3 +374,41 @@ func TestGetNodeNameByIPConfigurationID(t *testing.T) {
...
@@ -374,3 +374,41 @@ func TestGetNodeNameByIPConfigurationID(t *testing.T) {
assert
.
Equal
(
t
,
test
.
expected
,
nodeName
,
test
.
description
)
assert
.
Equal
(
t
,
test
.
expected
,
nodeName
,
test
.
description
)
}
}
}
}
func
TestExtractResourceGroupByVMSSNicID
(
t
*
testing
.
T
)
{
vmssNicIDTemplate
:=
"/subscriptions/script/resourceGroups/%s/providers/Microsoft.Compute/virtualMachineScaleSets/%s/virtualMachines/%s/networkInterfaces/nic-0"
testCases
:=
[]
struct
{
description
string
vmssNicID
string
expected
string
expectError
bool
}{
{
description
:
"extractResourceGroupByVMSSNicID should get resource group name for vmss nic ID"
,
vmssNicID
:
fmt
.
Sprintf
(
vmssNicIDTemplate
,
"rg1"
,
"vmss1"
,
"0"
),
expected
:
"rg1"
,
},
{
description
:
"extractResourceGroupByVMSSNicID should return error for VM nic ID"
,
vmssNicID
:
"/subscriptions/script/resourceGroups/rg2/providers/Microsoft.Network/networkInterfaces/nic-0"
,
expectError
:
true
,
},
{
description
:
"extractResourceGroupByVMSSNicID should return error for wrong vmss nic ID"
,
vmssNicID
:
"wrong-nic-id"
,
expectError
:
true
,
},
}
for
_
,
test
:=
range
testCases
{
resourceGroup
,
err
:=
extractResourceGroupByVMSSNicID
(
test
.
vmssNicID
)
if
test
.
expectError
{
assert
.
Error
(
t
,
err
,
test
.
description
)
continue
}
assert
.
NoError
(
t
,
err
,
test
.
description
)
assert
.
Equal
(
t
,
test
.
expected
,
resourceGroup
,
test
.
description
)
}
}
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