Beispiel #1
0
func initEnv(ctx *cli.Context) error {
	if ctx.GlobalBool("debug") {
		common.SetupLOG(log, "DEBUG")
	} else {
		common.SetupLOG(log, "INFO")
	}

	if noDaemon {
		client = NewLBClient()
	} else {
		var (
			c   *cnc.Client
			err error
		)
		if host := ctx.GlobalString("host"); host == "" {
			c, err = cnc.NewDefaultClient()
		} else {
			c, err = cnc.NewClient(host, nil)
		}
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error while creating cilium-client: %s\n", err)
			return fmt.Errorf("Error while creating cilium-client: %s", err)
		}
		client = c
	}

	return nil
}
func (s *CiliumClientSuite) SetUpSuite(c *C) {
	socketDir := os.Getenv("SOCKET_DIR")
	socketPath := filepath.Join(socketDir, "cilium.sock")
	tempLibDir, err := ioutil.TempDir("", "cilium-test")
	c.Assert(err, IsNil)
	tempRunDir, err := ioutil.TempDir("", "cilium-test-run")
	c.Assert(err, IsNil)
	err = os.Mkdir(filepath.Join(tempRunDir, "globals"), 0777)
	c.Assert(err, IsNil)

	nodeAddress, err := addressing.NewNodeAddress("beef:beef:beef:beef:aaaa:aaaa:1111:0", "10.1.0.1", "")
	c.Assert(err, IsNil)

	daemonConf := cnd.NewConfig()
	daemonConf.LibDir = tempLibDir
	daemonConf.RunDir = tempRunDir
	daemonConf.DryMode = true
	daemonConf.LXCMap = nil
	daemonConf.NodeAddress = nodeAddress
	daemonConf.DockerEndpoint = "tcp://127.0.0.1"
	daemonConf.K8sEndpoint = "tcp://127.0.0.1"
	daemonConf.ValidLabelPrefixes = nil
	daemonConf.OptsMU.Lock()
	daemonConf.Opts.Set(endpoint.OptionDropNotify, true)
	daemonConf.OptsMU.Unlock()
	daemonConf.Device = "undefined"

	err = daemonConf.SetKVBackend()
	c.Assert(err, IsNil)

	d1 := []byte("#!/usr/bin/env bash\necho \"OK\"\n")
	err = ioutil.WriteFile(filepath.Join(daemonConf.LibDir, "join_ep.sh"), d1, 0755)
	c.Assert(err, IsNil)
	err = ioutil.WriteFile(filepath.Join(daemonConf.LibDir, "init.sh"), d1, 0755)
	c.Assert(err, IsNil)

	d, err := cnd.NewDaemon(daemonConf)
	if err != nil {
		c.Fatalf("Failed while creating new cilium-net test server: %+v", err)
	}
	server, err := cns.NewServer(socketPath, d)
	if err != nil {
		c.Fatalf("Failed while creating new cilium-net test server: %+v", err)
	}

	cli, err := cnc.NewClient("unix://"+socketPath, nil)
	if err != nil {
		c.Fatalf("Failed while creating new client: %+v", err)
	}
	s.cli = cli
	s.server = server

	go func() {
		if err := s.server.Start(); err != nil {
			c.Fatalf("Error while starting cilium-net test server: %s", err)
			s.server.Stop()
		}
	}()
}
Beispiel #3
0
func statusDaemon(ctx *cli.Context) {
	var (
		client *cnc.Client
		err    error
	)
	if host := ctx.GlobalString("host"); host == "" {
		client, err = cnc.NewDefaultClient()
	} else {
		client, err = cnc.NewClient(host, nil)
	}
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error while creating cilium-client: %s\n", err)
		os.Exit(1)
	}

	if sr, err := client.GlobalStatus(); err != nil {
		fmt.Fprintf(os.Stderr, "Status: ERROR - Unable to reach out daemon: %s\n", err)
		os.Exit(1)
	} else {
		w := tabwriter.NewWriter(os.Stdout, 2, 0, 3, ' ', 0)
		fmt.Fprintf(w, "KVStore:\t%s\n", sr.KVStore)
		fmt.Fprintf(w, "Docker:\t%s\n", sr.Docker)
		fmt.Fprintf(w, "Kubernetes:\t%s\n", sr.Kubernetes)
		fmt.Fprintf(w, "Cilium:\t%s\n", sr.Cilium)
		w.Flush()

		if sr.IPAMStatus != nil {
			fmt.Printf("V4 addresses reserved:\n")
			for _, ipv4 := range sr.IPAMStatus["4"] {
				fmt.Printf(" %s\n", ipv4)

			}
			fmt.Printf("V6 addresses reserved:\n")
			for _, ipv6 := range sr.IPAMStatus["6"] {
				fmt.Printf(" %s\n", ipv6)
			}
			w.Flush()
		}

		os.Exit(int(sr.Cilium.Code))
	}

}
Beispiel #4
0
func (s *DaemonSuite) SetUpSuite(c *C) {
	s.d = NewTestDaemon()

	r := NewRouter(s.d)

	l, err := net.Listen("tcp", "127.0.0.1:0")
	if err != nil {
		c.Fatalf("Error while trying to listen: %+v", err)
	}

	s.s = &server{l, "127.0.0.1", r}
	go func() {
		if err := s.s.Start(); err != nil {
			c.Fatalf("Error while starting cilium-net test server: %s", err)
			s.s.Stop()
		}
	}()

	s.c, err = cnc.NewClient("http://"+s.s.listener.Addr().String(), nil)
	if err != nil {
		c.Fatalf("Error while trying to listen: %+v", err)
	}
}
Beispiel #5
0
func configDaemon(ctx *cli.Context) {
	var (
		client *cnc.Client
		err    error
	)

	first := ctx.Args().First()

	if first == "list" {
		for k, s := range daemon.DaemonOptionLibrary {
			fmt.Printf("%-24s %s\n", k, s.Description)
		}
		return
	}

	if host := ctx.GlobalString("host"); host == "" {
		client, err = cnc.NewDefaultClient()
	} else {
		client, err = cnc.NewClient(host, nil)
	}

	if err != nil {
		fmt.Fprintf(os.Stderr, "Error while creating cilium-client: %s\n", err)
		os.Exit(1)
	}

	res, err := client.Ping()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to reach daemon: %s\n", err)
		os.Exit(1)
	}

	if res == nil {
		fmt.Fprintf(os.Stderr, "Empty response from daemon\n")
		os.Exit(1)
	}

	opts := ctx.Args()

	if len(opts) == 0 {
		res.Opts.Dump()
		return
	}

	dOpts := make(option.OptionMap, len(opts))

	for k := range opts {
		name, value, err := option.ParseOption(opts[k], &daemon.DaemonOptionLibrary)
		if err != nil {
			fmt.Printf("%s\n", err)
			os.Exit(1)
		}

		dOpts[name] = value

		err = client.Update(dOpts)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Unable to update daemon: %s\n", err)
			os.Exit(1)
		}
	}
}