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

RegionalGCLBForVIP() Fix #969

Merged
merged 2 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions cmd/e2e-test/ilb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestILB(t *testing.T) {
t.Fatalf("got %v, want RFC1918 address, ing: %v", vip, ing)
}

params := &fuzz.GCLBForVIPParams{VIP: vip, Validators: fuzz.FeatureValidators(features.All), Region: Framework.Region}
params := &fuzz.GCLBForVIPParams{VIP: vip, Validators: fuzz.FeatureValidators(features.All), Region: Framework.Region, Network: Framework.Network}
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, params)
if err != nil {
t.Fatalf("Error getting GCP resources for LB with IP = %q: %v", vip, err)
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestILBHttps(t *testing.T) {
t.Fatalf("got %v, want RFC1918 address, ing: %v", vip, ing)
}

params := &fuzz.GCLBForVIPParams{VIP: vip, Region: Framework.Region, Validators: fuzz.FeatureValidators(features.All)}
params := &fuzz.GCLBForVIPParams{VIP: vip, Region: Framework.Region, Network: Framework.Network, Validators: fuzz.FeatureValidators(features.All)}
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, params)
if err != nil {
t.Fatalf("Error getting GCP resources for LB with IP = %q: %v", vip, err)
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestILBUpdate(t *testing.T) {
t.Fatalf("got %v, want RFC1918 address, ing: %v", vip, ing)
}

params := &fuzz.GCLBForVIPParams{VIP: vip, Region: Framework.Region, Validators: fuzz.FeatureValidators(features.All)}
params := &fuzz.GCLBForVIPParams{VIP: vip, Region: Framework.Region, Network: Framework.Network, Validators: fuzz.FeatureValidators(features.All)}
gclb, err := fuzz.GCLBForVIP(context.Background(), Framework.Cloud, params)
if err != nil {
t.Fatalf("Error getting GCP resources for LB with IP = %q: %v", vip, err)
Expand Down Expand Up @@ -604,7 +604,7 @@ func TestILBShared(t *testing.T) {
t.Fatalf("got %v, want RFC1918 address, ing: %v", vip, ing)
}

params := &fuzz.GCLBForVIPParams{VIP: vip, Region: Framework.Region, Validators: fuzz.FeatureValidators(features.All)}
params := &fuzz.GCLBForVIPParams{VIP: vip, Region: Framework.Region, Network: Framework.Network, Validators: fuzz.FeatureValidators(features.All)}
gclb, err = fuzz.GCLBForVIP(context.Background(), Framework.Cloud, params)
if err != nil {
t.Fatalf("Error getting GCP resources for LB with IP = %q: %v", vip, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/e2e-test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ for ATTEMPT in $(seq 60); do
sleep 1
done

NETWORK = NETWORK_INFO | sed 's+projects/.*/networks/++'
NETWORK=$(echo ${NETWORK_INFO} | sed 's+projects/.*/networks/++')

if [[ -z "${NETWORK}" ]]; then
echo "Error: could not parse network from network info"
Expand Down
15 changes: 7 additions & 8 deletions pkg/fuzz/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ func hasBetaResource(resourceType string, validators []FeatureValidator) bool {
type GCLBForVIPParams struct {
VIP string
Region string
Network string
Validators []FeatureValidator
}

Expand All @@ -395,9 +396,8 @@ func GCLBForVIP(ctx context.Context, c cloud.Cloud, params *GCLBForVIPParams) (*
gclb := NewGCLB(params.VIP)

if params.Region != "" {
if err := RegionalGCLBForVIP(ctx, c, gclb, params); err != nil {
return nil, err
}
err := RegionalGCLBForVIP(ctx, c, gclb, params)
return gclb, err
}

allGFRs, err := c.GlobalForwardingRules().List(ctx, filter.None)
Expand Down Expand Up @@ -628,22 +628,21 @@ func GCLBForVIP(ctx context.Context, c cloud.Cloud, params *GCLBForVIPParams) (*

// GCLBForVIP retrieves all of the resources associated with the GCLB for a given VIP.
func RegionalGCLBForVIP(ctx context.Context, c cloud.Cloud, gclb *GCLB, params *GCLBForVIPParams) error {

allRFRs, err := c.ForwardingRules().List(ctx, params.Region, filter.None)
if err != nil {
klog.Warningf("Error listing forwarding rules: %v", err)
return err
}

var rfrs []*compute.ForwardingRule
for _, gfr := range allRFRs {
if gfr.IPAddress == params.VIP {
rfrs = append(rfrs, gfr)
for _, rfr := range allRFRs {
if rfr.IPAddress == params.VIP && rfr.Network == params.Network {
rfrs = append(rfrs, rfr)
}
}

if len(rfrs) == 0 {
klog.Warningf("No params.Regional forwarding rules found, can't get all GCLB resources")
klog.Warningf("No regional forwarding rules found, can't get all GCLB resources")
return nil
}

Expand Down