Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ILB subnet discovery to check for VPC as well #895

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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