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 deploy route #262

Merged
merged 3 commits into from
Aug 21, 2018
Merged
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
18 changes: 17 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,11 @@ For each Deployment, 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(required): destination network cidr for add IP routing table
- gateway(required): the gateway of the interface subnet
- routeIntf: a array of route without gateway (Optional)
- dstCIDR(required): destination network cidr for add IP routing table
7. capability: the power of the container, if it's ture, it will get almost all capability and act as a privileged=true.
8.
9. networkType: the string options for network type, support "host", "custom" and "cluster".
Expand Down Expand Up @@ -811,7 +816,18 @@ 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":[
],
Expand Down
16 changes: 9 additions & 7 deletions src/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ func generateClientCommand(network entity.DeploymentNetwork) (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 @@ -124,7 +126,7 @@ func generateInitContainer(networks []entity.DeploymentNetwork) ([]corev1.Contai
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
20 changes: 13 additions & 7 deletions src/entity/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,27 @@ const (
DeploymentCustomNetwork = "custom"
)

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

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

// DeploymentNetwork is the structure for deployment network info
type DeploymentNetwork 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 []DeploymentRoute `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 []DeploymentRouteGw `bson:"routesGw,omitempty" json:"routesGw" validate:"required,dive,required"`
RoutesIntf []DeploymentRouteIntf `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