mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-07-31 15:43:45 +00:00
Support IPs, MAC and cni-args in delegate API
This commit is contained in:
parent
1aac2431b8
commit
6f90a0f075
@ -73,7 +73,7 @@ func GetAPIEndpoint(endpoint string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateDelegateRequest creates Request for delegate API request
|
// CreateDelegateRequest creates Request for delegate API request
|
||||||
func CreateDelegateRequest(cniCommand, cniContainerID, cniNetNS, cniIFName, podNamespace, podName, podUID string, cniConfig []byte) *Request {
|
func CreateDelegateRequest(cniCommand, cniContainerID, cniNetNS, cniIFName, podNamespace, podName, podUID string, cniConfig []byte, interfaceAttributes *DelegateInterfaceAttributes) *Request {
|
||||||
return &Request{
|
return &Request{
|
||||||
Env: map[string]string{
|
Env: map[string]string{
|
||||||
"CNI_COMMAND": strings.ToUpper(cniCommand),
|
"CNI_COMMAND": strings.ToUpper(cniCommand),
|
||||||
@ -82,6 +82,7 @@ func CreateDelegateRequest(cniCommand, cniContainerID, cniNetNS, cniIFName, podN
|
|||||||
"CNI_IFNAME": cniIFName,
|
"CNI_IFNAME": cniIFName,
|
||||||
"CNI_ARGS": fmt.Sprintf("K8S_POD_NAMESPACE=%s;K8S_POD_NAME=%s;K8S_POD_UID=%s", podNamespace, podName, podUID),
|
"CNI_ARGS": fmt.Sprintf("K8S_POD_NAMESPACE=%s;K8S_POD_NAME=%s;K8S_POD_UID=%s", podNamespace, podName, podUID),
|
||||||
},
|
},
|
||||||
Config: cniConfig,
|
Config: cniConfig,
|
||||||
|
InterfaceAttributes: interfaceAttributes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,20 @@ type Request struct {
|
|||||||
Env map[string]string `json:"env,omitempty"`
|
Env map[string]string `json:"env,omitempty"`
|
||||||
// CNI configuration passed via stdin to the CNI plugin
|
// CNI configuration passed via stdin to the CNI plugin
|
||||||
Config []byte `json:"config,omitempty"`
|
Config []byte `json:"config,omitempty"`
|
||||||
|
// Annotation for Delegate request
|
||||||
|
InterfaceAttributes *DelegateInterfaceAttributes `json:"interfaceAttributes,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DelegateInterfaceAttributes annotates delegate request for additional config
|
||||||
|
type DelegateInterfaceAttributes struct {
|
||||||
|
// IPRequest contains an optional requested IP address for this network
|
||||||
|
// attachment
|
||||||
|
IPRequest []string `json:"ips,omitempty"`
|
||||||
|
// MacRequest contains an optional requested MAC address for this
|
||||||
|
// network attachment
|
||||||
|
MacRequest string `json:"mac,omitempty"`
|
||||||
|
// CNIArgs contains additional CNI arguments for the network interface
|
||||||
|
CNIArgs *map[string]interface{} `json:"cni-args"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response represents the response (computed in the CNI server) for
|
// Response represents the response (computed in the CNI server) for
|
||||||
|
@ -86,7 +86,7 @@ func (s *Server) HandleCNIRequest(cmd string, k8sArgs *types.K8sArgs, cniCmdArgs
|
|||||||
|
|
||||||
// HandleDelegateRequest is the CNI server handler function; it is invoked whenever
|
// HandleDelegateRequest is the CNI server handler function; it is invoked whenever
|
||||||
// a CNI request is processed as delegate CNI request.
|
// a CNI request is processed as delegate CNI request.
|
||||||
func (s *Server) HandleDelegateRequest(cmd string, k8sArgs *types.K8sArgs, cniCmdArgs *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) ([]byte, error) {
|
func (s *Server) HandleDelegateRequest(cmd string, k8sArgs *types.K8sArgs, cniCmdArgs *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo, interfaceAttributes *api.DelegateInterfaceAttributes) ([]byte, error) {
|
||||||
var result []byte
|
var result []byte
|
||||||
var err error
|
var err error
|
||||||
var multusConfByte []byte
|
var multusConfByte []byte
|
||||||
@ -100,7 +100,7 @@ func (s *Server) HandleDelegateRequest(cmd string, k8sArgs *types.K8sArgs, cniCm
|
|||||||
logging.Verbosef("%s starting delegate request %+v", cmd, cniCmdArgs)
|
logging.Verbosef("%s starting delegate request %+v", cmd, cniCmdArgs)
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case "ADD":
|
case "ADD":
|
||||||
result, err = cmdDelegateAdd(cniCmdArgs, k8sArgs, exec, kubeClient, multusConfig)
|
result, err = cmdDelegateAdd(cniCmdArgs, k8sArgs, exec, kubeClient, multusConfig, interfaceAttributes)
|
||||||
case "DEL":
|
case "DEL":
|
||||||
err = cmdDelegateDel(cniCmdArgs, k8sArgs, exec, kubeClient, multusConfig)
|
err = cmdDelegateDel(cniCmdArgs, k8sArgs, exec, kubeClient, multusConfig)
|
||||||
case "CHECK":
|
case "CHECK":
|
||||||
@ -265,7 +265,7 @@ func (s *Server) handleDelegateRequest(r *http.Request) ([]byte, error) {
|
|||||||
return nil, fmt.Errorf("could not extract the kubernetes runtime args: %w", err)
|
return nil, fmt.Errorf("could not extract the kubernetes runtime args: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := s.HandleDelegateRequest(cmdType, k8sArgs, cniCmdArgs, s.exec, s.kubeclient)
|
result, err := s.HandleDelegateRequest(cmdType, k8sArgs, cniCmdArgs, s.exec, s.kubeclient, cr.InterfaceAttributes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Prefix error with request information for easier debugging
|
// Prefix error with request information for easier debugging
|
||||||
return nil, fmt.Errorf("%+v %v", cniCmdArgs, err)
|
return nil, fmt.Errorf("%+v %v", cniCmdArgs, err)
|
||||||
@ -435,7 +435,7 @@ func serializeResult(result cnitypes.Result) ([]byte, error) {
|
|||||||
return responseBytes, nil
|
return responseBytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdDelegateAdd(cmdArgs *skel.CmdArgs, k8sArgs *types.K8sArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo, multusConfig *types.NetConf) ([]byte, error) {
|
func cmdDelegateAdd(cmdArgs *skel.CmdArgs, k8sArgs *types.K8sArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo, multusConfig *types.NetConf, interfaceAttributes *api.DelegateInterfaceAttributes) ([]byte, error) {
|
||||||
namespace := string(k8sArgs.K8S_POD_NAMESPACE)
|
namespace := string(k8sArgs.K8S_POD_NAMESPACE)
|
||||||
podName := string(k8sArgs.K8S_POD_NAME)
|
podName := string(k8sArgs.K8S_POD_NAME)
|
||||||
if namespace == "" || podName == "" {
|
if namespace == "" || podName == "" {
|
||||||
@ -446,7 +446,22 @@ func cmdDelegateAdd(cmdArgs *skel.CmdArgs, k8sArgs *types.K8sArgs, exec invoke.E
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
delegateCNIConf, err := types.LoadDelegateNetConf(cmdArgs.StdinData, nil, "", "")
|
// copy deleate annotation into network selection element
|
||||||
|
var selectionElement *types.NetworkSelectionElement
|
||||||
|
if interfaceAttributes != nil {
|
||||||
|
selectionElement = &types.NetworkSelectionElement{}
|
||||||
|
if interfaceAttributes.MacRequest != "" {
|
||||||
|
selectionElement.MacRequest = interfaceAttributes.MacRequest
|
||||||
|
}
|
||||||
|
if interfaceAttributes.IPRequest != nil {
|
||||||
|
selectionElement.IPRequest = interfaceAttributes.IPRequest
|
||||||
|
}
|
||||||
|
if interfaceAttributes.CNIArgs != nil {
|
||||||
|
selectionElement.CNIArgs = interfaceAttributes.CNIArgs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delegateCNIConf, err := types.LoadDelegateNetConf(cmdArgs.StdinData, selectionElement, "", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user