From b476e17cb895d65c2fcfaaa2365be673ab729d11 Mon Sep 17 00:00:00 2001 From: Philipp Riederer Date: Fri, 19 Aug 2022 10:29:57 +0200 Subject: [PATCH 1/2] Test the non-working `enable_overlapping_ranges`-config --- pkg/config/config_test.go | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 8ebfc7944..d8c494fca 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -94,7 +94,44 @@ var _ = Describe("Allocation operations", func() { Expect(ipamconfig.LeaderLeaseDuration).To(Equal(3000)) Expect(ipamconfig.LeaderRenewDeadline).To(Equal(2000)) Expect(ipamconfig.LeaderRetryPeriod).To(Equal(1000)) + }) + + It("overlapping range can be set", func() { + var globalConf string = `{ + "datastore": "kubernetes", + "kubernetes": { + "kubeconfig": "/etc/cni/net.d/whereabouts.d/whereabouts.kubeconfig" + }, + "log_file": "/tmp/whereabouts.log", + "log_level": "debug", + "gateway": "192.168.5.5", + "enable_overlapping_ranges": false + }` + Expect(ioutil.WriteFile("/tmp/whereabouts.conf", []byte(globalConf), 0755)).To(Succeed()) + + ipamconfig, _, err := LoadIPAMConfig([]byte(generateIPAMConfWithOverlappingRanges()), "") + Expect(err).NotTo(HaveOccurred()) + Expect(ipamconfig.OverlappingRanges).To(BeTrue()) + }) + + It("overlapping range can be disabled", func() { + var globalConf string = `{ + "datastore": "kubernetes", + "kubernetes": { + "kubeconfig": "/etc/cni/net.d/whereabouts.d/whereabouts.kubeconfig" + }, + "log_file": "/tmp/whereabouts.log", + "log_level": "debug", + "gateway": "192.168.5.5", + "enable_overlapping_ranges": true + }` + Expect(ioutil.WriteFile("/tmp/whereabouts.conf", []byte(globalConf), 0755)).To(Succeed()) + + ipamconfig, _, err := LoadIPAMConfig([]byte(generateIPAMConfWithoutOverlappingRanges()), "") + Expect(err).NotTo(HaveOccurred()) + + Expect(ipamconfig.OverlappingRanges).To(BeFalse()) }) It("can load a config list", func() { @@ -283,3 +320,33 @@ var _ = Describe("Allocation operations", func() { Expect(ipamConfig.ReconcilerCronExpression).To(Equal("30 4 * * *")) }) }) + +func generateIPAMConfWithOverlappingRanges() string { + return `{ + "cniVersion": "0.3.1", + "name": "mynet", + "type": "ipvlan", + "master": "foo0", + "ipam": { + "range": "192.168.2.230/24", + "configuration_path": "/tmp/whereabouts.conf", + "type": "whereabouts", + "enable_overlapping_ranges": true + } + }` +} + +func generateIPAMConfWithoutOverlappingRanges() string { + return `{ + "cniVersion": "0.3.1", + "name": "mynet", + "type": "ipvlan", + "master": "foo0", + "ipam": { + "range": "192.168.2.230/24", + "configuration_path": "/tmp/whereabouts.conf", + "type": "whereabouts", + "enable_overlapping_ranges": false + } + }` +} From d8809009be45c8ef8436e41185cc38b91f104784 Mon Sep 17 00:00:00 2001 From: Philipp Riederer Date: Thu, 4 Aug 2022 11:18:32 +0200 Subject: [PATCH 2/2] fix overwriting of OverlappingRanges by mergo --- pkg/config/config.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/config/config.go b/pkg/config/config.go index 47c83490f..ac0223814 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -60,9 +60,11 @@ func LoadIPAMConfig(bytes []byte, envArgs string, extraConfigPaths ...string) (* // Now let's try to merge the configurations... // NB: Don't try to do any initialization before this point or it won't account for merged flat file. + var OverlappingRanges bool = n.IPAM.OverlappingRanges if err := mergo.Merge(&n, flatipam); err != nil { logging.Errorf("Merge error with flat file: %s", err) } + n.IPAM.OverlappingRanges = OverlappingRanges // Logging if n.IPAM.LogFile != "" {