Skip to content

Commit 9ed24a3

Browse files
committed
Merge branch 'master' of github.com:sharmasushant/azure-container-networking into fork-master
2 parents 3a006e2 + 3ea96ed commit 9ed24a3

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

cni/network/network_windows.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package network
22

33
import (
4+
"fmt"
45
"net"
56

67
"github.com/Azure/azure-container-networking/cni"
@@ -19,7 +20,7 @@ import (
1920
* Issue link: https://github.com/kubernetes/kubernetes/issues/57253
2021
*/
2122
func handleConsecutiveAdd(containerId, endpointId string, nwInfo *network.NetworkInfo, nwCfg *cni.NetworkConfig) (*cniTypesCurr.Result, error) {
22-
hnsEndpoint, _ := hcsshim.GetHNSEndpointByName(endpointId)
23+
hnsEndpoint, err := hcsshim.GetHNSEndpointByName(endpointId)
2324
if hnsEndpoint != nil {
2425
log.Printf("[net] Found existing endpoint through hcsshim: %+v", hnsEndpoint)
2526
log.Printf("[net] Attaching ep %v to container %v", hnsEndpoint.Id, containerId)
@@ -55,7 +56,8 @@ func handleConsecutiveAdd(containerId, endpointId string, nwInfo *network.Networ
5556
return result, nil
5657
}
5758

58-
return nil, nil
59+
err = fmt.Errorf("GetHNSEndpointByName for %v returned nil with err %v", endpointId, err)
60+
return nil, err
5961
}
6062

6163
func addDefaultRoute(gwIPString string, epInfo *network.EndpointInfo, result *cniTypesCurr.Result) {

cns/NetworkContainerContract.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ const (
1616
const (
1717
AzureContainerInstance = "AzureContainerInstance"
1818
WebApps = "WebApps"
19+
ClearContainer = "ClearContainer"
1920
)
2021

2122
// Orchestrator Types
2223
const (
23-
Kubernetes = "Kubernetes"
24+
Kubernetes = "Kubernetes"
25+
ServiceFabric = "ServiceFabric"
2426
)
2527

2628
// Encap Types

cns/restserver/restserver.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -820,14 +820,9 @@ func (service *httpRestService) setOrchestratorType(w http.ResponseWriter, r *ht
820820
service.lock.Lock()
821821

822822
switch req.OrchestratorType {
823-
case cns.Kubernetes:
824-
service.state.OrchestratorType = cns.Kubernetes
823+
case cns.ServiceFabric, cns.Kubernetes, cns.WebApps:
824+
service.state.OrchestratorType = req.OrchestratorType
825825
service.saveState()
826-
break
827-
case cns.WebApps:
828-
service.state.OrchestratorType = cns.WebApps
829-
service.saveState()
830-
break
831826
default:
832827
returnMessage = fmt.Sprintf("Invalid Orchestrator type %v", req.OrchestratorType)
833828
returnCode = UnsupportedOrchestratorType
@@ -866,13 +861,14 @@ func (service *httpRestService) saveNetworkContainerGoalState(req cns.CreateNetw
866861
CreateNetworkContainerRequest: req,
867862
HostVersion: hostVersion}
868863

869-
if req.NetworkContainerType == cns.AzureContainerInstance {
864+
if req.NetworkContainerType == cns.AzureContainerInstance ||
865+
req.NetworkContainerType == cns.ClearContainer {
870866
switch service.state.OrchestratorType {
871-
case cns.Kubernetes:
867+
case cns.Kubernetes, cns.ServiceFabric:
872868
var podInfo cns.KubernetesPodInfo
873869
err := json.Unmarshal(req.OrchestratorContext, &podInfo)
874870
if err != nil {
875-
errBuf := fmt.Sprintf("Unmarshalling AzureContainerInstanceInfo failed with error %v", err)
871+
errBuf := fmt.Sprintf("Unmarshalling %s failed with error %v", req.NetworkContainerType, err)
876872
return UnexpectedError, errBuf
877873
}
878874

@@ -980,7 +976,7 @@ func (service *httpRestService) getNetworkContainerResponse(req cns.GetNetworkCo
980976
defer service.lock.Unlock()
981977

982978
switch service.state.OrchestratorType {
983-
case cns.Kubernetes:
979+
case cns.Kubernetes, cns.ServiceFabric:
984980
var podInfo cns.KubernetesPodInfo
985981
err := json.Unmarshal(req.OrchestratorContext, &podInfo)
986982
if err != nil {

network/endpoint_windows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func ConstructEndpointID(containerID string, netNsPath string, ifName string) (s
4747
// newEndpointImpl creates a new endpoint in the network.
4848
func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
4949
// Get Infrastructure containerID. Handle ADD calls for workload container.
50+
var err error
5051
infraEpName, _ := ConstructEndpointID(epInfo.ContainerID, epInfo.NetNsPath, epInfo.IfName)
5152

5253
hnsEndpoint := &hcsshim.HNSEndpoint{
@@ -79,11 +80,20 @@ func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) {
7980
return nil, err
8081
}
8182

83+
defer func() {
84+
if err != nil {
85+
log.Printf("[net] HNSEndpointRequest DELETE id:%v", hnsResponse.Id)
86+
hnsResponse, err := hcsshim.HNSEndpointRequest("DELETE", hnsResponse.Id, "")
87+
log.Printf("[net] HNSEndpointRequest DELETE response:%+v err:%v.", hnsResponse, err)
88+
}
89+
}()
90+
8291
// Attach the endpoint.
8392
log.Printf("[net] Attaching endpoint %v to container %v.", hnsResponse.Id, epInfo.ContainerID)
8493
err = hcsshim.HotAttachEndpoint(epInfo.ContainerID, hnsResponse.Id)
8594
if err != nil {
8695
log.Printf("[net] Failed to attach endpoint: %v.", err)
96+
return nil, err
8797
}
8898

8999
// Create the endpoint object.

0 commit comments

Comments
 (0)