Beispiel #1
0
func launch(c *cli.Context) {
	conf := config.Conf(c)

	resultChan := make(chan error)

	rClient, err := config.GetRancherClient(conf)
	if err != nil {
		log.Fatal(err)
	}

	kClient := kubernetesclient.NewClient(conf.KubernetesURL, true)

	rcHandler := kubernetesevents.NewHandler(rClient, kClient, kubernetesevents.RCKind)
	svcHandler := kubernetesevents.NewHandler(rClient, kClient, kubernetesevents.ServiceKind)
	handlers := []kubernetesevents.Handler{rcHandler, svcHandler}

	go func(rc chan error) {
		err := kubernetesevents.ConnectToEventStream(handlers, conf)
		log.Errorf("Kubernetes stream listener exited with error: %s", err)
		rc <- err
	}(resultChan)

	go func(rc chan error) {
		err := rancherevents.ConnectToEventStream(conf)
		log.Errorf("Rancher stream listener exited with error: %s", err)
		rc <- err
	}(resultChan)

	<-resultChan
	log.Info("Exiting.")
}
func TestDetectsRemoval(t *testing.T) {
	metadataClient := metadata.NewClient(fakeMetadataURL)
	kubeClient := kubernetesclient.NewClient(kubeURL, false)
	c := cache.New(1*time.Minute, 1*time.Minute)

	metadataHandler.hosts = []metadata.Host{
		{
			Name:     "test1",
			Hostname: "test1",
			Labels:   map[string]string{},
		},
	}

	kubeHandler.nodes["test1"] = &model.Node{
		Metadata: &model.ObjectMeta{
			Labels: map[string]interface{}{
				"test1": "val1",
			},
			Annotations: map[string]interface{}{
				"io.rancher.labels.test1": "",
			},
			Name: "test1",
		},
	}

	sync(kubeClient, metadataClient, c)

	if _, ok := kubeHandler.nodes["test1"].Metadata.Labels["test1"]; ok {
		t.Error("Label test1 was not detected as removed")
	}
}
Beispiel #3
0
func ConnectToEventStream(conf config.Config) error {

	kClient := kubernetesclient.NewClient(conf.KubernetesURL, false)
	dClient, err := dockerclient.NewDockerClient()
	if err != nil {
		return err
	}
	sh := syncHandler{
		kClient: kClient,
		dClient: dClient,
	}
	ph := PingHandler{}

	eventHandlers := map[string]revents.EventHandler{
		"compute.instance.providelabels": sh.Handler,
		"config.update":                  ph.Handler,
		"ping":                           ph.Handler,
	}

	router, err := revents.NewEventRouter("", 0, conf.CattleURL, conf.CattleAccessKey, conf.CattleSecretKey, nil, eventHandlers, "", conf.WorkerCount)
	if err != nil {
		return err
	}
	err = router.Run(nil)
	return err
}
func (s *GenerichandlerTestSuite) SetUpSuite(c *check.C) {
	s.events = make(chan client.ExternalServiceEvent, 10)
	s.kClient = kubernetesclient.NewClient(conf.KubernetesURL, true)
	mock := &MockServiceEventOperations{
		events: s.events,
	}
	mockRancherClient := &client.RancherClient{
		ExternalServiceEvent: mock,
	}

	svcHandler := NewHandler(mockRancherClient, s.kClient, ServiceKind)
	handlers := []Handler{svcHandler}
	go ConnectToEventStream(handlers, conf)
	time.Sleep(time.Second)
}
Beispiel #5
0
func ConnectToEventStream(conf config.Config) error {

	kClient := kubernetesclient.NewClient(conf.KubernetesURL, false)

	eventHandlers := map[string]revents.EventHandler{
		"compute.instance.providelabels": eventhandlers.NewProvideLablesHandler(kClient).Handler,
		"config.update":                  eventhandlers.NewPingHandler().Handler,
		"ping":                           eventhandlers.NewPingHandler().Handler,
	}

	router, err := revents.NewEventRouter("", 0, conf.CattleURL, conf.CattleAccessKey, conf.CattleSecretKey, nil, eventHandlers, "", conf.WorkerCount, revents.DefaultPingConfig)
	if err != nil {
		return err
	}
	err = router.StartWithoutCreate(nil)
	return err
}
func (s *ListenerTestSuite) SetUpSuite(c *check.C) {
	s.publishChan = make(chan client.Publish, 10)

	s.kClient = kubernetesclient.NewClient(conf.KubernetesURL, true)

	mock := &MockPublishOperations{
		publishChan: s.publishChan,
	}
	s.mockRClient = &client.RancherClient{
		Publish: mock,
	}

	dClient, err := dockerclient.NewDockerClient()
	if err != nil {
		c.Fatal(err)
	}
	s.dClient = dClient
}
func launch(c *cli.Context) {
	conf := config.Conf(c)

	resultChan := make(chan error)

	rClient, err := config.GetRancherClient(conf)
	if err != nil {
		log.Fatal(err)
	}

	kClient := kubernetesclient.NewClient(conf.KubernetesURL, true)

	svcHandler := kubernetesevents.NewHandler(rClient, kClient, kubernetesevents.ServiceKind)
	handlers := []kubernetesevents.Handler{svcHandler}

	log.Info("Watching changes for kinds: ", c.StringSlice("watch-kind"))
	for _, kind := range c.StringSlice("watch-kind") {
		handlers = append(handlers, kubernetesevents.NewChangeHandler(rClient, kClient, kind))
	}

	go func(rc chan error) {
		err := kubernetesevents.ConnectToEventStream(handlers, conf)
		log.Errorf("Kubernetes stream listener exited with error: %s", err)
		rc <- err
	}(resultChan)

	go func(rc chan error) {
		err := rancherevents.ConnectToEventStream(conf)
		log.Errorf("Rancher stream listener exited with error: %s", err)
		rc <- err
	}(resultChan)

	go func(rc chan error) {
		err := healthcheck.StartHealthCheck(conf.HealthCheckPort)
		log.Errorf("Rancher healthcheck exited with error: %s", err)
		rc <- err
	}(resultChan)

	<-resultChan
	log.Info("Exiting.")
}
func TestDetectsChange(t *testing.T) {
	metadataClient := metadata.NewClient(fakeMetadataURL)
	kubeClient := kubernetesclient.NewClient(kubeURL, false)
	c := cache.New(1*time.Minute, 1*time.Minute)

	metadataHandler.hosts = []metadata.Host{
		{
			Name:     "test3",
			Hostname: "test3",
			Labels: map[string]string{
				"test3": "val3",
			},
		},
	}

	kubeHandler.nodes["test3"] = &model.Node{
		Metadata: &model.ObjectMeta{
			Labels: map[string]interface{}{
				"test3": "valx",
			},
			Annotations: map[string]interface{}{
				"io.rancher.labels.test3": "",
			},
			Name: "test3",
		},
	}

	sync(kubeClient, metadataClient, c)

	if val := kubeHandler.nodes["test3"].Metadata.Labels["test3"]; val != "val3" {
		t.Error("Label test3 was not detected as changed")
	}

	if _, ok := kubeHandler.nodes["test3"].Metadata.Annotations["io.rancher.labels.test3"]; !ok {
		t.Error("Annotation was not set on addition of new label")
	}
}