host-local: support custom IPs allocation through runtime configuration

Signed-off-by: Bruce Ma <brucema19901024@gmail.com>
This commit is contained in:
Bruce Ma
2021-03-10 17:41:30 +08:00
parent 7da1c84919
commit 028fc2f219
2 changed files with 39 additions and 3 deletions

View File

@ -379,4 +379,29 @@ var _ = Describe("IPAM config", func() {
_, _, err := LoadIPAMConfig([]byte(input), "")
Expect(err).NotTo(HaveOccurred())
})
It("Should parse custom IPs from runtime configuration", func() {
input := `{
"cniVersion": "0.3.1",
"name": "mynet",
"type": "ipvlan",
"master": "foo0",
"runtimeConfig": {
"ips": ["192.168.0.1", "192.168.0.5/24", "2001:db8::1/64"]
},
"ipam": {
"type": "host-local",
"subnet": "10.1.2.0/24"
}
}`
conf, version, err := LoadIPAMConfig([]byte(input), "")
Expect(err).NotTo(HaveOccurred())
Expect(version).Should(Equal("0.3.1"))
Expect(conf.IPArgs).To(Equal([]net.IP{
net.IPv4(192, 168, 0, 1).To4(),
net.IPv4(192, 168, 0, 5).To4(),
net.ParseIP("2001:db8::1"),
}))
})
})