Example #1
0
func (v *vulcan) NewBackend(rsc *kubernetes.Resource) (loadbalancer.Backend, error) {
	s := engine.HTTPBackendSettings{
		Timeouts:  engine.HTTPBackendTimeouts{},
		KeepAlive: engine.HTTPBackendKeepAlive{},
	}
	if val, ok := rsc.GetAnnotation(DailTimeoutKey); ok {
		s.Timeouts.Dial = val
	}
	if val, ok := rsc.GetAnnotation(ReadTimeoutKey); ok {
		s.Timeouts.Read = val
	}
	if val, ok := rsc.GetAnnotation(MaxIdleConnsKey); ok {
		if i, er := strconv.Atoi(val); er == nil {
			s.KeepAlive.MaxIdleConnsPerHost = i
		}
	}
	if val, ok := rsc.GetAnnotation(loadbalancer.BackendSettingsKey); ok {
		if er := json.Unmarshal([]byte(val), &s); er != nil {
			logger.Warnf("Failed to parse settings for frontend %q: %v", rsc.ID, er)
		}
	}

	b, er := engine.NewHTTPBackend(rsc.ID(), s)
	if er != nil {
		return nil, er
	}
	if rsc.IsWebsocket() {
		b.Type = ws
	}
	return newBackend(b), nil
}
Example #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
}
Example #3
0
func (t *traefik) NewFrontend(rsc *kubernetes.Resource) (loadbalancer.Frontend, error) {
	f := types.Frontend{Backend: rsc.ID(), PassHostHeader: false}
	f.Routes = NewRoute(rsc.Route)
	if phh, ok := rsc.GetAnnotation(loadbalancer.PassHostHeaderKey); ok {
		if val, er := strconv.ParseBool(phh); er == nil {
			f.PassHostHeader = val
		}
	}

	return &frontend{Frontend: f, id: rsc.ID(), middlewares: make([]*middleware, 0, 1)}, nil
}
Example #4
0
func (t *traefik) NewBackend(rsc *kubernetes.Resource) (loadbalancer.Backend, error) {
	// b := new(types.Backend)
	b := &types.Backend{
		LoadBalancer:   defaultLoadBalancerMethod,
		CircuitBreaker: defaultCircuitBreaker,
	}
	b.Servers = make(map[string]types.Server)
	if lbm, ok := rsc.GetAnnotation(LoadbalancingMethodKey); ok && validLBM(lbm) {
		b.LoadBalancer = &types.LoadBalancer{Method: lbm}
	}
	if exp, ok := rsc.GetAnnotation(loadbalancer.FailoverExpressionKey); ok {
		b.CircuitBreaker = &types.CircuitBreaker{Expression: exp}
	}

	return &backend{Backend: *b, id: rsc.ID()}, nil
}