Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix overwriting of OverlappingRanges by mergo #257

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
67 changes: 67 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to me we're leaking this file after the execution, but I've noticed that also happens for other tests.

I'll handle that in a follow-up.


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() {
Expand Down Expand Up @@ -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
}
}`
}