Skip to content

Commit

Permalink
Merge pull request #911 from spencerhance/neg-validator-region
Browse files Browse the repository at this point in the history
Plumb region to neg validator for e2e testing
  • Loading branch information
k8s-ci-robot committed Oct 23, 2019
2 parents a9a78ad + 74a0029 commit 3add0a3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
4 changes: 3 additions & 1 deletion pkg/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ func WaitForIngress(s *Sandbox, ing *v1beta1.Ingress, options *WaitForIngressOpt
if err != nil {
return true, err
}
validator, err := fuzz.NewIngressValidator(s.ValidatorEnv, ing, features.All, []fuzz.WhiteboxTest{}, nil)
attrs := fuzz.DefaultAttributes()
attrs.Region = s.f.Region
validator, err := fuzz.NewIngressValidator(s.ValidatorEnv, ing, features.All, []fuzz.WhiteboxTest{}, attrs)
if err != nil {
return true, err
}
Expand Down
20 changes: 14 additions & 6 deletions pkg/fuzz/features/neg.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func (*NegFeature) Name() string {
type negValidator struct {
fuzz.NullValidator

ing *v1beta1.Ingress
env fuzz.ValidatorEnv
ing *v1beta1.Ingress
env fuzz.ValidatorEnv
region string
}

// Name implements fuzz.FeatureValidator.
Expand All @@ -71,6 +72,7 @@ func (v *negValidator) ConfigureAttributes(env fuzz.ValidatorEnv, ing *v1beta1.I
// Capture the env for use later in CheckResponse.
v.ing = ing
v.env = env
v.region = a.Region
return nil
}

Expand All @@ -95,7 +97,7 @@ func (v *negValidator) CheckResponse(host, path string, resp *http.Response, bod
urlMapName := v.env.Namer().UrlMap(v.env.Namer().LoadBalancer(key))
if negEnabled {
if utils.IsGCEL7ILBIngress(v.ing) {
return fuzz.CheckResponseContinue, verifyNegRegionBackend(v.env, negName, negName, urlMapName)
return fuzz.CheckResponseContinue, verifyNegRegionBackend(v.env, negName, negName, urlMapName, v.region)
}
return fuzz.CheckResponseContinue, verifyNegBackend(v.env, negName, urlMapName)
} else {
Expand Down Expand Up @@ -186,10 +188,16 @@ func verifyBackend(env fuzz.ValidatorEnv, bsName string, backendKeyword string,
}

// verifyBackend verifies the backend service and check if the corresponding backend group has the keyword
func verifyNegRegionBackend(env fuzz.ValidatorEnv, bsName string, backendKeyword string, urlMapName string) error {
func verifyNegRegionBackend(env fuzz.ValidatorEnv, bsName, backendKeyword, urlMapName, region string) error {
klog.V(3).Info("Verifying NEG Regional Backend")

// Region can't be empty
if region == "" {
return fmt.Errorf("want region, got empty string")
}

ctx := context.Background()
beService, err := env.Cloud().AlphaRegionBackendServices().Get(ctx, &meta.Key{Name: bsName, Region: "us-central1"})
beService, err := env.Cloud().BetaRegionBackendServices().Get(ctx, &meta.Key{Name: bsName, Region: region})
if err != nil {
return err
}
Expand All @@ -205,7 +213,7 @@ func verifyNegRegionBackend(env fuzz.ValidatorEnv, bsName string, backendKeyword
}

// Examine if ingress url map is targeting the backend service
urlMap, err := env.Cloud().AlphaRegionUrlMaps().Get(ctx, &meta.Key{Name: urlMapName, Region: "us-central1"})
urlMap, err := env.Cloud().BetaRegionUrlMaps().Get(ctx, &meta.Key{Name: urlMapName, Region: region})
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/fuzz/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type IngressValidatorAttributes struct {
CheckHTTPS bool
RejectInsecureCerts bool
RequestTimeout time.Duration
Region string
// HTTPPort and HTTPSPort are used only for unit testing.
HTTPPort int
HTTPSPort int
Expand Down Expand Up @@ -154,8 +155,8 @@ type PathResult struct {
Err error
}

// defaultAttributes are the base attributes for validation.
func defaultAttributes() *IngressValidatorAttributes {
// DefaultAttributes are the base attributes for validation.
func DefaultAttributes() *IngressValidatorAttributes {
return &IngressValidatorAttributes{
CheckHTTP: true,
CheckHTTPS: false,
Expand All @@ -175,7 +176,7 @@ func NewIngressValidator(env ValidatorEnv, ing *v1beta1.Ingress, features []Feat
}

if attribs == nil {
attribs = defaultAttributes()
attribs = DefaultAttributes()
}
attribs.baseAttributes(ing)
if err := attribs.applyFeatures(env, ing, fvs); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/fuzz/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func TestValidatorCheck(t *testing.T) {
ms.serve()
}

attribs := defaultAttributes()
attribs := DefaultAttributes()
attribs.HTTPPort = ms.l.Addr().(*net.TCPAddr).Port
attribs.HTTPSPort = ms.ls.Addr().(*net.TCPAddr).Port
validator, err := NewIngressValidator(&MockValidatorEnv{}, tc.ing, []Feature{}, []WhiteboxTest{}, attribs)
Expand Down Expand Up @@ -380,7 +380,7 @@ func TestValidatorCheckFeature(t *testing.T) {
}
ms.serve()

attribs := defaultAttributes()
attribs := DefaultAttributes()
attribs.HTTPPort = ms.l.Addr().(*net.TCPAddr).Port
attribs.HTTPSPort = ms.ls.Addr().(*net.TCPAddr).Port

Expand Down Expand Up @@ -412,13 +412,13 @@ func TestPortStr(t *testing.T) {
{
desc: "http, default port",
scheme: "http",
a: *defaultAttributes(),
a: *DefaultAttributes(),
want: "",
},
{
desc: "https, default port",
scheme: "https",
a: *defaultAttributes(),
a: *DefaultAttributes(),
want: "",
},
{
Expand Down

0 comments on commit 3add0a3

Please sign in to comment.