Skip to content

Commit

Permalink
Merge pull request #262 from linkernetworks/sufuf3/update-deploy
Browse files Browse the repository at this point in the history
[Task] Update deploy route
  • Loading branch information
John-Lin authored Aug 21, 2018
2 parents 8170a0e + 59e5e94 commit bc67b53
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
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

0 comments on commit bc67b53

Please sign in to comment.