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

[Task] Update pod route #261

Merged
merged 9 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from 8 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
32 changes: 18 additions & 14 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,6 @@ Response Data:
100,
200
],
"routes":[
{
"dstCIDR":"224.0.0.0/4",
"gateway":"0.0.0.0"
}
],
"bridgeName": "",
"nodes": [
{
Expand Down Expand Up @@ -386,12 +380,6 @@ Response Data:
100,
200
],
"routes":[
{
"dstCIDR":"224.0.0.0/4",
"gateway":"0.0.0.0"
}
],
"bridgeName": "ovsbr0",
"nodes": [
{
Expand Down Expand Up @@ -632,6 +620,11 @@ For each Pod, we have fileds need to handle.
- vlanTag: the vlan tag for `ifName` interface.
- ipADdress: the IPv4 address of the `ifName` interface.
- netmask: the IPv4 netmask of the `ifName` interface.
- routesGw: a array of route with gateway (Optional)
- dstCIDR: destination network cidr for add IP routing table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dstCIDR(required):

- gateway: the gateway of the interface subnet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gateway(required):

- routeIntf: a array of route without gateway (Optional)
- dstCIDR: destination network cidr for add IP routing table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dstCIDR(required):

7. capability: the power of the container, if it's ture, it will get almost all capability and act as a privileged=true.
8. restartPolicy: the attribute how the pod restart is container, it should be a string and only valid for those following strings.
- Always,OnFailure,Never
Expand Down Expand Up @@ -659,8 +652,19 @@ Request Data:
"ifName":"eth12",
"vlanTag":0,
"ipAddress":"1.2.3.4",
"netmask":"255.255.255.0"
}],
"netmask":"255.255.255.0",
"routesGw": [
{
"dstCIDR":"192.168.2.0/24",
"gateway":"192.168.2.254"
}
],
"routeIntf": [
{
"dstCIDR":"224.0.0.0/4",
}
]
},
"volumes":[
],
"capability":true,
Expand Down
20 changes: 13 additions & 7 deletions src/entity/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,27 @@ type Container struct {
Command []string `bson:"command" json:"command" validate:"required,dive,required"`
}

// PodRoute is the structure for add IP routing table
type PodRoute struct {
// PodRouteGw is the structure for add IP routing table with gateway
type PodRouteGw struct {
DstCIDR string `bson:"dstCIDR" json:"dstCIDR" validate:"required,cidrv4"`
Gateway string `bson:"gateway" json:"gateway" validate:"required,ipv4"`
}

// PodRouteIntf is the structure for add IP routing table via interface
type PodRouteIntf struct {
DstCIDR string `bson:"dstCIDR" json:"dstCIDR" validate:"required,cidrv4"`
Gateway string `bson:"gateway" json:"gateway" validate:"omitempty,ipv4"`
}

// PodNetwork is the structure for pod network info
type PodNetwork struct {
Name string `bson:"name" json:"name" validate:"required"`
IfName string `bson:"ifName" json:"ifName" validate:"required"`
// can not validate nil
VlanTag *int32 `bson:"vlanTag" json:"vlanTag" validate:"-"`
IPAddress string `bson:"ipAddress" json:"ipAddress" validate:"required,ipv4"`
Netmask string `bson:"netmask" json:"netmask" validate:"required,ipv4"`
Routes []PodRoute `bson:"routes,omitempty" json:"routes" validate:"required,dive,required"`
VlanTag *int32 `bson:"vlanTag" json:"vlanTag" validate:"-"`
IPAddress string `bson:"ipAddress" json:"ipAddress" validate:"required,ipv4"`
Netmask string `bson:"netmask" json:"netmask" validate:"required,ipv4"`
RoutesGw []PodRouteGw `bson:"routesGw,omitempty" json:"routesGw" validate:"required,dive,required"`
RoutesIntf []PodRouteIntf `bson:"routesIntf,omitempty" json:"routesIntf" validate:"required,dive,required"`

// It's from the entity.Network entity
BridgeName string `bson:"bridgeName" json:"bridgeName" validate:"-"`
Expand Down
16 changes: 9 additions & 7 deletions src/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ func generateClientCommand(network entity.PodNetwork) (command []string) {
if network.VlanTag != nil {
command = append(command, "-v="+strconv.Itoa((int)(*network.VlanTag)))
}
if len(network.Routes) != 0 {
// Support one command with one add route in first version
if network.Routes[0].Gateway != "" {
command = append(command, "--net="+network.Routes[0].DstCIDR, "-g="+network.Routes[0].Gateway)
} else {
command = append(command, "--net="+network.Routes[0].DstCIDR)
if len(network.RoutesGw) != 0 {
for _, netroute := range network.RoutesGw {
command = append(command, "--route-gw="+netroute.DstCIDR+","+netroute.Gateway)
}
}
if len(network.RoutesIntf) != 0 {
for _, netroute := range network.RoutesIntf {
command = append(command, "--route-intf="+netroute.DstCIDR)
}
}
return
Expand All @@ -123,7 +125,7 @@ func generateInitContainer(networks []entity.PodNetwork) ([]corev1.Container, er
for i, v := range networks {
containers = append(containers, corev1.Container{
Name: fmt.Sprintf("init-network-client-%d", i),
Image: "sdnvortex/network-controller:v0.4.0",
Image: "sdnvortex/network-controller:v0.4.3",
Command: []string{"/go/bin/client"},
Args: generateClientCommand(v),
Env: []corev1.EnvVar{
Expand Down
9 changes: 6 additions & 3 deletions tests/01-multiple-interface/pod.info
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,25 @@
"vlanTag":123,
"ipAddress":"1.2.3.4",
"netmask":"255.255.255.0",
"routes": []
"routesGw": [],
"routesIntf": []
},
{
"name":"@NETWORKNAME@",
"ifName":"eth13",
"vlanTag":124,
"ipAddress":"1.2.4.5",
"netmask":"255.255.255.0",
"routes": []
"routesGw": [],
"routesIntf": []
},
{
"name":"@NETWORKNAME@",
"ifName":"eth15",
"ipAddress":"15.2.4.5",
"netmask":"255.255.255.0",
"routes":[]
"routesGw":[],
"routesIntf":[]
}
],
"volumes":[],
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.