func NewDefaultConfigurer(ipt *iptables.IPTablesController) kawasaki.Configurer {
	resolvConfigurer := &kawasaki.ResolvConfigurer{
		HostsFileCompiler:  &dns.HostsFileCompiler{},
		ResolvFileCompiler: &dns.ResolvFileCompiler{},
		FileWriter:         &dns.RootfsWriter{},
		IDMapReader:        &kawasaki.RootIdMapReader{},
	}

	hostConfigurer := &configure.Host{
		Veth:       &devices.VethCreator{},
		Link:       &devices.Link{},
		Bridge:     &devices.Bridge{},
		FileOpener: netns.Opener(os.Open),
	}

	containerConfigurer := &configure.Container{
		FileOpener: netns.Opener(os.Open),
	}

	return kawasaki.NewConfigurer(
		resolvConfigurer,
		hostConfigurer,
		containerConfigurer,
		iptables.NewInstanceChainCreator(ipt),
	)
}
		netNsPath := fmt.Sprintf("/run/netns/%s", netNsName)
		netNsFd, err = os.Open(netNsPath)
		Expect(err).NotTo(HaveOccurred())

		sess, err = gexec.Start(exec.Command("ip", "link", "add", linkName, "type", "dummy"), GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())
		Eventually(sess).Should(gexec.Exit(0))

		sess, err = gexec.Start(exec.Command("ip", "link", "set", linkName, "netns", netNsName), GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())
		Eventually(sess).Should(gexec.Exit(0))

		configurer = &configure.Container{
			FileOpener: netns.Opener(func(path string) (*os.File, error) {
				return netNsFd, nil
			}),
		}

		logger = lagertest.NewTestLogger("container")

		containerIP, subnet, err := net.ParseCIDR("192.0.2.20/24")
		Expect(err).NotTo(HaveOccurred())
		networkConfig = kawasaki.NetworkConfig{
			ContainerIntf: linkName,
			ContainerIP:   containerIP,
			BridgeIP:      net.ParseIP("192.0.2.1"),
			Subnet:        subnet,
			Mtu:           1600,
		}
	})
Exemple #3
0
	BeforeEach(func() {
		vethCreator = &fakedevices.FaveVethCreator{}
		linkConfigurer = &fakedevices.FakeLink{AddIPReturns: make(map[string]error)}
		bridger = &fakedevices.FakeBridge{}

		logger = lagertest.NewTestLogger("test")
		config = kawasaki.NetworkConfig{}
	})

	JustBeforeEach(func() {
		configurer = &configure.Host{
			Veth:       vethCreator,
			Link:       linkConfigurer,
			Bridge:     bridger,
			FileOpener: netns.Opener(nsOpener),
		}
	})

	Describe("Apply", func() {
		var (
			netnsFD *os.File

			existingBridge *net.Interface
		)

		BeforeEach(func() {
			var err error
			netnsFD, err = ioutil.TempFile("", "")
			Expect(err).NotTo(HaveOccurred())