Skip to content
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
5 changes: 3 additions & 2 deletions cnm/plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ var args = common.ArgumentList{
Type: "string",
DefaultValue: common.OptEnvironmentAzure,
ValueMap: map[string]interface{}{
common.OptEnvironmentAzure: 0,
common.OptEnvironmentMAS: 0,
common.OptEnvironmentAzure: 0,
common.OptEnvironmentMAS: 0,
common.OptEnvironmentFileIpam: 0,
},
},
{
Expand Down
5 changes: 3 additions & 2 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ var args = acn.ArgumentList{
Type: "string",
DefaultValue: acn.OptEnvironmentAzure,
ValueMap: map[string]interface{}{
acn.OptEnvironmentAzure: 0,
acn.OptEnvironmentMAS: 0,
acn.OptEnvironmentAzure: 0,
acn.OptEnvironmentMAS: 0,
acn.OptEnvironmentFileIpam: 0,
},
},

Expand Down
9 changes: 5 additions & 4 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ package common
// Command line options.
const (
// Operating environment.
OptEnvironment = "environment"
OptEnvironmentAlias = "e"
OptEnvironmentAzure = "azure"
OptEnvironmentMAS = "mas"
OptEnvironment = "environment"
OptEnvironmentAlias = "e"
OptEnvironmentAzure = "azure"
OptEnvironmentMAS = "mas"
OptEnvironmentFileIpam = "fileIpam"

// API server URL.
OptAPIServerURL = "api-url"
Expand Down
23 changes: 13 additions & 10 deletions ipam/mas.go → ipam/fileIpam.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import (
"runtime"
"strings"

"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/log"
)

const (
defaultLinuxFilePath = "/etc/kubernetes/interfaces.json"
defaultWindowsFilePath = `c:\k\interfaces.json`
windows = "windows"
name = "MAS"
)

// Microsoft Azure Stack IPAM configuration source.
type masSource struct {
type fileIpamSource struct {
name string
sink addressConfigSink
fileLoaded bool
Expand Down Expand Up @@ -50,36 +50,39 @@ type IPAddress struct {
IsPrimary bool
}

// Creates the MAS source.
func newMasSource(options map[string]interface{}) (*masSource, error) {
// Creates the MAS/fileIpam source.
func newFileIpamSource(options map[string]interface{}) (*fileIpamSource, error) {
var filePath string
var name string

if runtime.GOOS == windows {
filePath = defaultWindowsFilePath
} else {
filePath = defaultLinuxFilePath
}

return &masSource{
name: name,
name = options[common.OptEnvironment].(string)
return &fileIpamSource{
name: name,
filePath: filePath,
}, nil
}

// Starts the MAS source.
func (source *masSource) start(sink addressConfigSink) error {
func (source *fileIpamSource) start(sink addressConfigSink) error {
source.sink = sink
return nil
}

// Stops the MAS source.
func (source *masSource) stop() {
func (source *fileIpamSource) stop() {
source.sink = nil
}

// Refreshes configuration.
func (source *masSource) refresh() error {
func (source *fileIpamSource) refresh() error {
if source == nil {
return errors.New("masSource is nil")
return errors.New("fileIpamSource is nil")
}

if source.fileLoaded {
Expand Down
46 changes: 35 additions & 11 deletions ipam/mas_test.go → ipam/fileIpam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import (
"reflect"
"runtime"
"testing"

"github.com/Azure/azure-container-networking/common"
)

func TestNewMasSource(t *testing.T) {
options := make(map[string]interface{})
mas, _ := newMasSource(options)
options[common.OptEnvironment] = common.OptEnvironmentMAS
mas, _ := newFileIpamSource(options)

if runtime.GOOS == windows {
if mas.filePath != defaultWindowsFilePath {
Expand All @@ -20,14 +23,35 @@ func TestNewMasSource(t *testing.T) {
t.Fatalf("default file path set incorrectly")
}
}
if mas.name != "MAS" {

if mas.name != "mas" {
t.Fatalf("mas source Name incorrect")
}
}

func TestNewFileIpamSource(t *testing.T) {
options := make(map[string]interface{})
options[common.OptEnvironment] = common.OptEnvironmentFileIPAM
fileIpam, _ := newFileIpamSource(options)

if runtime.GOOS == windows {
if fileIpam.filePath != defaultWindowsFilePath {
t.Fatalf("default file path set incorrectly")
}
} else {
if fileIpam.filePath != defaultLinuxFilePath {
t.Fatalf("default file path set incorrectly")
}
}

if fileIpam.name != "fileIpam" {
t.Fatalf("fileIpam source Name incorrect")
}
}

func TestGetSDNInterfaces(t *testing.T) {
const validFileName = "testfiles/masInterfaceConfig.json"
const invalidFileName = "mas_test.go"
const invalidFileName = "fileIpam_test.go"
const nonexistentFileName = "bad"

interfaces, err := getSDNInterfaces(validFileName)
Expand Down Expand Up @@ -166,11 +190,11 @@ func TestPopulateAddressSpaceMultipleSDNInterfaces(t *testing.T) {
IsPrimary: true,
IPSubnets: []IPSubnet{
{
Prefix: "0.0.0.0/24",
Prefix: "0.0.0.0/24",
IPAddresses: []IPAddress{},
},
{
Prefix: "0.1.0.0/24",
Prefix: "0.1.0.0/24",
IPAddresses: []IPAddress{},
},
{
Expand All @@ -183,22 +207,22 @@ func TestPopulateAddressSpaceMultipleSDNInterfaces(t *testing.T) {
},
{
MacAddress: "111111111111",
IsPrimary: false,
IsPrimary: false,
IPSubnets: []IPSubnet{
{
Prefix: "1.0.0.0/24",
Prefix: "1.0.0.0/24",
IPAddresses: []IPAddress{},
},
{
Prefix: "1.1.0.0/24",
Prefix: "1.1.0.0/24",
IPAddresses: []IPAddress{},
},
},
},
{
MacAddress: "222222222222",
IsPrimary: false,
IPSubnets: []IPSubnet{},
IsPrimary: false,
IPSubnets: []IPSubnet{},
},
},
}
Expand Down Expand Up @@ -263,4 +287,4 @@ func TestPopulateAddressSpaceMultipleSDNInterfaces(t *testing.T) {
if pool.Priority != 1 {
t.Fatalf("Incorrect interface priority. expected: %d, actual %d", 1, pool.Priority)
}
}
}
5 changes: 4 additions & 1 deletion ipam/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ func (am *addressManager) StartSource(options map[string]interface{}) error {
am.source, err = newAzureSource(options)

case common.OptEnvironmentMAS:
am.source, err = newMasSource(options)
am.source, err = newFileIpamSource(options)

case common.OptEnvironmentFileIpam:
am.source, err = newFileIpamSource(options)

case "null":
am.source, err = newNullSource()
Expand Down