diff --git a/src/code.cloudfoundry.org/silk/controller/integration/helpers/helpers.go b/src/code.cloudfoundry.org/silk/controller/integration/helpers/helpers.go index 7260a23b4..57b8e5259 100644 --- a/src/code.cloudfoundry.org/silk/controller/integration/helpers/helpers.go +++ b/src/code.cloudfoundry.org/silk/controller/integration/helpers/helpers.go @@ -31,7 +31,7 @@ func DefaultTestConfig(dbConf db.Config, fixturesPath string) config.Config { CACertFile: filepath.Join(fixturesPath, "ca.crt"), ServerCertFile: filepath.Join(fixturesPath, "server.crt"), ServerKeyFile: filepath.Join(fixturesPath, "server.key"), - Network: "10.255.0.0/16", + Network: []string{"10.255.0.0/16", "10.250.0.0/16"}, SubnetPrefixLength: 24, Database: dbConf, LeaseExpirationSeconds: 60, diff --git a/src/code.cloudfoundry.org/silk/controller/integration/integration_test.go b/src/code.cloudfoundry.org/silk/controller/integration/integration_test.go index a78efe508..e4bd9be3a 100644 --- a/src/code.cloudfoundry.org/silk/controller/integration/integration_test.go +++ b/src/code.cloudfoundry.org/silk/controller/integration/integration_test.go @@ -14,6 +14,7 @@ import ( "code.cloudfoundry.org/silk/controller/config" "code.cloudfoundry.org/silk/controller/integration/helpers" "code.cloudfoundry.org/silk/controller/leaser" + "code.cloudfoundry.org/silk/daemon" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -83,14 +84,21 @@ var _ = Describe("Silk Controller", func() { Describe("acquiring", func() { It("provides an endpoint to acquire a subnet leases", func() { + By("acquiring a lease") lease, err := testClient.AcquireSubnetLease("10.244.4.5") Expect(err).NotTo(HaveOccurred()) Expect(lease.UnderlayIP).To(Equal("10.244.4.5")) + + By("checking that the lease subnet is valid") _, subnet, err := net.ParseCIDR(lease.OverlaySubnet) Expect(err).NotTo(HaveOccurred()) - _, network, err := net.ParseCIDR(conf.Network) + + By("checking that the lease is contained in the overlay network") + overlayNetwork, err := daemon.NewMultipleCIDRNetwork(conf.Network) Expect(err).NotTo(HaveOccurred()) - Expect(network.Contains(subnet.IP)).To(BeTrue()) + Expect(overlayNetwork.Contains(subnet.IP)).To(BeTrue()) + + By("checking the hardware attr") expectedHardwareAddr, err := (&leaser.HardwareAddressGenerator{}).GenerateForVTEP(subnet.IP) Expect(err).NotTo(HaveOccurred()) Expect(lease.OverlayHardwareAddr).To(Equal(expectedHardwareAddr.String())) @@ -117,19 +125,24 @@ var _ = Describe("Silk Controller", func() { Context("when the existing lease is in a different overlay network", func() { BeforeEach(func() { helpers.StopServer(session) - conf.Network = "10.254.0.0/16" + conf.Network = []string{"10.254.0.0/16", "10.253.0.0/16"} session = helpers.StartAndWaitForServer(controllerBinaryPath, conf, testClient) }) + It("returns a new lease in the new network", func() { + By("acquiring a new lease after the overlay network has changed") lease, err := testClient.AcquireSubnetLease("10.244.4.5") Expect(err).NotTo(HaveOccurred()) - Expect(lease).NotTo(Equal(existingLease)) + + By("checking that the new lease is a valid subnet") _, subnet, err := net.ParseCIDR(lease.OverlaySubnet) Expect(err).NotTo(HaveOccurred()) - _, network, err := net.ParseCIDR(conf.Network) + + By("checking that the new lease is in the new overlay network") + overlayNetwork, err := daemon.NewMultipleCIDRNetwork(conf.Network) Expect(err).NotTo(HaveOccurred()) - Expect(network.Contains(subnet.IP)).To(BeTrue()) + Expect(overlayNetwork.Contains(subnet.IP)).To(BeTrue()) }) }) }) @@ -199,7 +212,7 @@ var _ = Describe("Silk Controller", func() { Describe("lease expiration", func() { BeforeEach(func() { helpers.StopServer(session) - conf.Network = "10.255.0.0/29" + conf.Network = []string{"10.255.0.0/29"} conf.SubnetPrefixLength = 30 conf.LeaseExpirationSeconds = 3 session = helpers.StartAndWaitForServer(controllerBinaryPath, conf, testClient) @@ -302,7 +315,7 @@ var _ = Describe("Silk Controller", func() { Context("when the existing lease is in a different overlay network", func() { BeforeEach(func() { helpers.StopServer(session) - conf.Network = "10.254.0.0/16" + conf.Network = []string{"10.254.0.0/16"} session = helpers.StartAndWaitForServer(controllerBinaryPath, conf, testClient) }) It("renews the same lease in the old network", func() { @@ -399,7 +412,7 @@ var _ = Describe("Silk Controller", func() { Expect(err).NotTo(HaveOccurred()) helpers.StopServer(session) - conf.Network = "10.254.0.0/16" + conf.Network = []string{"10.254.0.0/16"} session = helpers.StartAndWaitForServer(controllerBinaryPath, conf, testClient) newNetworkLease, err = testClient.AcquireSubnetLease("10.244.4.6") @@ -437,13 +450,13 @@ var _ = Describe("Silk Controller", func() { leaseIPs := make(map[string]struct{}) leaseSubnets := make(map[string]struct{}) - _, network, err := net.ParseCIDR(conf.Network) + overlayNetwork, err := daemon.NewMultipleCIDRNetwork(conf.Network) Expect(err).NotTo(HaveOccurred()) for lease := range leases { _, subnet, err := net.ParseCIDR(lease.OverlaySubnet) Expect(err).NotTo(HaveOccurred()) - Expect(network.Contains(subnet.IP)).To(BeTrue()) + Expect(overlayNetwork.Contains(subnet.IP)).To(BeTrue()) leaseIPs[lease.UnderlayIP] = struct{}{} leaseSubnets[lease.OverlaySubnet] = struct{}{} @@ -474,13 +487,13 @@ var _ = Describe("Silk Controller", func() { leaseUnderlays := make(map[string]struct{}) leaseIPs := make(map[string]struct{}) - _, network, err := net.ParseCIDR(conf.Network) + overlayNetwork, err := daemon.NewMultipleCIDRNetwork(conf.Network) Expect(err).NotTo(HaveOccurred()) for lease := range leases { _, subnet, err := net.ParseCIDR(lease.OverlaySubnet) Expect(err).NotTo(HaveOccurred()) - Expect(network.Contains(subnet.IP)).To(BeTrue()) + Expect(overlayNetwork.Contains(subnet.IP)).To(BeTrue()) Expect(lease.OverlaySubnet).To(ContainSubstring("/32")) leaseUnderlays[lease.UnderlayIP] = struct{}{} @@ -531,7 +544,11 @@ var _ = Describe("Silk Controller", func() { Eventually(fakeMetron.AllEvents, "10s").Should(ContainElement(hasMetricWithValue("totalLeases", 2))) }) It("emits number of free leases", func() { - Eventually(fakeMetron.AllEvents, "10s").Should(ContainElement(hasMetricWithValue("freeLeases", 253))) + // 256 per /16 + // 2 * /16 cidrs = 512 + // 512 - 1 (for the single ip subnet) = 511 + // 511 - 2 (for the two leases acquired in this test) = 209 + Eventually(fakeMetron.AllEvents, "10s").Should(ContainElement(hasMetricWithValue("freeLeases", 509))) }) It("emits number of stale leases", func() { Eventually(fakeMetron.AllEvents, "2s").Should(ContainElement(hasMetricWithValue("staleLeases", 0))) @@ -539,6 +556,5 @@ var _ = Describe("Silk Controller", func() { Eventually(fakeMetron.AllEvents, "10s").Should(ContainElement(hasMetricWithValue("staleLeases", 2))) }) }) - }) })