Exemplo n.º 1
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	kingpin.Version(getVersion())
	kingpin.MustParse(ro.Parse(os.Args[1:]))
	logger.Configure(*logLevel, "[romulusd] ", os.Stdout)
	logger.Infof("Starting up romulusd version=%s", getVersion())

	ctx, cancel := context.WithCancel(context.Background())
	lb, er := getLBProvider(*provider, ctx)
	if er != nil {
		logger.Fatalf(er.Error())
	}

	kubernetes.Keyspace = normalizeAnnotationsKey(*annoKey)
	ng, er := NewEngine((*kubeAPI).String(), *kubeUser, *kubePass, *kubeSec, lb, *timeout, ctx)
	if er != nil {
		logger.Fatalf(er.Error())
	}

	if er := ng.Start(*selector, *resync); er != nil {
		logger.Fatalf(er.Error())
	}

	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)
	select {
	case <-sig:
		logger.Infof("Shutting Down...")
		cancel()
		time.Sleep(100 * time.Millisecond)
		os.Exit(0)
	}
}
Exemplo n.º 2
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	kingpin.Version(version)
	kingpin.MustParse(app.Parse(os.Args[1:]))
	logger.Configure(*level, "[transmon] ", os.Stdout)
	logger.Infof("Starting transmon version %v", version)

	c, stop := context.WithCancel(context.Background())
	conf, er := config.ReadAndWatch(*conf, c)
	if er != nil {
		logger.Fatalf("Failed to read config: %v", er)
	}

	go workers(conf, c, stop)

	if conf.Cleaner.Enabled {
		go cleaner(conf, c)
	}

	sig := make(chan os.Signal, 1)
	signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)
	select {
	case <-sig:
		logger.Infof("Received interrupt, shutting down...")
		close(sig)
		stop()
		time.Sleep(3 * time.Second)
		os.Exit(0)
	}
}
Exemplo n.º 3
0
func TestDefaultResourceFromIngress(te *testing.T) {
	var (
		is  = assert.New(te)
		m   = NewCache()
		ing = &extensions.Ingress{
			ObjectMeta: api.ObjectMeta{Name: "ingress", Namespace: "test", UID: types.UID("one")},
			Spec: extensions.IngressSpec{
				Backend: &extensions.IngressBackend{
					ServiceName: "service",
					ServicePort: intstr.FromString("web"),
				},
			},
		}
		svc = &api.Service{
			ObjectMeta: api.ObjectMeta{Name: "service", Namespace: "test", UID: types.UID("two")},
			Spec: api.ServiceSpec{
				Type:      api.ServiceTypeClusterIP,
				ClusterIP: "1.2.3.4",
				Ports: []api.ServicePort{
					api.ServicePort{Name: "web", Port: 80, TargetPort: intstr.FromString("http")},
				},
			},
		}
		end = &api.Endpoints{
			ObjectMeta: api.ObjectMeta{Name: "service", Namespace: "test", UID: types.UID("three")},
			Subsets: []api.EndpointSubset{
				api.EndpointSubset{
					Addresses: []api.EndpointAddress{
						api.EndpointAddress{IP: "10.11.12.13"},
						api.EndpointAddress{IP: "10.20.21.23"},
					},
					Ports: []api.EndpointPort{
						api.EndpointPort{Name: "web", Port: 8080, Protocol: api.ProtocolTCP},
					},
				},
			},
		}
	)

	if testing.Verbose() {
		logger.Configure("debug", "[romulus-test] ", os.Stdout)
		defer logger.SetLevel("error")
	}

	m.SetServiceStore(cache.NewStore(cache.MetaNamespaceKeyFunc))
	m.SetEndpointsStore(cache.NewStore(cache.MetaNamespaceKeyFunc))
	m.endpoints.Add(end)
	m.service.Add(svc)

	list := resourcesFromIngress(m, ing)
	te.Logf("Default ResourceList: %v", list)
	is.True(len(list) > 0, "ResourceList should be non-zero")
	ma := list.Map()
	rsc, ok := ma["test.service.web"]
	if is.True(ok, "'test.service.web' not created: %v", list) {
		is.False(rsc.NoServers(), "%v should have servers", rsc)
	}
}
Exemplo n.º 4
0
func TestRoutedResourceFromIngress(te *testing.T) {
	var (
		is  = assert.New(te)
		m   = NewCache()
		ing = &extensions.Ingress{
			ObjectMeta: api.ObjectMeta{Name: "ingress", Namespace: "test", UID: types.UID("one")},
			Spec: extensions.IngressSpec{
				Rules: []extensions.IngressRule{
					extensions.IngressRule{
						Host: "www.example.net",
						IngressRuleValue: extensions.IngressRuleValue{
							HTTP: &extensions.HTTPIngressRuleValue{
								Paths: []extensions.HTTPIngressPath{
									extensions.HTTPIngressPath{
										Path: "/foo",
										Backend: extensions.IngressBackend{
											ServiceName: "service",
											ServicePort: intstr.FromString("web"),
										},
									},
								},
							},
						},
					},
				},
			},
		}
		svc = &api.Service{
			ObjectMeta: api.ObjectMeta{
				Name:        "service",
				Namespace:   "test",
				UID:         types.UID("two"),
				Annotations: map[string]string{"romulus/path": "/bar"},
			},
			Spec: api.ServiceSpec{
				Type: api.ServiceTypeClusterIP,
				Ports: []api.ServicePort{
					api.ServicePort{Name: "web", Port: 80, TargetPort: intstr.FromString("http")},
				},
			},
		}
		end = &api.Endpoints{
			ObjectMeta: api.ObjectMeta{Name: "service", Namespace: "test", UID: types.UID("three")},
			Subsets: []api.EndpointSubset{
				api.EndpointSubset{
					Addresses: []api.EndpointAddress{
						api.EndpointAddress{IP: "10.11.12.13"},
						api.EndpointAddress{IP: "10.20.21.23"},
					},
					Ports: []api.EndpointPort{
						api.EndpointPort{Name: "web", Port: 8080, Protocol: api.ProtocolTCP},
					},
				},
			},
		}
	)

	if testing.Verbose() {
		logger.Configure("debug", "[romulus-test] ", os.Stdout)
		defer logger.SetLevel("error")
	}

	m.SetServiceStore(cache.NewStore(cache.MetaNamespaceKeyFunc))
	m.SetEndpointsStore(cache.NewStore(cache.MetaNamespaceKeyFunc))
	m.service.Add(svc)
	m.endpoints.Add(end)

	list := resourcesFromIngress(m, ing)
	te.Logf("Routed ResourceList: %v", list)
	is.True(len(list) > 0, "ResourceList should be non-zero")
	ma := list.Map()
	rsc, ok := ma["test.service.web"]
	if is.True(ok, "'test.service.web' not created: %v", list) {
		is.False(rsc.NoServers(), "%v should have servers", rsc)
		rt := rsc.Route.String()
		is.Equal("Route(host(`www.example.net`) && path(`/foo`))", rt)
	}
}
Exemplo n.º 5
0
func main() {
	app.Version(version)
	command := kingpin.MustParse(app.Parse(os.Args[1:]))
	logger.Configure(*logLevel, "[runchef] ", os.Stdout)

	switch command {
	case enable.FullCommand():
		cli, er := ezd.New(etcdEp, etcdTo)
		if er != nil {
			logger.Fatalf(er.Error())
		}

		if reason, ok := cli.Get(disableKey); ok == nil {
			if er := cli.Delete(disableKey); er != nil {
				logger.Fatalf(er.Error())
			}
			logger.Infof("Chef is now enabled! (Was disabled with reason: %s)", reason)
		} else {
			logger.Infof("Chef is already enabled.")
		}
	case disable.FullCommand():
		cli, er := ezd.New(etcdEp, etcdTo)
		if er != nil {
			logger.Fatalf(er.Error())
		}

		if reason, ok := cli.Get(disableKey); ok == nil {
			logger.Infof("Chef is already disabled with reason: %s", reason)
		} else {
			if er := cli.Set(disableKey, *disableReason); er != nil {
				logger.Fatalf(er.Error())
			}
			logger.Infof("Chef disabled with reason: %s", *disableReason)
		}
	case shell.FullCommand():
		c := *shellImage
		if len(*shellContainer) > 0 {
			c = *shellContainer
			*pullImage = false
		}
		if er := runShell(c, *shellCache, *pullImage); er != nil {
			logger.Fatalf(er.Error())
		}
	case client.FullCommand():
		c := *clientImage
		if len(*clientContainer) > 0 {
			c = *clientContainer
			*pullImage = false
		}
		cli, er := ezd.New(etcdEp, etcdTo)
		if er != nil {
			logger.Fatalf(er.Error())
		}
		if reason, ok := cli.Get(disableKey); ok == nil {
			logger.Infof("Chef is disabled: %v", reason)
			os.Exit(0)
		}
		defer cleanupChef()
		newClientRB(filepath.Join(*chefDir, "client.rb"), *clientName, *clientEnv, *sslVerify).write()
		if er := runChef(c, *clientCache, *clientEnv, *clientRunlist, *clientForceFmt, *clientLocal, *pullImage); er != nil {
			logger.Fatalf(er.Error())
		}
	}
}
Exemplo n.º 6
0
func init() {
	logger.Configure("debug", "[transmon] ", os.Stdout)
}