Skip to content

Commit

Permalink
Merge pull request #123 from linkernetworks/hwchiu/VX-187
Browse files Browse the repository at this point in the history
Support the vlan tag for client
  • Loading branch information
John-Lin authored Jul 19, 2018
2 parents b996f03 + c9ad9e9 commit 2836777
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/entity/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Container struct {
type PodNetwork struct {
Name string `bson:"name" json:"name"`
IfName string `bson:"ifName" json:"ifName"`
VlanTag int `bson:"vlanTag" json:"vlanTag"`
VlanTag *int32 `bson:"vlanTag" json:"vlanTag"`
IPAddress string `bson:"ipAddress json:"ipAddress"`
Netmask string `bson:"netmask" json:"netmask"`
BridgeName string `bson:"bridgeName" json:"bridgeName"` //its from the entity.Network entity
Expand Down
10 changes: 8 additions & 2 deletions src/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pod
import (
"fmt"
"regexp"
"strconv"

"github.com/linkernetworks/mongo"
"github.com/linkernetworks/vortex/src/entity"
Expand Down Expand Up @@ -106,15 +107,20 @@ func generateNodeLabels(networks []entity.Network) []string {
return utils.Intersections(totalNames)
}

func generateClientCommand(network entity.PodNetwork) []string {
func generateClientCommand(network entity.PodNetwork) (command []string) {
ip := utils.IPToCIDR(network.IPAddress, network.Netmask)

return []string{
command = []string{
"-s=unix:///tmp/vortex.sock",
"-b=" + network.BridgeName,
"-n=" + network.IfName,
"-i=" + ip,
}

if network.VlanTag != nil {
command = append(command, "-v="+strconv.Itoa((int)(*network.VlanTag)))
}
return
}

func generateInitContainer(networks []entity.PodNetwork) ([]corev1.Container, error) {
Expand Down
8 changes: 8 additions & 0 deletions src/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ func (suite *PodTestSuite) TestGenerateClientCommand() {
command := generateClientCommand(podNetwork)
ans := []string{"-s=unix:///tmp/vortex.sock", "-b=" + bName, "-n=" + ifName, "-i=1.2.3.4/24"}
suite.Equal(ans, command)

var vlanTag int32
vlanTag = 123
podNetwork.VlanTag = &vlanTag
command = generateClientCommand(podNetwork)
ans = []string{"-s=unix:///tmp/vortex.sock", "-b=" + bName, "-n=" + ifName, "-i=1.2.3.4/24", "-v=123"}
suite.Equal(ans, command)

}

func (suite *PodTestSuite) TestGenerateNetwork() {
Expand Down

0 comments on commit 2836777

Please sign in to comment.