Beispiel #1
0
func (s *ApiSuite) TestMiddlewareCRUD(c *C) {
	b, err := engine.NewHTTPBackend("b1", engine.HTTPBackendSettings{})
	c.Assert(err, IsNil)

	c.Assert(s.client.UpsertBackend(*b), IsNil)

	f, err := engine.NewHTTPFrontend(s.ng.GetRegistry().GetRouter(), "f1", b.Id, `Path("/")`, engine.HTTPFrontendSettings{})
	c.Assert(err, IsNil)
	fk := engine.FrontendKey{Id: f.Id}

	c.Assert(s.client.UpsertFrontend(*f, 0), IsNil)

	cl := s.makeConnLimit("c1", 10, "client.ip", 2, f)
	c.Assert(s.client.UpsertMiddleware(fk, cl, 0), IsNil)

	ms, err := s.client.GetMiddlewares(fk)
	c.Assert(err, IsNil)
	c.Assert(ms[0], DeepEquals, cl)

	cl = s.makeConnLimit("c1", 10, "client.ip", 3, f)
	c.Assert(s.client.UpsertMiddleware(fk, cl, 0), IsNil)

	mk := engine.MiddlewareKey{Id: cl.Id, FrontendKey: fk}
	v, err := s.client.GetMiddleware(mk)
	c.Assert(err, IsNil)
	c.Assert(v, DeepEquals, &cl)

	c.Assert(s.client.DeleteMiddleware(mk), IsNil)

	_, err = s.client.GetMiddleware(mk)
	c.Assert(err, FitsTypeOf, &engine.NotFoundError{})

}
Beispiel #2
0
func (v *vulcan) NewFrontend(rsc *kubernetes.Resource) (loadbalancer.Frontend, error) {
	s := engine.HTTPFrontendSettings{}
	if val, ok := rsc.GetAnnotation(loadbalancer.PassHostHeaderKey); ok {
		b, _ := strconv.ParseBool(val)
		s.PassHostHeader = b
	}
	if val, ok := rsc.GetAnnotation(loadbalancer.TrustForwardHeadersKey); ok {
		b, _ := strconv.ParseBool(val)
		s.TrustForwardHeader = b
	}
	if val, ok := rsc.GetAnnotation(loadbalancer.FailoverExpressionKey); ok {
		s.FailoverPredicate = val
	}
	if val, ok := rsc.GetAnnotation(loadbalancer.FrontendSettingsKey); ok {
		if er := json.Unmarshal([]byte(val), &s); er != nil {
			logger.Warnf("Failed to parse settings for frontend %q: %v", rsc.ID, er)
		}
	}

	f, er := engine.NewHTTPFrontend(vroute.NewMux(), rsc.ID(), rsc.ID(), NewRoute(rsc.Route).String(), s)
	if er != nil {
		return nil, er
	}
	return newFrontend(f), nil
}
Beispiel #3
0
func (s *ApiSuite) TestFrontendCRUD(c *C) {
	b, err := engine.NewHTTPBackend("b1", engine.HTTPBackendSettings{})
	c.Assert(err, IsNil)

	c.Assert(s.client.UpsertBackend(*b), IsNil)

	f, err := engine.NewHTTPFrontend(s.ng.GetRegistry().GetRouter(), "f1", b.Id, `Path("/")`, engine.HTTPFrontendSettings{})
	c.Assert(err, IsNil)
	fk := engine.FrontendKey{Id: f.Id}

	c.Assert(s.client.UpsertFrontend(*f, 0), IsNil)

	fs, err := s.client.GetFrontends()
	c.Assert(err, IsNil)
	c.Assert(fs[0], DeepEquals, *f)

	out, err := s.client.GetFrontend(fk)
	c.Assert(err, IsNil)
	c.Assert(out, DeepEquals, f)

	settings := f.HTTPSettings()
	settings.Hostname = `localhost`
	f.Settings = settings
	f.Route = `Path("/v2")`

	c.Assert(s.client.UpsertFrontend(*f, 0), IsNil)

	c.Assert(s.client.DeleteFrontend(fk), IsNil)

	out, err = s.client.GetFrontend(fk)
	c.Assert(err, FitsTypeOf, &engine.NotFoundError{})
}