Beispiel #1
0
	modelerUtility "github.com/deis/router/utils/modeler"
	"k8s.io/kubernetes/pkg/api"
	"k8s.io/kubernetes/pkg/api/errors"
	client "k8s.io/kubernetes/pkg/client/unversioned"
	"k8s.io/kubernetes/pkg/labels"
)

const (
	prefix               string = "router.deis.io"
	modelerFieldTag      string = "key"
	modelerConstraintTag string = "constraint"
)

var (
	namespace        = utils.GetOpt("POD_NAMESPACE", "default")
	modeler          = modelerUtility.NewModeler(prefix, modelerFieldTag, modelerConstraintTag, true)
	servicesSelector labels.Selector
)

func init() {
	var err error
	servicesSelector, err = labels.Parse(fmt.Sprintf("%s/routable==true", prefix))
	if err != nil {
		log.Fatal(err)
	}
}

// RouterConfig is the primary type used to encapsulate all router configuration.
type RouterConfig struct {
	WorkerProcesses          string      `key:"workerProcesses" constraint:"^(auto|[1-9]\\d*)$"`
	MaxWorkerConnections     string      `key:"maxWorkerConnections" constraint:"^[1-9]\\d*$"`
package model

import (
	"reflect"
	"testing"

	modelerUtility "github.com/deis/router/utils/modeler"
)

var (
	// We'll test the declarative constraints on model attributes using this modeler instead of the
	// one defined in the non-test half of this package.  Why?  We want one that generates errors
	// instead of merely outputting warnings.  That allows us to easily assert validation failures
	// and also prevents us from clutter STDOUT with useless noise.
	testModeler = modelerUtility.NewModeler("", modelerFieldTag, modelerConstraintTag, false)
)

func TestInvalidWorkerProcesses(t *testing.T) {
	testInvalidValues(t, newTestRouterConfig, "WorkerProcesses", "workerProcesses", []string{"0", "-1", "foobar"})
}

func TestValidWorkerProcesses(t *testing.T) {
	testValidValues(t, newTestRouterConfig, "WorkerProcesses", "workerProcesses", []string{"auto", "2", "10"})
}

func TestInvalidMaxWorkerConnections(t *testing.T) {
	testInvalidValues(t, newTestRouterConfig, "MaxWorkerConnections", "maxWorkerConnections", []string{"0", "-1", "foobar"})
}

func TestValidMaxWorkerConnections(t *testing.T) {
	testValidValues(t, newTestRouterConfig, "MaxWorkerConnections", "maxWorkerConnections", []string{"1", "2", "10"})
Beispiel #3
0
	IncludeSubDomains bool `router:"includeSubDomains"`
	Preload           bool `router:"preload"`
}

func newHSTSConfig() *HSTSConfig {
	return &HSTSConfig{
		Enabled:           false,
		MaxAge:            10886400,
		IncludeSubDomains: false,
		Preload:           false,
	}
}

var (
	namespace = utils.GetOpt("POD_NAMESPACE", "default")
	modeler   = modelerUtility.NewModeler("router.deis.io", "router")
)

// Build creates a RouterConfig configuration object by querying the k8s API for
// relevant metadata concerning itself and all routable services.
func Build(kubeClient *client.Client) (*RouterConfig, error) {
	// Get all relevant information from k8s:
	//   deis-router rc
	//   All services with label "routable=true"
	//   deis-builder service, if it exists
	// These are used to construct a model...
	routerRC, err := getRC(kubeClient)
	if err != nil {
		return nil, err
	}
	appServices, err := getAppServices(kubeClient)