Skip to content

Commit 815086f

Browse files
authored
Merge pull request kubernetes#75282 from feiskyer/disable-outboud-snat
Allow disable outbound snat when Azure standard load balancer is used
2 parents 60d0ec5 + 84617c8 commit 815086f

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

pkg/cloudprovider/providers/azure/azure.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const (
7373
var (
7474
// Master nodes are not added to standard load balancer by default.
7575
defaultExcludeMasterFromStandardLB = true
76+
// Outbound SNAT is enabled by default.
77+
defaultDisableOutboundSNAT = false
7678
)
7779

7880
// Config holds the configuration parsed from the --cloud-config flag
@@ -145,6 +147,9 @@ type Config struct {
145147
// ExcludeMasterFromStandardLB excludes master nodes from standard load balancer.
146148
// If not set, it will be default to true.
147149
ExcludeMasterFromStandardLB *bool `json:"excludeMasterFromStandardLB" yaml:"excludeMasterFromStandardLB"`
150+
// DisableOutboundSNAT disables the outbound SNAT for public load balancer rules.
151+
// It should only be set when loadBalancerSku is standard. If not set, it will be default to false.
152+
DisableOutboundSNAT *bool `json:"disableOutboundSNAT" yaml:"disableOutboundSNAT"`
148153

149154
// Maximum allowed LoadBalancer Rule Count is the limit enforced by Azure Load balancer
150155
MaximumLoadBalancerRuleCount int `json:"maximumLoadBalancerRuleCount" yaml:"maximumLoadBalancerRuleCount"`
@@ -321,9 +326,20 @@ func NewCloud(configReader io.Reader) (cloudprovider.Interface, error) {
321326
config.CloudProviderBackoffDuration = backoffDurationDefault
322327
}
323328

324-
// Do not add master nodes to standard LB by default.
325-
if config.ExcludeMasterFromStandardLB == nil {
326-
config.ExcludeMasterFromStandardLB = &defaultExcludeMasterFromStandardLB
329+
if strings.EqualFold(config.LoadBalancerSku, loadBalancerSkuStandard) {
330+
// Do not add master nodes to standard LB by default.
331+
if config.ExcludeMasterFromStandardLB == nil {
332+
config.ExcludeMasterFromStandardLB = &defaultExcludeMasterFromStandardLB
333+
}
334+
335+
// Enable outbound SNAT by default.
336+
if config.DisableOutboundSNAT == nil {
337+
config.DisableOutboundSNAT = &defaultDisableOutboundSNAT
338+
}
339+
} else {
340+
if config.DisableOutboundSNAT != nil && *config.DisableOutboundSNAT {
341+
return nil, fmt.Errorf("disableOutboundSNAT should only set when loadBalancerSku is standard")
342+
}
327343
}
328344

329345
azClientConfig := &azClientConfig{

pkg/cloudprovider/providers/azure/azure_loadbalancer.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,10 +959,11 @@ func (az *Cloud) reconcileLoadBalancerRule(
959959
BackendAddressPool: &network.SubResource{
960960
ID: to.StringPtr(lbBackendPoolID),
961961
},
962-
LoadDistribution: loadDistribution,
963-
FrontendPort: to.Int32Ptr(port.Port),
964-
BackendPort: to.Int32Ptr(port.Port),
965-
EnableFloatingIP: to.BoolPtr(true),
962+
LoadDistribution: loadDistribution,
963+
FrontendPort: to.Int32Ptr(port.Port),
964+
BackendPort: to.Int32Ptr(port.Port),
965+
EnableFloatingIP: to.BoolPtr(true),
966+
DisableOutboundSnat: to.BoolPtr(az.disableLoadBalancerOutboundSNAT()),
966967
},
967968
}
968969
if protocol == v1.ProtocolTCP {

pkg/cloudprovider/providers/azure/azure_wrap.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ func (az *Cloud) excludeMasterNodesFromStandardLB() bool {
300300
return az.ExcludeMasterFromStandardLB != nil && *az.ExcludeMasterFromStandardLB
301301
}
302302

303+
func (az *Cloud) disableLoadBalancerOutboundSNAT() bool {
304+
if !az.useStandardLoadBalancer() || az.DisableOutboundSNAT == nil {
305+
return false
306+
}
307+
308+
return *az.DisableOutboundSNAT
309+
}
310+
303311
// IsNodeUnmanaged returns true if the node is not managed by Azure cloud provider.
304312
// Those nodes includes on-prem or VMs from other clouds. They will not be added to load balancer
305313
// backends. Azure routes and managed disks are also not supported for them.

0 commit comments

Comments
 (0)