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
094dbded
Commit
094dbded
authored
Mar 30, 2018
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support of Azure standard load balancer and public IP
parent
30a8f7d1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
12 deletions
+85
-12
azure.go
pkg/cloudprovider/providers/azure/azure.go
+19
-0
azure_loadbalancer.go
pkg/cloudprovider/providers/azure/azure_loadbalancer.go
+20
-3
azure_standard.go
pkg/cloudprovider/providers/azure/azure_standard.go
+35
-7
azure_vmsets.go
pkg/cloudprovider/providers/azure/azure_vmsets.go
+1
-1
azure_vmss.go
pkg/cloudprovider/providers/azure/azure_vmss.go
+1
-1
azure_wrap.go
pkg/cloudprovider/providers/azure/azure_wrap.go
+9
-0
No files found.
pkg/cloudprovider/providers/azure/azure.go
View file @
094dbded
...
...
@@ -49,6 +49,14 @@ const (
vmTypeVMSS
=
"vmss"
vmTypeStandard
=
"standard"
loadBalancerSkuBasic
=
"basic"
loadBalancerSkuStandard
=
"standard"
)
var
(
// Master nodes are not added to standard load balancer by default.
defaultExcludeMasterFromStandardLB
=
true
)
// Config holds the configuration parsed from the --cloud-config flag
...
...
@@ -109,6 +117,13 @@ type Config struct {
// Use instance metadata service where possible
UseInstanceMetadata
bool
`json:"useInstanceMetadata" yaml:"useInstanceMetadata"`
// Sku of Load Balancer and Public IP. Candidate values are: basic and standard.
// If not set, it will be default to basic.
LoadBalancerSku
string
`json:"loadBalancerSku" yaml:"loadBalancerSku"`
// ExcludeMasterFromStandardLB excludes master nodes from standard load balancer.
// If not set, it will be default to true.
ExcludeMasterFromStandardLB
*
bool
`json:"excludeMasterFromStandardLB" yaml:"excludeMasterFromStandardLB"`
// Maximum allowed LoadBalancer Rule Count is the limit enforced by Azure Load balancer
MaximumLoadBalancerRuleCount
int
`json:"maximumLoadBalancerRuleCount" yaml:"maximumLoadBalancerRuleCount"`
}
...
...
@@ -208,7 +223,11 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
glog
.
V
(
2
)
.
Infof
(
"Azure cloudprovider (write ops) using rate limit config: QPS=%g, bucket=%d"
,
config
.
CloudProviderRateLimitQPSWrite
,
config
.
CloudProviderRateLimitBucketWrite
)
}
// Do not add master nodes to standard LB by default.
if
config
.
ExcludeMasterFromStandardLB
==
nil
{
config
.
ExcludeMasterFromStandardLB
=
&
defaultExcludeMasterFromStandardLB
}
azClientConfig
:=
&
azClientConfig
{
...
...
pkg/cloudprovider/providers/azure/azure_loadbalancer.go
View file @
094dbded
...
...
@@ -219,8 +219,14 @@ func (az *Cloud) getServiceLoadBalancer(service *v1.Service, clusterName string,
}
}
// service does not have a load balancer, select one
if
wantLb
{
hasMode
,
_
,
_
:=
getServiceLoadBalancerMode
(
service
)
if
az
.
useStandardLoadBalancer
()
&&
hasMode
{
return
nil
,
nil
,
false
,
fmt
.
Errorf
(
"standard load balancer doesn't work with annotation %q"
,
ServiceAnnotationLoadBalancerMode
)
}
// service does not have a basic load balancer, select one.
// Standard load balancer doesn't need this because all backends nodes should be added to same LB.
if
wantLb
&&
!
az
.
useStandardLoadBalancer
()
{
// select new load balancer for service
selectedLB
,
exists
,
err
:=
az
.
selectLoadBalancer
(
clusterName
,
service
,
&
existingLBs
,
nodes
)
if
err
!=
nil
{
...
...
@@ -237,6 +243,11 @@ func (az *Cloud) getServiceLoadBalancer(service *v1.Service, clusterName string,
Location
:
&
az
.
Location
,
LoadBalancerPropertiesFormat
:
&
network
.
LoadBalancerPropertiesFormat
{},
}
if
az
.
useStandardLoadBalancer
()
{
defaultLB
.
Sku
=
&
network
.
LoadBalancerSku
{
Name
:
network
.
LoadBalancerSkuNameStandard
,
}
}
}
return
defaultLB
,
nil
,
false
,
nil
...
...
@@ -427,6 +438,12 @@ func (az *Cloud) ensurePublicIPExists(service *v1.Service, pipName string, domai
}
}
pip
.
Tags
=
&
map
[
string
]
*
string
{
"service"
:
&
serviceName
}
if
az
.
useStandardLoadBalancer
()
{
pip
.
Sku
=
&
network
.
PublicIPAddressSku
{
Name
:
network
.
PublicIPAddressSkuNameStandard
,
}
}
glog
.
V
(
3
)
.
Infof
(
"ensure(%s): pip(%s) - creating"
,
serviceName
,
*
pip
.
Name
)
glog
.
V
(
10
)
.
Infof
(
"CreateOrUpdatePIPWithRetry(%s, %q): start"
,
pipResourceGroup
,
*
pip
.
Name
)
err
=
az
.
CreateOrUpdatePIPWithRetry
(
pipResourceGroup
,
pip
)
...
...
@@ -804,7 +821,7 @@ func (az *Cloud) reconcileLoadBalancer(clusterName string, service *v1.Service,
if
wantLb
&&
nodes
!=
nil
{
// Add the machines to the backend pool if they're not already
vmSetName
:=
az
.
mapLoadBalancerNameToVMSet
(
lbName
,
clusterName
)
err
:=
az
.
vmSet
.
EnsureHostsInPool
(
serviceName
,
nodes
,
lbBackendPoolID
,
vmSetName
)
err
:=
az
.
vmSet
.
EnsureHostsInPool
(
serviceName
,
nodes
,
lbBackendPoolID
,
vmSetName
,
isInternal
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
pkg/cloudprovider/providers/azure/azure_standard.go
View file @
094dbded
...
...
@@ -59,6 +59,7 @@ const (
var
errNotInVMSet
=
errors
.
New
(
"vm is not in the vmset"
)
var
providerIDRE
=
regexp
.
MustCompile
(
`^`
+
CloudProviderName
+
`://(?:.*)/Microsoft.Compute/virtualMachines/(.+)$`
)
var
backendPoolIDRE
=
regexp
.
MustCompile
(
`^/subscriptions/(?:.*)/resourceGroups/(?:.*)/providers/Microsoft.Network/loadBalancers/(.+)/backendAddressPools/(?:.*)`
)
// getStandardMachineID returns the full identifier of a virtual machine.
func
(
az
*
Cloud
)
getStandardMachineID
(
machineName
string
)
string
{
...
...
@@ -109,6 +110,12 @@ func (az *Cloud) getLoadBalancerProbeID(lbName, lbRuleName string) string {
}
func
(
az
*
Cloud
)
mapLoadBalancerNameToVMSet
(
lbName
string
,
clusterName
string
)
(
vmSetName
string
)
{
// Backends of Standard load balancer could belong to multiple VMAS or VMSS.
// Return "" to indicate so that following logic won't check this.
if
az
.
useStandardLoadBalancer
()
{
return
""
}
vmSetName
=
strings
.
TrimSuffix
(
lbName
,
InternalLoadBalancerNameSuffix
)
if
strings
.
EqualFold
(
clusterName
,
vmSetName
)
{
vmSetName
=
az
.
vmSet
.
GetPrimaryVMSetName
()
...
...
@@ -123,7 +130,7 @@ func (az *Cloud) mapLoadBalancerNameToVMSet(lbName string, clusterName string) (
// This would be the name for Azure LoadBalancer resource.
func
(
az
*
Cloud
)
getLoadBalancerName
(
clusterName
string
,
vmSetName
string
,
isInternal
bool
)
string
{
lbNamePrefix
:=
vmSetName
if
strings
.
EqualFold
(
vmSetName
,
az
.
vmSet
.
GetPrimaryVMSetName
())
{
if
strings
.
EqualFold
(
vmSetName
,
az
.
vmSet
.
GetPrimaryVMSetName
())
||
az
.
useStandardLoadBalancer
()
{
lbNamePrefix
=
clusterName
}
if
isInternal
{
...
...
@@ -592,7 +599,7 @@ func (as *availabilitySet) GetPrimaryInterface(nodeName, vmSetName string) (netw
// ensureHostInPool ensures the given VM's Primary NIC's Primary IP Configuration is
// participating in the specified LoadBalancer Backend Pool.
func
(
as
*
availabilitySet
)
ensureHostInPool
(
serviceName
string
,
nodeName
types
.
NodeName
,
backendPoolID
string
,
vmSetName
string
)
error
{
func
(
as
*
availabilitySet
)
ensureHostInPool
(
serviceName
string
,
nodeName
types
.
NodeName
,
backendPoolID
string
,
vmSetName
string
,
isInternal
bool
)
error
{
vmName
:=
mapNodeNameToVMName
(
nodeName
)
nic
,
err
:=
as
.
GetPrimaryInterface
(
vmName
,
vmSetName
)
if
err
!=
nil
{
...
...
@@ -623,6 +630,22 @@ func (as *availabilitySet) ensureHostInPool(serviceName string, nodeName types.N
}
}
if
!
foundPool
{
if
as
.
useStandardLoadBalancer
()
&&
len
(
newBackendPools
)
>
0
{
// Although standard load balancer supports backends from multiple availability
// 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
// about this.
backendPool
:=
*
newBackendPools
[
0
]
.
ID
matches
:=
backendPoolIDRE
.
FindStringSubmatch
(
backendPool
)
if
len
(
matches
)
==
2
{
lbName
:=
matches
[
1
]
if
strings
.
HasSuffix
(
lbName
,
InternalLoadBalancerNameSuffix
)
==
isInternal
{
glog
.
V
(
4
)
.
Infof
(
"Node %q has already been added to LB %q, omit adding it to a new one"
,
nodeName
,
lbName
)
return
nil
}
}
}
newBackendPools
=
append
(
newBackendPools
,
network
.
BackendAddressPool
{
ID
:
to
.
StringPtr
(
backendPoolID
),
...
...
@@ -653,18 +676,23 @@ func (as *availabilitySet) ensureHostInPool(serviceName string, nodeName types.N
// EnsureHostsInPool ensures the given Node's primary IP configurations are
// participating in the specified LoadBalancer Backend Pool.
func
(
as
*
availabilitySet
)
EnsureHostsInPool
(
serviceName
string
,
nodes
[]
*
v1
.
Node
,
backendPoolID
string
,
vmSetName
string
)
error
{
hostUpdates
:=
make
([]
func
()
error
,
len
(
nodes
))
for
i
,
node
:=
range
nodes
{
func
(
as
*
availabilitySet
)
EnsureHostsInPool
(
serviceName
string
,
nodes
[]
*
v1
.
Node
,
backendPoolID
string
,
vmSetName
string
,
isInternal
bool
)
error
{
hostUpdates
:=
make
([]
func
()
error
,
0
,
len
(
nodes
))
for
_
,
node
:=
range
nodes
{
localNodeName
:=
node
.
Name
if
as
.
useStandardLoadBalancer
()
&&
as
.
excludeMasterNodesFromStandardLB
()
&&
isMasterNode
(
node
)
{
glog
.
V
(
4
)
.
Infof
(
"Excluding master node %q from load balancer backendpool %q"
,
localNodeName
,
backendPoolID
)
continue
}
f
:=
func
()
error
{
err
:=
as
.
ensureHostInPool
(
serviceName
,
types
.
NodeName
(
localNodeName
),
backendPoolID
,
vmSetName
)
err
:=
as
.
ensureHostInPool
(
serviceName
,
types
.
NodeName
(
localNodeName
),
backendPoolID
,
vmSetName
,
isInternal
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"ensure(%s): backendPoolID(%s) - failed to ensure host in pool: %q"
,
serviceName
,
backendPoolID
,
err
)
}
return
nil
}
hostUpdates
[
i
]
=
f
hostUpdates
=
append
(
hostUpdates
,
f
)
}
errs
:=
utilerrors
.
AggregateGoroutines
(
hostUpdates
...
)
...
...
pkg/cloudprovider/providers/azure/azure_vmsets.go
View file @
094dbded
...
...
@@ -54,7 +54,7 @@ type VMSet interface {
GetVMSetNames
(
service
*
v1
.
Service
,
nodes
[]
*
v1
.
Node
)
(
availabilitySetNames
*
[]
string
,
err
error
)
// EnsureHostsInPool ensures the given Node's primary IP configurations are
// participating in the specified LoadBalancer Backend Pool.
EnsureHostsInPool
(
serviceName
string
,
nodes
[]
*
v1
.
Node
,
backendPoolID
string
,
vmSetName
string
)
error
EnsureHostsInPool
(
serviceName
string
,
nodes
[]
*
v1
.
Node
,
backendPoolID
string
,
vmSetName
string
,
isInternal
bool
)
error
// EnsureBackendPoolDeleted ensures the loadBalancer backendAddressPools deleted from the specified vmSet.
EnsureBackendPoolDeleted
(
poolID
,
vmSetName
string
)
error
...
...
pkg/cloudprovider/providers/azure/azure_vmss.go
View file @
094dbded
...
...
@@ -547,7 +547,7 @@ func (ss *scaleSet) updateVMSSInstancesWithRetry(scaleSetName string, vmInstance
// EnsureHostsInPool ensures the given Node's primary IP configurations are
// participating in the specified LoadBalancer Backend Pool.
func
(
ss
*
scaleSet
)
EnsureHostsInPool
(
serviceName
string
,
nodes
[]
*
v1
.
Node
,
backendPoolID
string
,
vmSetName
string
)
error
{
func
(
ss
*
scaleSet
)
EnsureHostsInPool
(
serviceName
string
,
nodes
[]
*
v1
.
Node
,
backendPoolID
string
,
vmSetName
string
,
isInternal
bool
)
error
{
virtualMachineScaleSet
,
exists
,
err
:=
ss
.
getScaleSetWithRetry
(
vmSetName
)
if
err
!=
nil
{
glog
.
Errorf
(
"ss.getScaleSetWithRetry(%s) for service %q failed: %v"
,
vmSetName
,
serviceName
,
err
)
...
...
pkg/cloudprovider/providers/azure/azure_wrap.go
View file @
094dbded
...
...
@@ -19,6 +19,7 @@ package azure
import
(
"fmt"
"net/http"
"strings"
"time"
"github.com/Azure/azure-sdk-for-go/arm/compute"
...
...
@@ -242,3 +243,11 @@ func (az *Cloud) newRouteTableCache() (*timedCache, error) {
return
newTimedcache
(
rtCacheTTL
,
getter
)
}
func
(
az
*
Cloud
)
useStandardLoadBalancer
()
bool
{
return
strings
.
EqualFold
(
az
.
LoadBalancerSku
,
loadBalancerSkuStandard
)
}
func
(
az
*
Cloud
)
excludeMasterNodesFromStandardLB
()
bool
{
return
az
.
ExcludeMasterFromStandardLB
!=
nil
&&
*
az
.
ExcludeMasterFromStandardLB
}
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