Skip to content

Commit

Permalink
Test the non-working enable_overlapping_ranges-config
Browse files Browse the repository at this point in the history
  • Loading branch information
toelke committed Aug 19, 2022
1 parent 39b1030 commit b476e17
Showing 1 changed file with 67 additions and 0 deletions.
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())

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
}
}`
}

0 comments on commit b476e17

Please sign in to comment.