Skip to content
Open
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
1 change: 1 addition & 0 deletions cni/netconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type NetworkConfig struct {
RuntimeConfig RuntimeConfig `json:"runtimeConfig,omitempty"`
WindowsSettings WindowsSettings `json:"windowsSettings,omitempty"`
AdditionalArgs []KVPair `json:"AdditionalArgs,omitempty"`
WireServerIP string `json:"wireServerIP,omitempty"`
}

type WindowsSettings struct {
Expand Down
14 changes: 12 additions & 2 deletions cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ const (
)

const (
// URL to query NMAgent version and determine whether we snat on host
nmAgentSupportedApisURL = "http://168.63.129.16/machine/plugins/?comp=nmagent&type=GetSupportedApis"
// Only SNAT support (no DNS support)
nmAgentSnatSupportAPI = "NetworkManagementSnatSupport"
// SNAT and DNS are both supported
nmAgentSnatAndDnsSupportAPI = "NetworkManagementDNSSupport"
)

// defaultWireServerIP is the Azure Wire Server IP address.
const defaultWireServerIP = "168.63.129.16"

// temporary consts related func determineSnat() which is to be deleted after
// a baking period with newest NMAgent changes
const (
Expand Down Expand Up @@ -344,6 +345,13 @@ func (plugin *NetPlugin) getNetworkInfo(netNs string, interfaceInfo *network.Int
return nwInfo
}

func buildNmAgentSupportedApisURL(wireServerIP string) string {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into using nmagent.Client here, but nmagent.Client.SupportedAPIs() doesn't return a URL, it makes the full HTTP call and returns parsed results. Using it here would require changing the DetermineSnatFeatureOnHost interface, implementation, and mock. Since this is just to make the Wire Server IP configurable for local OneBox testing, I kept the change minimal - just making the existing hardcoded IP configurable without refactoring the production workflow.

if wireServerIP == "" {
wireServerIP = defaultWireServerIP
}
return fmt.Sprintf("http://%s/machine/plugins/?comp=nmagent&type=GetSupportedApis", wireServerIP)
}
Comment on lines +348 to +353

// CNI implementation
// https://github.com/containernetworking/cni/blob/master/SPEC.md

Expand Down Expand Up @@ -500,6 +508,8 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
telemetryClient.Settings().Context = "AzureCNIMultitenancy"
plugin.multitenancyClient.Init(cnsClient, AzureNetIOShim{})

nmAgentSupportedApisURL := buildNmAgentSupportedApisURL(nwCfg.WireServerIP)

// Temporary if block to determining whether we disable SNAT on host (for multi-tenant scenario only)
if enableSnatForDNS, nwCfg.EnableSnatOnHost, err = plugin.multitenancyClient.DetermineSnatFeatureOnHost(
snatConfigFileName, nmAgentSupportedApisURL); err != nil {
Expand Down
32 changes: 32 additions & 0 deletions cni/network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1849,3 +1849,35 @@ func TestValidateArgs(t *testing.T) {
})
}
}

func TestBuildNmAgentSupportedApisURL(t *testing.T) {
tests := []struct {
name string
wireServerIP string
expectedURL string
}{
{
name: "empty string defaults to well-known wireserver IP",
wireServerIP: "",
expectedURL: "http://168.63.129.16/machine/plugins/?comp=nmagent&type=GetSupportedApis",
},
{
name: "custom IPv4 address",
wireServerIP: "10.0.0.1",
expectedURL: "http://10.0.0.1/machine/plugins/?comp=nmagent&type=GetSupportedApis",
},
{
name: "custom IPv4 address with port",
wireServerIP: "10.0.0.1:8080",
expectedURL: "http://10.0.0.1:8080/machine/plugins/?comp=nmagent&type=GetSupportedApis",
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
result := buildNmAgentSupportedApisURL(tt.wireServerIP)
assert.Equal(t, tt.expectedURL, result)
})
}
}
Loading