Example #1
0
func init() {
	bin := path.Base(os.Args[0])
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, `
Usage of %s
================
Example:
  %% %s
`, bin, bin)
		flag.PrintDefaults()
	}
	serverConfig = conf.New()
	serverConfig.VersionBuildStamp = Buildstamp
	serverConfig.VersionGitHash = Githash
	//config from file is loaded.
	//the values will be overwritten by command line flags
	flag.BoolVar(&serverConfig.DebugEnabled, "debug", serverConfig.DebugEnabled, "Enable debug output")
	flag.BoolVar(&serverConfig.Oauth2Enabled, "oauth", serverConfig.Oauth2Enabled, "Enable OAuth2")
	flag.BoolVar(&serverConfig.TeamAuthorization, "team-auth", serverConfig.TeamAuthorization, "Enable team based authorization")
	flag.StringVar(&serverConfig.AuthURL, "oauth-authurl", serverConfig.AuthURL, "OAuth2 Auth URL")
	flag.StringVar(&serverConfig.TokenURL, "oauth-tokeninfourl", serverConfig.TokenURL, "OAuth2 Auth URL")
	flag.StringVar(&serverConfig.TlsCertfilePath, "tls-cert", serverConfig.TlsCertfilePath, "TLS Certfile")
	flag.StringVar(&serverConfig.TlsKeyfilePath, "tls-key", serverConfig.TlsKeyfilePath, "TLS Keyfile")
	flag.IntVar(&serverConfig.Port, "port", serverConfig.Port, "Listening TCP Port of the service.")
	if serverConfig.Port == 0 {
		serverConfig.Port = 8082 //default port when no option is provided
	}
	flag.DurationVar(&serverConfig.LogFlushInterval, "flush-interval", time.Second*5, "Interval to flush Logs to disk.")
}
Example #2
0
// getMarathonClient connects to mesos cluster
// returns marathon interface like tasks, applications
// groups, deployment, subscriptions, ...
func initMarathonClient() marathon.Marathon {
	config := marathon.NewDefaultConfig()
	config.URL = conf.New().Endpoint
	client, err := marathon.NewClient(config)
	if err != nil {
		glog.Fatalf("Failed to create a client for marathon, error: %s", err)
	}
	return client
}
Example #3
0
// Deploy deploys a new application
// takes CreateRequest from backend as argument
func (mb MarathonBackend) Deploy(cr *backend.CreateRequest) (string, error) {
	glog.Infof("Deploying a new application with name %s", cr.Name)
	app := marathon.NewDockerApplication()
	id := cr.Name
	ports := cr.Ports
	cpu := float64(cr.CPULimit)
	storage := 0.0 //TODO: setup limit for storage
	memory := float64(cr.MemoryLimit)
	labels := cr.Labels
	imageurl := cr.ImageURL
	env := cr.Env
	replicas := cr.Replicas

	app.Name(id)
	app.Uris = strings.Fields(DOCKERCFG)
	app.CPU(cpu).Memory(memory).Storage(storage).Count(replicas)
	app.Env = env
	portmappings := make([]*marathon.PortMapping, 0, len(ports))
	for _, port := range ports {
		portmappings = append(portmappings, &marathon.PortMapping{ContainerPort: port, HostPort: 0, Protocol: "tcp"}) //TODO: change to protocol params, we probably want to have UDP too.
	}

	app.Container.Docker.PortMappings = portmappings
	//fluentd implementation
	if conf.New().FluentdEnabled {
		app.Container.Docker.Parameter("log-driver", "fluentd")
		app.Container.Docker.Parameter("log-opt", "\"fluentd-address=localhost:24224\"")
		app.Container.Docker.Parameter("log-opt", "\"fluentd-tag={{.Name}}\"")
	}
	app.Labels = labels

	app.Container.Docker.Container(imageurl).ForcePullImage = true

	//forcing basic health checks by default.
	//TODO  must be configurable later.
	checks := make([]*marathon.HealthCheck, 0, 2)
	httpHealth := marathon.HealthCheck{Protocol: "HTTP", Path: "/health", GracePeriodSeconds: 3, IntervalSeconds: 10, MaxConsecutiveFailures: 10}
	cmdHealth := marathon.HealthCheck{Protocol: "COMMAND", Command: &marathon.Command{Value: "curl -f -X GET  http://$HOST:$PORT0/health"}, MaxConsecutiveFailures: 10}
	checks = append(checks, &httpHealth)
	checks = append(checks, &cmdHealth)
	//app.HealthChecks = checks //FIXME health check has been removed because they were constantly killing the instances.
	application, err := mb.Client.CreateApplication(app)
	glog.Info(application) //TODO do we want to get some more information? Container IDs? I guess they can be not stable
	if err != nil {
		glog.Errorf("Could not create application %s, error %s", app.ID, err)
		return "", err
	}
	glog.Infof("Application was created, %s", app.ID)
	return app.ID, nil

}
Example #4
0
func getKubernetesClient() *k8s.Client {
	client := k8s.NewOrDie(&k8s.Config{Host: conf.New().Endpoint, Version: "v1"}) //PANIC if config not correct
	return client
}