mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-02 01:19:31 +00:00
[dependency] Add portmap capability support (Other changes were dependent on changes made in this commit)
Signed-off-by: Mathieu Rohon <mathieu.rohon@orange.com>
This commit is contained in:
36
examples/multus-ptp-portmap.conf
Normal file
36
examples/multus-ptp-portmap.conf
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"name": "multus-cni-network",
|
||||||
|
"type": "multus"
|
||||||
|
"capabilities": {
|
||||||
|
"portMappings": true
|
||||||
|
},
|
||||||
|
"delegates": [
|
||||||
|
{
|
||||||
|
"cniVersion": "0.3.1",
|
||||||
|
"name": "ptp-tuning-conflist",
|
||||||
|
"plugins": [
|
||||||
|
{
|
||||||
|
"dns": {
|
||||||
|
"nameservers": [
|
||||||
|
"172.16.1.1"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"ipMasq": true,
|
||||||
|
"ipam": {
|
||||||
|
"subnet": "172.16.0.0/24",
|
||||||
|
"type": "host-local"
|
||||||
|
},
|
||||||
|
"mtu": 512,
|
||||||
|
"type": "ptp"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"capabilities": {
|
||||||
|
"portMappings": true
|
||||||
|
},
|
||||||
|
"externalSetMarkChain": "KUBE-MARK-MASQ",
|
||||||
|
"type": "portmap"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
@@ -122,11 +122,12 @@ func validateIfName(nsname string, ifname string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func conflistAdd(rt *libcni.RuntimeConf, rawnetconflist []byte, binDir string) (cnitypes.Result, error) {
|
func conflistAdd(rt *libcni.RuntimeConf, rawnetconflist []byte, binDir string, exec invoke.Exec) (cnitypes.Result, error) {
|
||||||
logging.Debugf("conflistAdd: %v, %s, %s", rt, string(rawnetconflist), binDir)
|
logging.Debugf("conflistAdd: %v, %s, %s", rt, string(rawnetconflist), binDir)
|
||||||
// In part, adapted from K8s pkg/kubelet/dockershim/network/cni/cni.go
|
// In part, adapted from K8s pkg/kubelet/dockershim/network/cni/cni.go
|
||||||
binDirs := []string{binDir}
|
binDirs := filepath.SplitList(os.Getenv("CNI_PATH"))
|
||||||
cniNet := libcni.CNIConfig{Path: binDirs}
|
binDirs = append(binDirs, binDir)
|
||||||
|
cniNet := libcni.NewCNIConfig(binDirs, exec)
|
||||||
|
|
||||||
confList, err := libcni.ConfListFromBytes(rawnetconflist)
|
confList, err := libcni.ConfListFromBytes(rawnetconflist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -208,7 +209,7 @@ func delegateAdd(exec invoke.Exec, ifName string, delegate *types.DelegateNetCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
if delegate.ConfListPlugin != false {
|
if delegate.ConfListPlugin != false {
|
||||||
result, err := conflistAdd(rt, delegate.Bytes, binDir)
|
result, err := conflistAdd(rt, delegate.Bytes, binDir, exec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, logging.Errorf("Multus: error in invoke Conflist add - %q: %v", delegate.ConfList.Name, err)
|
return nil, logging.Errorf("Multus: error in invoke Conflist add - %q: %v", delegate.ConfList.Name, err)
|
||||||
}
|
}
|
||||||
@@ -435,7 +436,7 @@ func cmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient k8s.KubeClient) err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rt, _ := types.LoadCNIRuntimeConf(args, k8sArgs, "")
|
rt, _ := types.LoadCNIRuntimeConf(args, k8sArgs, "", in.RuntimeConfig)
|
||||||
return delPlugins(exec, args.IfName, in.Delegates, len(in.Delegates)-1, rt, in.BinDir)
|
return delPlugins(exec, args.IfName, in.Delegates, len(in.Delegates)-1, rt, in.BinDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -93,9 +93,9 @@ func LoadDelegateNetConf(bytes []byte, net *NetworkSelectionElement, deviceID st
|
|||||||
return delegateConf, nil
|
return delegateConf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadCNIRuntimeConf(args *skel.CmdArgs, k8sArgs *K8sArgs, ifName string) (*libcni.RuntimeConf, error) {
|
func LoadCNIRuntimeConf(args *skel.CmdArgs, k8sArgs *K8sArgs, ifName string, rc *RuntimeConfig) (*libcni.RuntimeConf, error) {
|
||||||
|
|
||||||
logging.Debugf("LoadCNIRuntimeConf: %v, %v, %s", args, k8sArgs, ifName)
|
logging.Debugf("LoadCNIRuntimeConf: %v, %v, %s, %v", args, k8sArgs, ifName, rc)
|
||||||
// In part, adapted from K8s pkg/kubelet/dockershim/network/cni/cni.go#buildCNIRuntimeConf
|
// In part, adapted from K8s pkg/kubelet/dockershim/network/cni/cni.go#buildCNIRuntimeConf
|
||||||
// Todo
|
// Todo
|
||||||
// ingress, egress and bandwidth capability features as same as kubelet.
|
// ingress, egress and bandwidth capability features as same as kubelet.
|
||||||
@@ -110,6 +110,12 @@ func LoadCNIRuntimeConf(args *skel.CmdArgs, k8sArgs *K8sArgs, ifName string) (*l
|
|||||||
{"K8S_POD_INFRA_CONTAINER_ID", string(k8sArgs.K8S_POD_INFRA_CONTAINER_ID)},
|
{"K8S_POD_INFRA_CONTAINER_ID", string(k8sArgs.K8S_POD_INFRA_CONTAINER_ID)},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rc != nil {
|
||||||
|
rt.CapabilityArgs = map[string]interface{}{
|
||||||
|
"portMappings": rc.PortMaps,
|
||||||
|
}
|
||||||
|
}
|
||||||
return rt, nil
|
return rt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,13 +35,20 @@ var _ = Describe("config operations", func() {
|
|||||||
"kubeconfig": "/etc/kubernetes/node-kubeconfig.yaml",
|
"kubeconfig": "/etc/kubernetes/node-kubeconfig.yaml",
|
||||||
"delegates": [{
|
"delegates": [{
|
||||||
"type": "weave-net"
|
"type": "weave-net"
|
||||||
}]
|
}],
|
||||||
|
"runtimeConfig": {
|
||||||
|
"portMappings": [
|
||||||
|
{"hostPort": 8080, "containerPort": 80, "protocol": "tcp"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
}`
|
}`
|
||||||
netConf, err := LoadNetConf([]byte(conf))
|
netConf, err := LoadNetConf([]byte(conf))
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(netConf.Delegates)).To(Equal(1))
|
Expect(len(netConf.Delegates)).To(Equal(1))
|
||||||
Expect(netConf.Delegates[0].Conf.Type).To(Equal("weave-net"))
|
Expect(netConf.Delegates[0].Conf.Type).To(Equal("weave-net"))
|
||||||
Expect(netConf.Delegates[0].MasterPlugin).To(BeTrue())
|
Expect(netConf.Delegates[0].MasterPlugin).To(BeTrue())
|
||||||
|
Expect(len(netConf.RuntimeConfig.PortMaps)).To(Equal(1))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("succeeds if only delegates are set", func() {
|
It("succeeds if only delegates are set", func() {
|
||||||
|
@@ -51,6 +51,17 @@ type NetConf struct {
|
|||||||
NamespaceIsolation bool `json:"namespaceIsolation"`
|
NamespaceIsolation bool `json:"namespaceIsolation"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RuntimeConfig struct {
|
||||||
|
PortMaps []PortMapEntry `json:"portMappings,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PortMapEntry struct {
|
||||||
|
HostPort int `json:"hostPort"`
|
||||||
|
ContainerPort int `json:"containerPort"`
|
||||||
|
Protocol string `json:"protocol"`
|
||||||
|
HostIP string `json:"hostIP,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type NetworkStatus struct {
|
type NetworkStatus struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Interface string `json:"interface,omitempty"`
|
Interface string `json:"interface,omitempty"`
|
||||||
|
Reference in New Issue
Block a user