forked from github/multus-cni
Support CNI RuntimeConfig for portmap/bandwidth/ip/mac
This changes introduce CNI RuntimeConfig for portmap, bandwidth, ip and mac for latest specification. IP and Mac is previously applied through CNI_ARGS, but it is changed to RuntimeConfig for now.
This commit is contained in:
committed by
Doug Smith
parent
0a2f7b18d3
commit
adec211ae1
@@ -383,17 +383,20 @@ var _ = Describe("config operations", func() {
|
||||
k8sArgs := &K8sArgs{K8S_POD_NAME: "dummy", K8S_POD_NAMESPACE: "namespacedummy", K8S_POD_INFRA_CONTAINER_ID: "123456789"}
|
||||
|
||||
rc := &RuntimeConfig{}
|
||||
tempportmap := make([]PortMapEntry, 2)
|
||||
rc.PortMaps = tempportmap
|
||||
rc.PortMaps = make([]*PortMapEntry, 2)
|
||||
|
||||
rc.PortMaps[0].HostPort = 0
|
||||
rc.PortMaps[0].ContainerPort = 1
|
||||
rc.PortMaps[0].Protocol = "sampleProtocol"
|
||||
rc.PortMaps[0].HostIP = "sampleHostIP"
|
||||
rc.PortMaps[1].HostPort = 1
|
||||
rc.PortMaps[1].ContainerPort = 2
|
||||
rc.PortMaps[1].Protocol = "anotherSampleProtocol"
|
||||
rc.PortMaps[1].HostIP = "anotherSampleHostIP"
|
||||
rc.PortMaps[0] = &PortMapEntry{
|
||||
HostPort: 0,
|
||||
ContainerPort: 1,
|
||||
Protocol: "sampleProtocol",
|
||||
HostIP: "sampleHostIP",
|
||||
}
|
||||
rc.PortMaps[1] = &PortMapEntry{
|
||||
HostPort: 1,
|
||||
ContainerPort: 2,
|
||||
Protocol: "anotherSampleProtocol",
|
||||
HostIP: "anotherSampleHostIP",
|
||||
}
|
||||
|
||||
rt := CreateCNIRuntimeConf(args, k8sArgs, "", rc)
|
||||
fmt.Println("rt.ContainerID: ", rt.ContainerID)
|
||||
@@ -467,4 +470,123 @@ var _ = Describe("config operations", func() {
|
||||
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
|
||||
It("verify the network selection elements goes into delegateconf", func() {
|
||||
cniConfig := `{
|
||||
"name": "weave1",
|
||||
"cniVersion": "0.2.0",
|
||||
"type": "weave-net"
|
||||
}`
|
||||
bandwidthEntry1 := &BandwidthEntry{
|
||||
IngressRate: 100,
|
||||
IngressBurst: 200,
|
||||
EgressRate: 100,
|
||||
EgressBurst: 200,
|
||||
}
|
||||
|
||||
portMapEntry1 := &PortMapEntry{
|
||||
HostPort: 8080,
|
||||
ContainerPort: 80,
|
||||
Protocol: "tcp",
|
||||
HostIP: "10.0.0.1",
|
||||
}
|
||||
|
||||
networkSelection := &NetworkSelectionElement{
|
||||
Name: "testname",
|
||||
InterfaceRequest: "testIF1",
|
||||
MacRequest: "c2:11:22:33:44:66",
|
||||
IPRequest: []string{"10.0.0.1/24"},
|
||||
BandwidthRequest: bandwidthEntry1,
|
||||
PortMappingsRequest: []*PortMapEntry{portMapEntry1},
|
||||
}
|
||||
|
||||
delegateConf, err := LoadDelegateNetConf([]byte(cniConfig), networkSelection, "")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(delegateConf.IfnameRequest).To(Equal(networkSelection.InterfaceRequest))
|
||||
Expect(delegateConf.MacRequest).To(Equal(networkSelection.MacRequest))
|
||||
Expect(delegateConf.IPRequest).To(Equal(networkSelection.IPRequest))
|
||||
Expect(delegateConf.BandwidthRequest).To(Equal(networkSelection.BandwidthRequest))
|
||||
Expect(delegateConf.PortMappingsRequest).To(Equal(networkSelection.PortMappingsRequest))
|
||||
})
|
||||
|
||||
It("test MergeCNIRuntimeConfig with masterPlugin", func() {
|
||||
conf := `{
|
||||
"name": "node-cni-network",
|
||||
"type": "multus",
|
||||
"kubeconfig": "/etc/kubernetes/node-kubeconfig.yaml",
|
||||
"delegates": [{
|
||||
"type": "weave-net"
|
||||
}],
|
||||
"runtimeConfig": {
|
||||
"portMappings": [
|
||||
{"hostPort": 8080, "containerPort": 80, "protocol": "tcp"}
|
||||
]
|
||||
}
|
||||
}`
|
||||
bandwidthEntry1 := &BandwidthEntry{
|
||||
IngressRate: 100,
|
||||
IngressBurst: 200,
|
||||
EgressRate: 100,
|
||||
EgressBurst: 200,
|
||||
}
|
||||
portMapEntry1 := &PortMapEntry{
|
||||
HostPort: 8080,
|
||||
ContainerPort: 80,
|
||||
Protocol: "tcp",
|
||||
HostIP: "10.0.0.1",
|
||||
}
|
||||
|
||||
networkSelection := &NetworkSelectionElement{
|
||||
Name: "testname",
|
||||
InterfaceRequest: "testIF1",
|
||||
MacRequest: "c2:11:22:33:44:66",
|
||||
IPRequest: []string{"10.0.0.1/24"},
|
||||
BandwidthRequest: bandwidthEntry1,
|
||||
PortMappingsRequest: []*PortMapEntry{portMapEntry1},
|
||||
}
|
||||
delegate, err := LoadDelegateNetConf([]byte(conf), networkSelection, "")
|
||||
delegate.MasterPlugin = true
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
runtimeConf := MergeCNIRuntimeConfig(&RuntimeConfig{}, delegate)
|
||||
Expect(runtimeConf.PortMaps).To(BeNil())
|
||||
Expect(runtimeConf.Bandwidth).To(BeNil())
|
||||
})
|
||||
|
||||
It("test MergeCNIRuntimeConfig with delegate plugin", func() {
|
||||
conf := `{
|
||||
"name": "weave1",
|
||||
"cniVersion": "0.2.0",
|
||||
"type": "weave-net"
|
||||
}`
|
||||
bandwidthEntry1 := &BandwidthEntry{
|
||||
IngressRate: 100,
|
||||
IngressBurst: 200,
|
||||
EgressRate: 100,
|
||||
EgressBurst: 200,
|
||||
}
|
||||
portMapEntry1 := &PortMapEntry{
|
||||
HostPort: 8080,
|
||||
ContainerPort: 80,
|
||||
Protocol: "tcp",
|
||||
HostIP: "10.0.0.1",
|
||||
}
|
||||
|
||||
networkSelection := &NetworkSelectionElement{
|
||||
Name: "testname",
|
||||
InterfaceRequest: "testIF1",
|
||||
MacRequest: "c2:11:22:33:44:66",
|
||||
IPRequest: []string{"10.0.0.1/24"},
|
||||
BandwidthRequest: bandwidthEntry1,
|
||||
PortMappingsRequest: []*PortMapEntry{portMapEntry1},
|
||||
}
|
||||
delegate, err := LoadDelegateNetConf([]byte(conf), networkSelection, "")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
runtimeConf := MergeCNIRuntimeConfig(&RuntimeConfig{}, delegate)
|
||||
Expect(runtimeConf.PortMaps).NotTo(BeNil())
|
||||
Expect(len(runtimeConf.PortMaps)).To(BeEquivalentTo(1))
|
||||
Expect(runtimeConf.PortMaps[0]).To(Equal(portMapEntry1))
|
||||
Expect(runtimeConf.Bandwidth).To(Equal(bandwidthEntry1))
|
||||
Expect(len(runtimeConf.IPs)).To(BeEquivalentTo(1))
|
||||
Expect(runtimeConf.Mac).To(Equal("c2:11:22:33:44:66"))
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user