Skip to content

Commit

Permalink
Merge pull request #907 from spencerhance/cherry-pick-906-release-1-7
Browse files Browse the repository at this point in the history
Cherry Pick #906 (Fix ILB forwarding rule bug) to release-1.7
  • Loading branch information
k8s-ci-robot committed Oct 22, 2019
2 parents 58db9e4 + d2484e2 commit fddfd0f
Show file tree
Hide file tree
Showing 2 changed files with 29 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
13 changes: 12 additions & 1 deletion pkg/loadbalancers/forwarding_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ package loadbalancers

import (
"fmt"

"k8s.io/ingress-gce/pkg/composite"
"k8s.io/ingress-gce/pkg/flags"
"k8s.io/ingress-gce/pkg/loadbalancers/features"
"k8s.io/ingress-gce/pkg/utils"
"k8s.io/klog"
)
Expand Down Expand Up @@ -89,9 +92,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 fddfd0f

Please sign in to comment.