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
ef6f88d9
Commit
ef6f88d9
authored
Apr 17, 2019
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Azure SLB support for multiple backend pools
Azure VM and vmssVM support multiple backend pools for the same SLB, but not for different LBs.
parent
a9ab371f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
123 additions
and
16 deletions
+123
-16
azure_standard.go
pkg/cloudprovider/providers/azure/azure_standard.go
+11
-8
azure_vmss.go
pkg/cloudprovider/providers/azure/azure_vmss.go
+11
-8
azure_wrap.go
pkg/cloudprovider/providers/azure/azure_wrap.go
+26
-0
azure_wrap_test.go
pkg/cloudprovider/providers/azure/azure_wrap_test.go
+75
-0
No files found.
pkg/cloudprovider/providers/azure/azure_standard.go
View file @
ef6f88d9
...
@@ -676,17 +676,20 @@ func (as *availabilitySet) ensureHostInPool(service *v1.Service, nodeName types.
...
@@ -676,17 +676,20 @@ func (as *availabilitySet) ensureHostInPool(service *v1.Service, nodeName types.
// sets, the same network interface couldn't be added to more than one load balancer of
// sets, the same network interface couldn't be added to more than one load balancer of
// the same type. Omit those nodes (e.g. masters) so Azure ARM won't complain
// the same type. Omit those nodes (e.g. masters) so Azure ARM won't complain
// about this.
// about this.
newBackendPoolsIDs
:=
make
([]
string
,
0
,
len
(
newBackendPools
))
for
_
,
pool
:=
range
newBackendPools
{
for
_
,
pool
:=
range
newBackendPools
{
backendPool
:=
*
pool
.
ID
if
pool
.
ID
!=
nil
{
matches
:=
backendPoolIDRE
.
FindStringSubmatch
(
backendPool
)
newBackendPoolsIDs
=
append
(
newBackendPoolsIDs
,
*
pool
.
ID
)
if
len
(
matches
)
==
2
{
lbName
:=
matches
[
1
]
if
strings
.
HasSuffix
(
lbName
,
InternalLoadBalancerNameSuffix
)
==
isInternal
{
klog
.
V
(
4
)
.
Infof
(
"Node %q has already been added to LB %q, omit adding it to a new one"
,
nodeName
,
lbName
)
return
nil
}
}
}
}
}
isSameLB
,
oldLBName
,
err
:=
isBackendPoolOnSameLB
(
backendPoolID
,
newBackendPoolsIDs
)
if
err
!=
nil
{
return
err
}
if
!
isSameLB
{
klog
.
V
(
4
)
.
Infof
(
"Node %q has already been added to LB %q, omit adding it to a new one"
,
nodeName
,
oldLBName
)
return
nil
}
}
}
newBackendPools
=
append
(
newBackendPools
,
newBackendPools
=
append
(
newBackendPools
,
...
...
pkg/cloudprovider/providers/azure/azure_vmss.go
View file @
ef6f88d9
...
@@ -785,17 +785,20 @@ func (ss *scaleSet) ensureHostsInVMSetPool(service *v1.Service, backendPoolID st
...
@@ -785,17 +785,20 @@ func (ss *scaleSet) ensureHostsInVMSetPool(service *v1.Service, backendPoolID st
// the same network interface couldn't be added to more than one load balancer of
// the same network interface couldn't be added to more than one load balancer of
// the same type. Omit those nodes (e.g. masters) so Azure ARM won't complain
// the same type. Omit those nodes (e.g. masters) so Azure ARM won't complain
// about this.
// about this.
newBackendPoolsIDs
:=
make
([]
string
,
0
,
len
(
newBackendPools
))
for
_
,
pool
:=
range
newBackendPools
{
for
_
,
pool
:=
range
newBackendPools
{
backendPool
:=
*
pool
.
ID
if
pool
.
ID
!=
nil
{
matches
:=
backendPoolIDRE
.
FindStringSubmatch
(
backendPool
)
newBackendPoolsIDs
=
append
(
newBackendPoolsIDs
,
*
pool
.
ID
)
if
len
(
matches
)
==
2
{
lbName
:=
matches
[
1
]
if
strings
.
HasSuffix
(
lbName
,
InternalLoadBalancerNameSuffix
)
==
isInternal
{
klog
.
V
(
4
)
.
Infof
(
"vmss %q has already been added to LB %q, omit adding it to a new one"
,
vmSetName
,
lbName
)
return
nil
}
}
}
}
}
isSameLB
,
oldLBName
,
err
:=
isBackendPoolOnSameLB
(
backendPoolID
,
newBackendPoolsIDs
)
if
err
!=
nil
{
return
err
}
if
!
isSameLB
{
klog
.
V
(
4
)
.
Infof
(
"VMSS %q has already been added to LB %q, omit adding it to a new one"
,
vmSetName
,
oldLBName
)
return
nil
}
}
}
newBackendPools
=
append
(
newBackendPools
,
newBackendPools
=
append
(
newBackendPools
,
...
...
pkg/cloudprovider/providers/azure/azure_wrap.go
View file @
ef6f88d9
...
@@ -336,3 +336,29 @@ func convertResourceGroupNameToLower(resourceID string) (string, error) {
...
@@ -336,3 +336,29 @@ func convertResourceGroupNameToLower(resourceID string) (string, error) {
resourceGroup
:=
matches
[
1
]
resourceGroup
:=
matches
[
1
]
return
strings
.
Replace
(
resourceID
,
resourceGroup
,
strings
.
ToLower
(
resourceGroup
),
1
),
nil
return
strings
.
Replace
(
resourceID
,
resourceGroup
,
strings
.
ToLower
(
resourceGroup
),
1
),
nil
}
}
// isBackendPoolOnSameLB checks whether newBackendPoolID is on the same load balancer as existingBackendPools.
// Since both public and internal LBs are supported, lbName and lbName-internal are treated as same.
// If not same, the lbName for existingBackendPools would also be returned.
func
isBackendPoolOnSameLB
(
newBackendPoolID
string
,
existingBackendPools
[]
string
)
(
bool
,
string
,
error
)
{
matches
:=
backendPoolIDRE
.
FindStringSubmatch
(
newBackendPoolID
)
if
len
(
matches
)
!=
2
{
return
false
,
""
,
fmt
.
Errorf
(
"new backendPoolID %q is in wrong format"
,
newBackendPoolID
)
}
newLBName
:=
matches
[
1
]
newLBNameTrimmed
:=
strings
.
TrimRight
(
newLBName
,
InternalLoadBalancerNameSuffix
)
for
_
,
backendPool
:=
range
existingBackendPools
{
matches
:=
backendPoolIDRE
.
FindStringSubmatch
(
backendPool
)
if
len
(
matches
)
!=
2
{
return
false
,
""
,
fmt
.
Errorf
(
"existing backendPoolID %q is in wrong format"
,
backendPool
)
}
lbName
:=
matches
[
1
]
if
!
strings
.
EqualFold
(
strings
.
TrimRight
(
lbName
,
InternalLoadBalancerNameSuffix
),
newLBNameTrimmed
)
{
return
false
,
lbName
,
nil
}
}
return
true
,
""
,
nil
}
pkg/cloudprovider/providers/azure/azure_wrap_test.go
View file @
ef6f88d9
...
@@ -198,3 +198,78 @@ func TestConvertResourceGroupNameToLower(t *testing.T) {
...
@@ -198,3 +198,78 @@ func TestConvertResourceGroupNameToLower(t *testing.T) {
assert
.
Equal
(
t
,
test
.
expected
,
real
,
test
.
desc
)
assert
.
Equal
(
t
,
test
.
expected
,
real
,
test
.
desc
)
}
}
}
}
func
TestIsBackendPoolOnSameLB
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
backendPoolID
string
existingBackendPools
[]
string
expected
bool
expectedLBName
string
expectError
bool
}{
{
backendPoolID
:
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb1/backendAddressPools/pool1"
,
existingBackendPools
:
[]
string
{
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb1/backendAddressPools/pool2"
,
},
expected
:
true
,
expectedLBName
:
""
,
},
{
backendPoolID
:
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb1-internal/backendAddressPools/pool1"
,
existingBackendPools
:
[]
string
{
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb1/backendAddressPools/pool2"
,
},
expected
:
true
,
expectedLBName
:
""
,
},
{
backendPoolID
:
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb1/backendAddressPools/pool1"
,
existingBackendPools
:
[]
string
{
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb1-internal/backendAddressPools/pool2"
,
},
expected
:
true
,
expectedLBName
:
""
,
},
{
backendPoolID
:
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb1/backendAddressPools/pool1"
,
existingBackendPools
:
[]
string
{
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb2/backendAddressPools/pool2"
,
},
expected
:
false
,
expectedLBName
:
"lb2"
,
},
{
backendPoolID
:
"wrong-backendpool-id"
,
existingBackendPools
:
[]
string
{
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb1/backendAddressPools/pool2"
,
},
expectError
:
true
,
},
{
backendPoolID
:
"/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Network/loadBalancers/lb1/backendAddressPools/pool1"
,
existingBackendPools
:
[]
string
{
"wrong-existing-backendpool-id"
,
},
expectError
:
true
,
},
{
backendPoolID
:
"wrong-backendpool-id"
,
existingBackendPools
:
[]
string
{
"wrong-existing-backendpool-id"
,
},
expectError
:
true
,
},
}
for
_
,
test
:=
range
tests
{
isSameLB
,
lbName
,
err
:=
isBackendPoolOnSameLB
(
test
.
backendPoolID
,
test
.
existingBackendPools
)
if
test
.
expectError
{
assert
.
Error
(
t
,
err
)
continue
}
assert
.
Equal
(
t
,
test
.
expected
,
isSameLB
)
assert
.
Equal
(
t
,
test
.
expectedLBName
,
lbName
)
}
}
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