Skip to content

Commit

Permalink
Merge pull request #906 from spencerhance/ilb-forwarding-rule-custom-…
Browse files Browse the repository at this point in the history
…mode-network

Fix ILB forwarding rule bug
  • Loading branch information
k8s-ci-robot committed Oct 22, 2019
2 parents 107276e + 1d6d9c5 commit 6de0890
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 17 additions & 0 deletions pkg/loadbalancers/features/l7ilb.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ func isSameNetwork(l, r string) (bool, error) {
return lID.Equal(rID), nil
}

// IsCustomModeNetwork is a helper for determining if a network is a custom mode network
// (as opposed to a auto mode network). This is used for l7-ilb since custom mode networks
// require an additional field on the forwarding rule
func IsCustomModeNetwork(c *gce.Cloud, networkURL string) (bool, error) {
netID, err := cloud.ParseResourceURL(networkURL)
if err != nil {
return false, err
}

network, err := c.Compute().Networks().Get(context.Background(), netID.Key)
if err != nil {
return false, err
}

return !network.AutoCreateSubnetworks, nil
}

// L7ILBVersion is a helper to get the version of L7-ILB
func L7ILBVersions() *ResourceVersions {
return versionsFromFeatures([]string{FeatureL7ILB})
Expand Down
12 changes: 11 additions & 1 deletion pkg/loadbalancers/forwarding_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package loadbalancers

import (
"fmt"
"k8s.io/ingress-gce/pkg/flags"
"k8s.io/ingress-gce/pkg/loadbalancers/features"

"k8s.io/ingress-gce/pkg/composite"
"k8s.io/ingress-gce/pkg/utils"
Expand Down Expand Up @@ -91,9 +93,17 @@ func (l *L7) checkForwardingRule(name, proxyLink, ip, portRange string) (fw *com
}

// Update rule for L7-ILB
if utils.IsGCEL7ILBIngress(l.runtimeInfo.Ingress) {
if flags.F.EnableL7Ilb && utils.IsGCEL7ILBIngress(l.runtimeInfo.Ingress) {
rule.LoadBalancingScheme = "INTERNAL_MANAGED"

// Custom mode networks require adding the cluster subnetwork
if isCustomMode, err := features.IsCustomModeNetwork(l.cloud, l.cloud.NetworkURL()); err != nil {
return nil, err
} else if isCustomMode {
rule.Subnetwork = l.cloud.SubnetworkURL()
}
}

if err = composite.CreateForwardingRule(l.cloud, key, rule); err != nil {
return nil, err
}
Expand Down

0 comments on commit 6de0890

Please sign in to comment.