Example #1
0
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),
	)
}
Example #2
0
	BeforeEach(func() {
		fakeDnsResolvConfigurer = new(fakes.FakeDnsResolvConfigurer)

		fakeHostConfigurer = new(fakes.FakeHostConfigurer)
		fakeContainerConfigurer = new(fakes.FakeContainerConfigurer)
		fakeInstanceChainCreator = new(fakes.FakeInstanceChainCreator)

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

		dummyFileOpener = func(path string) (*os.File, error) {
			return netnsFD, nil
		}

		configurer = kawasaki.NewConfigurer(fakeDnsResolvConfigurer, fakeHostConfigurer, fakeContainerConfigurer, fakeInstanceChainCreator)

		logger = lagertest.NewTestLogger("test")
	})

	AfterEach(func() {
		Expect(os.Remove(netnsFD.Name())).To(Succeed())
	})

	Describe("Apply", func() {
		It("configures dns", func() {
			Expect(configurer.Apply(logger, kawasaki.NetworkConfig{ContainerHandle: "h"}, 42)).To(Succeed())
			Expect(fakeDnsResolvConfigurer.ConfigureCallCount()).To(Equal(1))
			_, cfg, pid := fakeDnsResolvConfigurer.ConfigureArgsForCall(0)
			Expect(cfg).To(Equal(kawasaki.NetworkConfig{ContainerHandle: "h"}))
			Expect(pid).To(Equal(42))