Skip to content

Commit

Permalink
Merge pull request #895 from spencerhance/ilb-subnet-vpc-fix
Browse files Browse the repository at this point in the history
Fix ILB subnet discovery to check for VPC as well
  • Loading branch information
k8s-ci-robot authored Oct 17, 2019
2 parents 99732ed + beb8ce9 commit bdeebd6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/loadbalancers/features/l7ilb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud"

"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/filter"
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
Expand All @@ -38,14 +39,32 @@ func ILBSubnetSourceRange(cloud *gce.Cloud, region string) (string, error) {
}

for _, subnet := range subnets {
if subnet.Role == "ACTIVE" && subnet.Purpose == "INTERNAL_HTTPS_LOAD_BALANCER" {
sameNetwork, err := isSameNetwork(subnet.Network, cloud.NetworkURL())
if err != nil {
return "", fmt.Errorf("error comparing subnets: %v", err)
}
if subnet.Role == "ACTIVE" && subnet.Purpose == "INTERNAL_HTTPS_LOAD_BALANCER" && sameNetwork {
klog.V(3).Infof("Found L7-ILB Subnet %s - %s", subnet.Name, subnet.IpCidrRange)
return subnet.IpCidrRange, nil
}
}
return "", ErrSubnetNotFound
}

// isSameNetwork() is a helper for comparing networks across API versions
func isSameNetwork(l, r string) (bool, error) {
lID, err := cloud.ParseResourceURL(l)
if err != nil {
return false, err
}
rID, err := cloud.ParseResourceURL(r)
if err != nil {
return false, err
}

return lID.Equal(rID), nil
}

// L7ILBVersion is a helper to get the version of L7-ILB
func L7ILBVersions() *ResourceVersions {
return versionsFromFeatures([]string{FeatureL7ILB})
Expand Down

0 comments on commit bdeebd6

Please sign in to comment.