Pass HostInterface PrimaryIP info to CNI (#662)
* Pass HostPrimaryInterface details to CNS
This commit is contained in:
Родитель
0b3f31daee
Коммит
de95ffc399
1
Makefile
1
Makefile
|
@ -51,6 +51,7 @@ CNSFILES = \
|
|||
$(wildcard cns/networkcontainers/*.go) \
|
||||
$(wildcard cns/requestcontroller/*.go) \
|
||||
$(wildcard cns/requestcontroller/kubecontroller/*.go) \
|
||||
$(wildcard cns/fakes/*.go) \
|
||||
$(COREFILES) \
|
||||
$(CNMFILES)
|
||||
|
||||
|
|
|
@ -207,7 +207,8 @@ type PodIpInfo struct {
|
|||
|
||||
// DeleteNetworkContainerRequest specifies the details about the request to delete a specifc network container.
|
||||
type HostIPInfo struct {
|
||||
IPConfig IPSubnet
|
||||
PrimaryIP string
|
||||
Subnet string
|
||||
}
|
||||
|
||||
// DeleteNetworkContainerRequest specifies the details about the request to delete a specifc network container.
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
|
||||
"github.com/Azure/azure-container-networking/cns"
|
||||
"github.com/Azure/azure-container-networking/cns/common"
|
||||
"github.com/Azure/azure-container-networking/cns/fakes"
|
||||
"github.com/Azure/azure-container-networking/cns/logger"
|
||||
"github.com/Azure/azure-container-networking/cns/restserver"
|
||||
"github.com/Azure/azure-container-networking/log"
|
||||
|
@ -117,7 +118,7 @@ func TestMain(m *testing.M) {
|
|||
logger.InitLogger(logName, 0, 0, tmpLogDir+"/")
|
||||
config := common.ServiceConfig{}
|
||||
|
||||
httpRestService, err := restserver.NewHTTPRestService(&config)
|
||||
httpRestService, err := restserver.NewHTTPRestService(&config, fakes.NewFakeImdsClient())
|
||||
svc = httpRestService.(*restserver.HTTPRestService)
|
||||
svc.Name = "cns-test-server"
|
||||
if err != nil {
|
||||
|
|
|
@ -25,19 +25,19 @@ const (
|
|||
// DockerClient specifies a client to connect to docker.
|
||||
type DockerClient struct {
|
||||
connectionURL string
|
||||
imdsClient *imdsclient.ImdsClient
|
||||
imdsClient imdsclient.ImdsClientInterface
|
||||
}
|
||||
|
||||
// NewDockerClient create a new docker client.
|
||||
func NewDockerClient(url string) (*DockerClient, error) {
|
||||
return &DockerClient{
|
||||
connectionURL: url,
|
||||
imdsClient: &imdsclient.ImdsClient{},
|
||||
imdsClient: new(imdsclient.ImdsClient),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// NewDefaultDockerClient create a new docker client.
|
||||
func NewDefaultDockerClient(imdsClient *imdsclient.ImdsClient) (*DockerClient, error) {
|
||||
func NewDefaultDockerClient(imdsClient imdsclient.ImdsClientInterface) (*DockerClient, error) {
|
||||
return &DockerClient{
|
||||
connectionURL: defaultDockerConnectionURL,
|
||||
imdsClient: imdsClient,
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2017 Microsoft. All rights reserved.
|
||||
// MIT License
|
||||
|
||||
package fakes
|
||||
|
||||
import (
|
||||
"github.com/Azure/azure-container-networking/cns/imdsclient"
|
||||
"github.com/Azure/azure-container-networking/cns/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
HostPrimaryIpTest = "10.0.0.4"
|
||||
HostSubnetTest = "10.0.0.0/24"
|
||||
)
|
||||
|
||||
// ImdsClient can be used to connect to VM Host agent in Azure.
|
||||
type ImdsClientTest struct {
|
||||
}
|
||||
|
||||
func NewFakeImdsClient() *ImdsClientTest {
|
||||
return &ImdsClientTest{}
|
||||
}
|
||||
|
||||
// GetNetworkContainerInfoFromHost- Mock implementation to return Container version info.
|
||||
func (imdsClient *ImdsClientTest) GetNetworkContainerInfoFromHost(networkContainerID string, primaryAddress string, authToken string, apiVersion string) (*imdsclient.ContainerVersion, error) {
|
||||
|
||||
ret := &imdsclient.ContainerVersion{}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// GetPrimaryInterfaceInfoFromHost - Mock implementation to return Host interface info
|
||||
func (imdsClient *ImdsClientTest) GetPrimaryInterfaceInfoFromHost() (*imdsclient.InterfaceInfo, error) {
|
||||
logger.Printf("[Azure CNS] GetPrimaryInterfaceInfoFromHost")
|
||||
|
||||
interfaceInfo := &imdsclient.InterfaceInfo{
|
||||
Subnet: HostSubnetTest,
|
||||
PrimaryIP: HostPrimaryIpTest,
|
||||
}
|
||||
|
||||
return interfaceInfo, nil
|
||||
}
|
||||
|
||||
// GetPrimaryInterfaceInfoFromMemory - Mock implementation to return host interface info
|
||||
func (imdsClient *ImdsClientTest) GetPrimaryInterfaceInfoFromMemory() (*imdsclient.InterfaceInfo, error) {
|
||||
logger.Printf("[Azure CNS] GetPrimaryInterfaceInfoFromMemory")
|
||||
|
||||
return imdsClient.GetPrimaryInterfaceInfoFromHost()
|
||||
}
|
|
@ -68,3 +68,10 @@ type ContainerVersion struct {
|
|||
NetworkContainerID string
|
||||
ProgrammedVersion string
|
||||
}
|
||||
|
||||
// An ImdsInterface performs CRUD operations on IP reservations
|
||||
type ImdsClientInterface interface {
|
||||
GetNetworkContainerInfoFromHost(networkContainerID string, primaryAddress string, authToken string, apiVersion string) (*ContainerVersion, error)
|
||||
GetPrimaryInterfaceInfoFromHost() (*InterfaceInfo, error)
|
||||
GetPrimaryInterfaceInfoFromMemory() (*InterfaceInfo, error)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
|
||||
"github.com/Azure/azure-container-networking/cns"
|
||||
"github.com/Azure/azure-container-networking/cns/common"
|
||||
"github.com/Azure/azure-container-networking/cns/fakes"
|
||||
"github.com/Azure/azure-container-networking/cns/logger"
|
||||
acncommon "github.com/Azure/azure-container-networking/common"
|
||||
)
|
||||
|
@ -656,7 +657,7 @@ func startService() {
|
|||
var err error
|
||||
// Create the service.
|
||||
config := common.ServiceConfig{}
|
||||
service, err = NewHTTPRestService(&config)
|
||||
service, err = NewHTTPRestService(&config, fakes.NewFakeImdsClient())
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create CNS object %v\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/Azure/azure-container-networking/cns"
|
||||
"github.com/Azure/azure-container-networking/cns/common"
|
||||
"github.com/Azure/azure-container-networking/cns/fakes"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -40,7 +41,7 @@ var (
|
|||
|
||||
func getTestService() *HTTPRestService {
|
||||
var config common.ServiceConfig
|
||||
httpsvc, _ := NewHTTPRestService(&config)
|
||||
httpsvc, _ := NewHTTPRestService(&config, fakes.NewFakeImdsClient())
|
||||
svc = httpsvc.(*HTTPRestService)
|
||||
setOrchestratorTypeInternal(cns.KubernetesCRD)
|
||||
|
||||
|
@ -98,6 +99,14 @@ func requestIpAddressAndGetState(t *testing.T, req cns.GetIPConfigRequest) (ipCo
|
|||
t.Fatalf("Pod IP Prefix length is not added as expected ipConfig %+v, expected: %+v", PodIpInfo.PodIPConfig, subnetPrfixLength)
|
||||
}
|
||||
|
||||
if reflect.DeepEqual(PodIpInfo.HostPrimaryIPInfo.PrimaryIP, fakes.HostPrimaryIpTest) != true {
|
||||
t.Fatalf("Host PrimaryIP is not added as expected ipConfig %+v, expected primaryIP: %+v", PodIpInfo.HostPrimaryIPInfo, fakes.HostPrimaryIpTest)
|
||||
}
|
||||
|
||||
if reflect.DeepEqual(PodIpInfo.HostPrimaryIPInfo.Subnet, fakes.HostSubnetTest) != true {
|
||||
t.Fatalf("Host Subnet is not added as expected ipConfig %+v, expected Host subnet: %+v", PodIpInfo.HostPrimaryIPInfo, fakes.HostSubnetTest)
|
||||
}
|
||||
|
||||
// retrieve podinfo from orchestrator context
|
||||
if err := json.Unmarshal(req.OrchestratorContext, &podInfo); err != nil {
|
||||
return ipState, err
|
||||
|
|
|
@ -37,7 +37,7 @@ var (
|
|||
type HTTPRestService struct {
|
||||
*cns.Service
|
||||
dockerClient *dockerclient.DockerClient
|
||||
imdsClient *imdsclient.ImdsClient
|
||||
imdsClient imdsclient.ImdsClientInterface
|
||||
ipamClient *ipamclient.IpamClient
|
||||
networkContainer *networkcontainers.NetworkContainers
|
||||
PodIPIDByOrchestratorContext map[string]string // OrchestratorContext is key and value is Pod IP uuid.
|
||||
|
@ -102,16 +102,16 @@ type HTTPService interface {
|
|||
}
|
||||
|
||||
// NewHTTPRestService creates a new HTTP Service object.
|
||||
func NewHTTPRestService(config *common.ServiceConfig) (HTTPService, error) {
|
||||
func NewHTTPRestService(config *common.ServiceConfig, imdsClientInterface imdsclient.ImdsClientInterface) (HTTPService, error) {
|
||||
service, err := cns.NewService(config.Name, config.Version, config.ChannelMode, config.Store)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
imdsClient := &imdsclient.ImdsClient{}
|
||||
imdsClient := imdsClientInterface
|
||||
routingTable := &routes.RoutingTable{}
|
||||
nc := &networkcontainers.NetworkContainers{}
|
||||
dc, err := dockerclient.NewDefaultDockerClient(imdsClient)
|
||||
dc, err := dockerclient.NewDefaultDockerClient(imdsClientInterface)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -661,7 +661,13 @@ func (service *HTTPRestService) populateIpConfigInfoUntransacted(ipConfigStatus
|
|||
|
||||
podIpInfo.NetworkContainerPrimaryIPConfig = primaryIpConfiguration
|
||||
|
||||
// TODO Add Host Primary ipinfo
|
||||
hostInterfaceInfo, err := service.imdsClient.GetPrimaryInterfaceInfoFromMemory()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to get the HostInterfaceInfo %s", err)
|
||||
}
|
||||
|
||||
podIpInfo.HostPrimaryIPInfo.PrimaryIP = hostInterfaceInfo.PrimaryIP
|
||||
podIpInfo.HostPrimaryIPInfo.Subnet = hostInterfaceInfo.Subnet
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/Azure/azure-container-networking/cns/common"
|
||||
"github.com/Azure/azure-container-networking/cns/configuration"
|
||||
"github.com/Azure/azure-container-networking/cns/hnsclient"
|
||||
"github.com/Azure/azure-container-networking/cns/imdsclient"
|
||||
"github.com/Azure/azure-container-networking/cns/logger"
|
||||
"github.com/Azure/azure-container-networking/cns/requestcontroller"
|
||||
"github.com/Azure/azure-container-networking/cns/requestcontroller/kubecontroller"
|
||||
|
@ -367,7 +368,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Create CNS object.
|
||||
httpRestService, err := restserver.NewHTTPRestService(&config)
|
||||
httpRestService, err := restserver.NewHTTPRestService(&config, new(imdsclient.ImdsClient))
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to create CNS object, err:%v.\n", err)
|
||||
return
|
||||
|
|
Загрузка…
Ссылка в новой задаче