Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portmapping support related modifications #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions genie/genie-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func (gc *GenieController) delegateAddNetwork(pluginInfo *utils.PluginInfo, cniA
if err := os.Unsetenv("CNI_ARGS"); err != nil {
fmt.Fprintf(os.Stderr, "CNI Genie Error while unsetting env variable CNI_Args: %v\n", err)
}
rtConf, err := runtimeConf(cniArgs, pluginInfo.IfName, pluginInfo.OptionalArgs)
rtConf, err := runtimeConf(cniArgs, pluginInfo.IfName, pluginInfo.OptionalArgs, pluginInfo.RuntimeConfig)
if err != nil {
return nil, fmt.Errorf("Error generating runtime conf: %v", err)
}
Expand Down Expand Up @@ -411,7 +411,7 @@ func (gc *GenieController) deleteNetwork(pluginElements []*utils.PluginInfo, cni
}

func (gc *GenieController) delegateDelNetwork(pluginInfo *utils.PluginInfo, cniArgs *utils.CNIArgs) error {
rtConf, err := runtimeConf(cniArgs, pluginInfo.IfName, pluginInfo.OptionalArgs)
rtConf, err := runtimeConf(cniArgs, pluginInfo.IfName, pluginInfo.OptionalArgs, pluginInfo.RuntimeConfig)
if err != nil {
return fmt.Errorf("CNI Genie couldn't convert cniArgs to RuntimeConf: %v", err)
}
Expand Down Expand Up @@ -794,7 +794,7 @@ func (gc *GenieController) getK8sPodAnnotations(k8sArgs *utils.K8sArgs) (map[str
return pod.Annotations, nil
}

func runtimeConf(cniArgs *utils.CNIArgs, iface string, optionalArgs map[string]string) (*libcni.RuntimeConf, error) {
func runtimeConf(cniArgs *utils.CNIArgs, iface string, optionalArgs map[string]string, runtimeConfig *utils.RuntimeConfig) (*libcni.RuntimeConf, error) {
k8sArgs, err := loadArgs(cniArgs)
if err != nil {
return nil, err
Expand All @@ -815,11 +815,20 @@ func runtimeConf(cniArgs *utils.CNIArgs, iface string, optionalArgs map[string]s

args = append(args, setOptionalArgs(optionalArgs)...)

return &libcni.RuntimeConf{
rt := &libcni.RuntimeConf{
ContainerID: cniArgs.ContainerID,
NetNS: cniArgs.Netns,
IfName: iface,
Args: args}, nil
Args: args}

if runtimeConfig != nil {
rt.CapabilityArgs = map[string]interface{}{
"portMappings": runtimeConfig.PortMapEntries,
}
fmt.Fprintf(os.Stderr, "CNI Genie runtime config = %v\n", rt.CapabilityArgs)
}

return rt, nil
}

func setOptionalArgs(optionalParam map[string]string) [][2]string {
Expand All @@ -830,6 +839,7 @@ func setOptionalArgs(optionalParam map[string]string) [][2]string {
if optionalParam["mac"] != "" {
args = append(args, [2]string{"MAC", optionalParam["mac"]})
}

return args
}

Expand Down
3 changes: 3 additions & 0 deletions genie/genie-netattachdef-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (gc *GenieController) parseNetAttachDefAnnot(annot string, k8sArgs *utils.K
return nil, err
}

pluginInfo.RuntimeConfig = netElem.RuntimeConfig
fmt.Fprintf(os.Stderr, "CNI Genie runtime config : %+v\n", pluginInfo.RuntimeConfig)

pluginInfo.OptionalArgs = make(map[string]string, 0)

if len(netElem.IPs) > 0 {
Expand Down
7 changes: 6 additions & 1 deletion networkcrd/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package networkcrd

import (
"github.com/cni-genie/CNI-Genie/utils"
"github.com/containernetworking/cni/pkg/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -51,6 +52,10 @@ type NetworkSelectionElement struct {
// to the container by this network attachment
// +optional
Interface string `json:"interface,omitempty"`

//Runtime configuration to be passed to CNI
// +optional
RuntimeConfig *utils.RuntimeConfig `json:"runtimeConfig,omitempty"`
}

// NetworkStatus describes the status to be updated in pod
Expand All @@ -61,4 +66,4 @@ type NetworkStatus struct {
Mac string `json:"mac,omitempty"`
Default bool `json:"default,omitempty"`
DNS types.DNS `json:"dns,omitempty"`
}
}
13 changes: 13 additions & 0 deletions utils/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ type PhysicalNetworkList struct {

type ValidateResult func(types.Result, interface{}) error

// RuntimeConfig specifies CNI RuntimeConfig
type RuntimeConfig struct {
PortMapEntries []PortMapping `json:"portMappings,omitempty"`
}

// PortMapping for CNI
type PortMapping struct {
HostPort int `json:"hostPort"`
ContainerPort int `json:"containerPort"`
Protocol string `json:"protocol"`
}

// PluginInfo describes the details of plugin info for user pod
type PluginInfo struct {
PluginName string
Expand All @@ -163,6 +175,7 @@ type PluginInfo struct {
Refer_nic string
Config *libcni.NetworkConfigList
OptionalArgs map[string]string
RuntimeConfig *RuntimeConfig
ValidationParams interface{}
ValidateRes ValidateResult
}