Fix for http client call to wireserver (#431)

* modified wireserver call to non-blocking. Fixed logging issue in ipam

* fixed ut

* addressing review comments

* used inithttpclient function
This commit is contained in:
tamilmani1989 2019-11-25 17:07:50 -08:00 коммит произвёл GitHub
Родитель e0ba7ad924
Коммит 534e646fd9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 36 добавлений и 10 удалений

Просмотреть файл

@ -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)}
)
@ -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 {

Просмотреть файл

@ -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

Просмотреть файл

@ -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.
@ -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)

Просмотреть файл

@ -5,6 +5,7 @@ package ipam
import (
"encoding/xml"
"fmt"
"net"
"net/http"
"strings"
@ -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.
@ -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)