Skip to content

Commit

Permalink
Merge pull request #969 from spencerhance/fix-ilb-e2e-test-vip-bug
Browse files Browse the repository at this point in the history
RegionalGCLBForVIP() Fix
  • Loading branch information
k8s-ci-robot committed Dec 20, 2019
2 parents 5ac41e7 + 01a1808 commit 1d46157
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
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

0 comments on commit 1d46157

Please sign in to comment.