예제 #1
0
파일: main.go 프로젝트: digideskio/guardian
func wireNetworker(
	log lager.Logger,
	tag string,
	networkPoolCIDR *net.IPNet,
	externalIP net.IP,
	iptablesMgr kawasaki.IPTablesConfigurer,
	interfacePrefix string,
	chainPrefix string,
	propManager *properties.Manager,
	networkModulePath string) gardener.Networker {
	runner := &logging.Runner{CommandRunner: linux_command_runner.New(), Logger: log.Session("network-runner")}

	hostConfigurer := &configure.Host{
		Veth:   &devices.VethCreator{},
		Link:   &devices.Link{Name: "guardian"},
		Bridge: &devices.Bridge{},
		Logger: log.Session("network-host-configurer"),
	}

	containerCfgApplier := &configure.Container{
		Logger: log.Session("network-container-configurer"),
		Link:   &devices.Link{Name: "guardian"},
	}

	idGenerator := kawasaki.NewSequentialIDGenerator(time.Now().UnixNano())
	portPool, err := ports.NewPool(uint32(*portPoolStart), uint32(*portPoolSize), ports.State{})
	if err != nil {
		log.Fatal("invalid pool range", err)
	}

	switch networkModulePath {
	case "":
		return kawasaki.New(
			kawasaki.NewManager(runner, "/var/run/netns"),
			kawasaki.SpecParserFunc(kawasaki.ParseSpec),
			subnets.NewPool(networkPoolCIDR),
			kawasaki.NewConfigCreator(idGenerator, interfacePrefix, chainPrefix, externalIP),
			kawasaki.NewConfigurer(
				hostConfigurer,
				containerCfgApplier,
				iptablesMgr,
				&netns.Execer{},
			),
			propManager,
			iptables.NewPortForwarder(runner),
			portPool,
		)
	default:
		if _, err := os.Stat(networkModulePath); err != nil {
			log.Fatal("failed-to-stat-network-module", err)
			return nil
		}
		return gardener.ForeignNetworkAdaptor{
			ForeignNetworker: genclient.New(networkModulePath),
		}
	}
}
예제 #2
0
var _ = Describe("NetnsMgr", func() {
	var (
		fakeRunner *fake_command_runner.FakeCommandRunner
		netnsDir   string
		mgr        kawasaki.NetnsMgr
		logger     lager.Logger
	)

	BeforeEach(func() {
		netnsDir = tmpDir()
		logger = lagertest.NewTestLogger("test")
	})

	JustBeforeEach(func() {
		fakeRunner = fake_command_runner.New()
		mgr = kawasaki.NewManager(fakeRunner, netnsDir)
	})

	AfterEach(func() {
		os.RemoveAll(netnsDir)
	})

	Describe("Creating a Network Namespace", func() {
		It("creates a namespace using 'ip netns add'", func() {
			Expect(mgr.Create(logger, "my-namespace")).To(Succeed())

			Expect(fakeRunner).To(HaveExecutedSerially(fake_command_runner.CommandSpec{
				Path: "ip",
				Args: []string{
					"netns", "add", "my-namespace",
				},