Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
258aee2
Support hyper-v containers with containerd (*COW)
ashvindeodhar Jan 31, 2019
b7962da
Support hyper-v containers - portmapping
ashvindeodhar Apr 8, 2019
45a0908
Check for null ref before deleting
ashvindeodhar Apr 10, 2019
f42c71e
Merge remote-tracking branch 'origin/master' into containerd-cow
ashvindeodhar Apr 30, 2019
77210d1
*COW update
ashvindeodhar Apr 30, 2019
2205981
Make the protocol as const
ashvindeodhar May 1, 2019
f68b917
Address review comments
ashvindeodhar May 2, 2019
ac0000b
Merge remote-tracking branch 'origin/master' into containerd-cow
ashvindeodhar May 7, 2019
ddee108
Merge remote-tracking branch 'origin/master' into containerd-cow
ashvindeodhar May 7, 2019
21f447f
Update the dependencies in vendor
ashvindeodhar May 7, 2019
62b0c8d
WIP - VM to container connectivity
ashvindeodhar May 15, 2019
b1147b3
WIP-vm to container 2
ashvindeodhar May 21, 2019
76dfe9c
vm container connect 3
ashvindeodhar May 22, 2019
adf07f5
Fix dns_config searches and options
ashvindeodhar Jun 14, 2019
381c3c6
enable the gw endpoint creation
ashvindeodhar Jul 22, 2019
1649ad8
Use the localIP and do not create gw ep - use the loopback with gw IP
ashvindeodhar Aug 14, 2019
3348ce3
add endpoint acls
ashvindeodhar Aug 20, 2019
04e4e5d
WIP
ashvindeodhar Sep 18, 2019
69c6d6b
WIP2
ashvindeodhar Sep 18, 2019
7c4236b
WIP3
ashvindeodhar Sep 18, 2019
e61166d
Merge remote-tracking branch 'fork/fork-master' into containerd-cow
ashvindeodhar Sep 18, 2019
837e4f2
Merge remote-tracking branch 'fork/containerd-cow' into containerd-co…
ashvindeodhar Sep 18, 2019
c28b377
WIP 4
ashvindeodhar Sep 20, 2019
2ec3ee9
WIP6
ashvindeodhar Sep 20, 2019
41e738f
Merge remote-tracking branch 'fork/fork-master' into containerd-cow
ashvindeodhar Oct 1, 2019
4a9153b
Merge remote-tracking branch 'fork/containerd-cow' into containerd-co…
ashvindeodhar Oct 1, 2019
6b1c3c0
WIP-10-01
ashvindeodhar Oct 2, 2019
afcc71c
apipa ep delete
ashvindeodhar Oct 5, 2019
d627270
generic change
ashvindeodhar Oct 6, 2019
a8897a9
WIP7
ashvindeodhar Oct 7, 2019
12e7a71
WIP - not tested
ashvindeodhar Oct 7, 2019
99663ba
WIP 10-12
ashvindeodhar Oct 12, 2019
c4cbbe1
WIP-10-13-1
ashvindeodhar Oct 13, 2019
12bb8d8
WIP-10-13-2
ashvindeodhar Oct 14, 2019
a7d06c9
WIP-10-13-3
ashvindeodhar Oct 14, 2019
1da8f85
WIP-10-14-1
ashvindeodhar Oct 14, 2019
f6732cb
WIP-10-14-2
ashvindeodhar Oct 14, 2019
0fb1572
WIP-10-14-3
ashvindeodhar Oct 15, 2019
6456379
WIP-10-15-1
ashvindeodhar Oct 15, 2019
1e1866f
WIP-10-15-2
ashvindeodhar Oct 15, 2019
c9019b0
WIP-10-15-3
ashvindeodhar Oct 15, 2019
a10d7df
Address review comments
ashvindeodhar Oct 16, 2019
1fe0cad
Merge remote-tracking branch 'fork/containerd-cow' into containerd-co…
ashvindeodhar Oct 16, 2019
5f00ac1
address review comments
ashvindeodhar Oct 18, 2019
0bcd064
Merge remote-tracking branch 'origin/master' into containerd-cow-host…
ashvindeodhar Oct 18, 2019
3c1d2c7
Remove extra log line
ashvindeodhar Oct 18, 2019
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CNSFILES = \
$(wildcard cns/dockerclient/*.go) \
$(wildcard cns/imdsclient/*.go) \
$(wildcard cns/ipamclient/*.go) \
$(wildcard cns/hnsclient/*.go) \
$(wildcard cns/restserver/*.go) \
$(wildcard cns/routes/*.go) \
$(wildcard cns/service/*.go) \
Expand Down
4 changes: 2 additions & 2 deletions cni/network/multitenancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func getContainerNetworkConfigurationInternal(
namespace string,
podName string,
ifName string) (*cniTypesCurr.Result, *cns.GetNetworkContainerResponse, net.IPNet, error) {
cnsClient, err := cnsclient.NewCnsClient(address)
cnsClient, err := cnsclient.GetCnsClient()
if err != nil {
log.Printf("Initializing CNS client error %v", err)
log.Printf("Failed to get CNS client. Error: %v", err)
return nil, nil, net.IPNet{}, err
}

Expand Down
17 changes: 16 additions & 1 deletion cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
return err
}

if nwCfg.MultiTenancy {
// Initialize CNSClient
cnsclient.InitCnsClient(nwCfg.CNSUrl)
}

k8sContainerID := args.ContainerID
if len(k8sContainerID) == 0 {
errMsg := "Container ID not specified in CNI Args"
Expand Down Expand Up @@ -552,6 +557,11 @@ func (plugin *netPlugin) Get(args *cniSkel.CmdArgs) error {
return err
}

if nwCfg.MultiTenancy {
// Initialize CNSClient
cnsclient.InitCnsClient(nwCfg.CNSUrl)
}

// Initialize values from network config.
if networkId, err = getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg); err != nil {
log.Printf("[cni-net] Failed to extract network name from network config. error: %v", err)
Expand Down Expand Up @@ -627,6 +637,11 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error {
log.Printf("[cni-net] Failed to get POD info due to error: %v", err)
}

if nwCfg.MultiTenancy {
// Initialize CNSClient
cnsclient.InitCnsClient(nwCfg.CNSUrl)
}

// Initialize values from network config.
if networkId, err = getNetworkName(k8sPodName, k8sNamespace, args.IfName, nwCfg); err != nil {
log.Printf("[cni-net] Failed to extract network name from network config. error: %v", err)
Expand Down Expand Up @@ -772,7 +787,7 @@ func (plugin *netPlugin) Update(args *cniSkel.CmdArgs) error {

// now query CNS to get the target routes that should be there in the networknamespace (as a result of update)
log.Printf("Going to collect target routes for [name=%v, namespace=%v] from CNS.", k8sPodName, k8sNamespace)
if cnsClient, err = cnsclient.NewCnsClient(nwCfg.CNSUrl); err != nil {
if cnsClient, err = cnsclient.InitCnsClient(nwCfg.CNSUrl); err != nil {
log.Printf("Initializing CNS client error in CNI Update%v", err)
log.Printf(err.Error())
return plugin.Errorf(err.Error())
Expand Down
1 change: 1 addition & 0 deletions cni/network/network_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func setEndpointOptions(cnsNwConfig *cns.GetNetworkContainerResponse, epInfo *ne
epInfo.Data[network.SnatBridgeIPKey] = cnsNwConfig.LocalIPConfiguration.GatewayIPAddress + "/" + strconv.Itoa(int(cnsNwConfig.LocalIPConfiguration.IPSubnet.PrefixLength))
epInfo.AllowInboundFromHostToNC = cnsNwConfig.AllowHostToNCCommunication
epInfo.AllowInboundFromNCToHost = cnsNwConfig.AllowNCToHostCommunication
epInfo.NetworkContainerID = cnsNwConfig.NetworkContainerID
}

epInfo.Data[network.OptVethName] = vethName
Expand Down
3 changes: 3 additions & 0 deletions cni/network/network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func setEndpointOptions(cnsNwConfig *cns.GetNetworkContainerResponse, epInfo *ne
cnetAddressMap = append(cnetAddressMap, ipSubnet.IPAddress+"/"+strconv.Itoa(int(ipSubnet.PrefixLength)))
}
epInfo.Data[network.CnetAddressSpace] = cnetAddressMap
epInfo.AllowInboundFromHostToNC = cnsNwConfig.AllowHostToNCCommunication
epInfo.AllowInboundFromNCToHost = cnsNwConfig.AllowNCToHostCommunication
epInfo.NetworkContainerID = cnsNwConfig.NetworkContainerID
}
}

Expand Down
1 change: 1 addition & 0 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type GetNetworkContainerRequest struct {

// GetNetworkContainerResponse describes the response to retrieve a specifc network container.
type GetNetworkContainerResponse struct {
NetworkContainerID string
IPConfiguration IPConfiguration
Routes []Route
CnetAddressSpace []IPSubnet
Expand Down
54 changes: 40 additions & 14 deletions cns/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ import "encoding/json"

// Container Network Service remote API Contract
const (
SetEnvironmentPath = "/network/environment"
CreateNetworkPath = "/network/create"
DeleteNetworkPath = "/network/delete"
CreateHnsNetworkPath = "/network/hns/create"
DeleteHnsNetworkPath = "/network/hns/delete"
ReserveIPAddressPath = "/network/ip/reserve"
ReleaseIPAddressPath = "/network/ip/release"
GetHostLocalIPPath = "/network/ip/hostlocal"
GetIPAddressUtilizationPath = "/network/ip/utilization"
GetUnhealthyIPAddressesPath = "/network/ipaddresses/unhealthy"
GetHealthReportPath = "/network/health"
NumberOfCPUCoresPath = "/hostcpucores"
V1Prefix = "/v0.1"
V2Prefix = "/v0.2"
SetEnvironmentPath = "/network/environment"
CreateNetworkPath = "/network/create"
DeleteNetworkPath = "/network/delete"
CreateHnsNetworkPath = "/network/hns/create"
DeleteHnsNetworkPath = "/network/hns/delete"
ReserveIPAddressPath = "/network/ip/reserve"
ReleaseIPAddressPath = "/network/ip/release"
GetHostLocalIPPath = "/network/ip/hostlocal"
GetIPAddressUtilizationPath = "/network/ip/utilization"
GetUnhealthyIPAddressesPath = "/network/ipaddresses/unhealthy"
GetHealthReportPath = "/network/health"
NumberOfCPUCoresPath = "/hostcpucores"
CreateHostNCApipaEndpointPath = "/network/createhostncapipaendpoint"
DeleteHostNCApipaEndpointPath = "/network/deletehostncapipaendpoint"
V1Prefix = "/v0.1"
V2Prefix = "/v0.2"
)

// SetEnvironmentRequest describes the Request to set the environment in CNS.
Expand Down Expand Up @@ -153,3 +155,27 @@ type OptionMap map[string]interface{}
type errorResponse struct {
Err string
}

// CreateHostNCApipaEndpointRequest describes request for create apipa endpoint
// for host container connectivity for the given network container
type CreateHostNCApipaEndpointRequest struct {
NetworkContainerID string
}

// CreateHostNCApipaEndpointResponse describes response for create apipa endpoint request
// for host container connectivity.
type CreateHostNCApipaEndpointResponse struct {
Response Response
EndpointID string
}

// DeleteHostNCApipaEndpointRequest describes request for deleting apipa endpoint created
// for host NC connectivity.
type DeleteHostNCApipaEndpointRequest struct {
NetworkContainerID string
}

// DeleteHostNCApipaEndpointResponse describes response for delete host NC apipa endpoint request.
type DeleteHostNCApipaEndpointResponse struct {
Response Response
}
135 changes: 128 additions & 7 deletions cns/cnsclient/cnsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,34 @@ const (
defaultCnsURL = "http://localhost:10090"
)

// NewCnsClient create a new cns client.
func NewCnsClient(url string) (*CNSClient, error) {
if url == "" {
url = defaultCnsURL
var (
cnsClient *CNSClient
)

// InitCnsClient initializes new cns client and returns the object
func InitCnsClient(url string) (*CNSClient, error) {
if cnsClient == nil {
if url == "" {
url = defaultCnsURL
}

cnsClient = &CNSClient{
connectionURL: url,
}
}

return &CNSClient{
connectionURL: url,
}, nil
return cnsClient, nil
}

// GetCnsClient returns the cns client object
func GetCnsClient() (*CNSClient, error) {
var err error

if cnsClient == nil {
err = fmt.Errorf("[Azure CNSClient] CNS Client not initialized")
}

return cnsClient, err
}

// GetNetworkConfiguration Request to get network config.
Expand Down Expand Up @@ -77,3 +96,105 @@ func (cnsClient *CNSClient) GetNetworkConfiguration(orchestratorContext []byte)

return &resp, nil
}

// CreateHostNCApipaEndpoint creates an endpoint in APIPA network for host container connectivity.
func (cnsClient *CNSClient) CreateHostNCApipaEndpoint(
networkContainerID string) (string, error) {
var (
err error
body bytes.Buffer
)

httpc := &http.Client{}
url := cnsClient.connectionURL + cns.CreateHostNCApipaEndpointPath
log.Printf("CreateHostNCApipaEndpoint url: %v for NC: %s", url, networkContainerID)

payload := &cns.CreateHostNCApipaEndpointRequest{
NetworkContainerID: networkContainerID,
}

if err = json.NewEncoder(&body).Encode(payload); err != nil {
log.Errorf("encoding json failed with %v", err)
return "", err
}

res, err := httpc.Post(url, "application/json", &body)
if err != nil {
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
return "", err
}

defer res.Body.Close()

if res.StatusCode != http.StatusOK {
errMsg := fmt.Sprintf("[Azure CNSClient] CreateHostNCApipaEndpoint: Invalid http status code: %v",
res.StatusCode)
log.Errorf(errMsg)
return "", fmt.Errorf(errMsg)
}

var resp cns.CreateHostNCApipaEndpointResponse

if err = json.NewDecoder(res.Body).Decode(&resp); err != nil {
log.Errorf("[Azure CNSClient] Error parsing CreateHostNCApipaEndpoint response resp: %v err: %v",
res.Body, err.Error())
return "", err
}

if resp.Response.ReturnCode != 0 {
log.Errorf("[Azure CNSClient] CreateHostNCApipaEndpoint received error response :%v", resp.Response.Message)
return "", fmt.Errorf(resp.Response.Message)
}

return resp.EndpointID, nil
}

// DeleteHostNCApipaEndpoint deletes the endpoint in APIPA network created for host container connectivity.
func (cnsClient *CNSClient) DeleteHostNCApipaEndpoint(networkContainerID string) error {
var body bytes.Buffer

httpc := &http.Client{}
url := cnsClient.connectionURL + cns.DeleteHostNCApipaEndpointPath
log.Printf("DeleteHostNCApipaEndpoint url: %v for NC: %s", url, networkContainerID)

payload := &cns.DeleteHostNCApipaEndpointRequest{
NetworkContainerID: networkContainerID,
}

err := json.NewEncoder(&body).Encode(payload)
if err != nil {
log.Errorf("encoding json failed with %v", err)
return err
}

res, err := httpc.Post(url, "application/json", &body)
if err != nil {
log.Errorf("[Azure CNSClient] HTTP Post returned error %v", err.Error())
return err
}

defer res.Body.Close()

if res.StatusCode != http.StatusOK {
errMsg := fmt.Sprintf("[Azure CNSClient] DeleteHostNCApipaEndpoint: Invalid http status code: %v",
res.StatusCode)
log.Errorf(errMsg)
return fmt.Errorf(errMsg)
}

var resp cns.DeleteHostNCApipaEndpointResponse

err = json.NewDecoder(res.Body).Decode(&resp)
if err != nil {
log.Errorf("[Azure CNSClient] Error parsing DeleteHostNCApipaEndpoint response resp: %v err: %v",
res.Body, err.Error())
return err
}

if resp.Response.ReturnCode != 0 {
log.Errorf("[Azure CNSClient] DeleteHostNCApipaEndpoint received error response :%v", resp.Response.Message)
return fmt.Errorf(resp.Response.Message)
}

return nil
}
19 changes: 19 additions & 0 deletions cns/hnsclient/hnsclient_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,22 @@ func CreateHnsNetwork(nwConfig cns.CreateHnsNetworkRequest) error {
func DeleteHnsNetwork(networkName string) error {
return fmt.Errorf("DeleteHnsNetwork shouldn't be called for linux platform")
}

// CreateHostNCApipaEndpoint creates the endpoint in the apipa network
// for host container connectivity
// This is windows platform specific.
func CreateHostNCApipaEndpoint(
networkContainerID string,
localIPConfiguration cns.IPConfiguration,
allowNCToHostCommunication bool,
allowHostToNCCommunication bool) (string, error) {
return "", nil
}

// DeleteHostNCApipaEndpoint deletes the endpoint in the apipa network
// created for host container connectivity
// This is windows platform specific.
func DeleteHostNCApipaEndpoint(
networkContainerID string) error {
return nil
}
Loading