diff --git a/cnm/plugin/main.go b/cnm/plugin/main.go index 995b957545..9919b8a555 100644 --- a/cnm/plugin/main.go +++ b/cnm/plugin/main.go @@ -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, }, }, { diff --git a/cns/service/main.go b/cns/service/main.go index 3609aba856..2be2bde65c 100644 --- a/cns/service/main.go +++ b/cns/service/main.go @@ -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, }, }, diff --git a/common/config.go b/common/config.go index 7a272dc73e..35b9f36ea2 100644 --- a/common/config.go +++ b/common/config.go @@ -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" diff --git a/ipam/mas.go b/ipam/fileIpam.go similarity index 88% rename from ipam/mas.go rename to ipam/fileIpam.go index 45b6ec4fda..358e9c8133 100644 --- a/ipam/mas.go +++ b/ipam/fileIpam.go @@ -11,6 +11,7 @@ import ( "runtime" "strings" + "github.com/Azure/azure-container-networking/common" "github.com/Azure/azure-container-networking/log" ) @@ -18,11 +19,10 @@ 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 @@ -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 { diff --git a/ipam/mas_test.go b/ipam/fileIpam_test.go similarity index 86% rename from ipam/mas_test.go rename to ipam/fileIpam_test.go index 15cfe98051..16d9e72a88 100644 --- a/ipam/mas_test.go +++ b/ipam/fileIpam_test.go @@ -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 { @@ -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) @@ -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{}, }, { @@ -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{}, }, }, } @@ -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) } -} \ No newline at end of file +} diff --git a/ipam/manager.go b/ipam/manager.go index 4cbd34f790..e9a912780e 100644 --- a/ipam/manager.go +++ b/ipam/manager.go @@ -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()