Skip to content

Commit

Permalink
port bindings and mac address config
Browse files Browse the repository at this point in the history
  • Loading branch information
steiler committed Jun 2, 2021
1 parent a29ede6 commit d33387a
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions runtime/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,39 @@ func (c *ContainerdRuntime) CreateContainer(ctx context.Context, node *types.Nod
return err
}

var rc libcni.RuntimeConf
rc.ContainerID = node.LongName
rc.IfName = "eth0"
rc.NetNS = node.NSPath
cnirc := &libcni.RuntimeConf{
ContainerID: node.ShortName,
IfName: "eth0",
NetNS: node.NSPath,
CapabilityArgs: make(map[string]interface{}),
//"portMappings": []portMapping{
// {HostPort: 8080, ContainerPort: 80, Protocol: "tcp"},
//},
}

// set mac if defined in node
if node.MacAddress != "" {
cnirc.CapabilityArgs["mac"] = node.MacAddress
}

portmappings := []portMapping{}

for contdatasl, hostdata := range node.PortBindings {
//fmt.Printf("%+v", hostdata)
//fmt.Printf("%+v", contdatasl)
for _, x := range hostdata {
hostport, err := strconv.Atoi(x.HostPort)
if err != nil {
return err
}
portmappings = append(portmappings, portMapping{HostPort: hostport, ContainerPort: contdatasl.Int(), Protocol: contdatasl.Proto()})
}
}
if len(portmappings) > 0 {
cnirc.CapabilityArgs["portMappings"] = portmappings
}

res, err := cnic.AddNetworkList(ctx, cncl, &rc)
res, err := cnic.AddNetworkList(ctx, cncl, cnirc)
if err != nil {
return err
}
Expand All @@ -183,6 +210,13 @@ func (c *ContainerdRuntime) CreateContainer(ctx context.Context, node *types.Nod

}

type portMapping struct {
HostPort int `json:"hostPort"`
HostIP string `json:"hostIP,omitempty"`
ContainerPort int `json:"containerPort"`
Protocol string `json:"protocol"`
}

func WithSysctls(sysctls map[string]string) oci.SpecOpts {
return func(ctx context.Context, client oci.Client, c *containers.Container, s *specs.Spec) error {
if s.Linux == nil {
Expand Down

0 comments on commit d33387a

Please sign in to comment.