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
7 changes: 1 addition & 6 deletions cni/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ import (
cniTypesCurr "github.com/containernetworking/cni/pkg/types/current"
)

const (
// Plugin name.
name = "azure-vnet-ipam"
)

var (
ipv4DefaultRouteDstPrefix = net.IPNet{net.IPv4zero, net.IPv4Mask(0, 0, 0, 0)}
)
Expand All @@ -35,7 +30,7 @@ type ipamPlugin struct {
}

// NewPlugin creates a new ipamPlugin object.
func NewPlugin(config *common.PluginConfig) (*ipamPlugin, error) {
func NewPlugin(name string, config *common.PluginConfig) (*ipamPlugin, error) {
// Setup base plugin.
plugin, err := cni.NewPlugin(name, config.Version)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cni/ipam/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestMain(m *testing.M) {
}

// Create the plugin.
plugin, err = NewPlugin(&config)
plugin, err = NewPlugin("ipamtest", &config)
if err != nil {
fmt.Printf("Failed to create IPAM plugin, err:%v.\n", err)
return
Expand Down
16 changes: 15 additions & 1 deletion cni/ipam/plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"github.com/Azure/azure-container-networking/cni"
"github.com/Azure/azure-container-networking/cni/ipam"
"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/log"
)

const (
name = "azure-vnet-ipam"
)

// Version is populated by make during build.
Expand All @@ -20,7 +25,16 @@ func main() {
var config common.PluginConfig
config.Version = version

ipamPlugin, err := ipam.NewPlugin(&config)
log.SetName(name)
log.SetLevel(log.LevelInfo)
if err := log.SetTarget(log.TargetLogfile); err != nil {
fmt.Printf("Failed to setup cni logging: %v\n", err)
return
}

defer log.Close()

ipamPlugin, err := ipam.NewPlugin(name, &config)
if err != nil {
fmt.Printf("Failed to create IPAM plugin, err:%v.\n", err)
os.Exit(1)
Expand Down
21 changes: 19 additions & 2 deletions ipam/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package ipam

import (
"encoding/xml"
"fmt"
"net"
"net/http"
"strings"
Expand All @@ -17,9 +18,12 @@ import (
const (
// Host URL to query.
azureQueryUrl = "http://168.63.129.16/machine/plugins?comp=nmagent&type=getinterfaceinfov1"

// Minimum time interval between consecutive queries.
azureQueryInterval = 10 * time.Second
// http connection timeout
httpConnectionTimeout = 10
// http response header timeout
responseHeaderTimeout = 10
)

// Microsoft Azure IPAM configuration source.
Expand Down Expand Up @@ -84,14 +88,27 @@ func (s *azureSource) refresh() error {
return err
}

httpClient := common.InitHttpClient(httpConnectionTimeout, responseHeaderTimeout)
if httpClient == nil {
log.Errorf("[ipam] Failed intializing http client")
return fmt.Errorf("Error intializing http client")
}

log.Printf("[ipam] Wireserver call %v to retrieve IP List", s.queryUrl)
// Fetch configuration.
resp, err := http.Get(s.queryUrl)
resp, err := httpClient.Get(s.queryUrl)
if err != nil {
log.Printf("[ipam] wireserver call failed with: %v", err)
return err
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
log.Errorf("[ipam] http return error code for wireserver call %+v", resp)
return fmt.Errorf("wireserver http error %+v", resp)
}

// Decode XML document.
var doc common.XmlDocument
decoder := xml.NewDecoder(resp.Body)
Expand Down