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
54 changes: 29 additions & 25 deletions network/hnswrapper/hnsv2wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,65 +13,69 @@ import (
type Hnsv2wrapper struct{}

func (Hnsv2wrapper) CreateEndpoint(endpoint *hcn.HostComputeEndpoint) (*hcn.HostComputeEndpoint, error) {
return endpoint.Create()
return endpoint.Create() // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (Hnsv2wrapper) DeleteEndpoint(endpoint *hcn.HostComputeEndpoint) error {
return endpoint.Delete()
return endpoint.Delete() // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (Hnsv2wrapper) CreateNetwork(network *hcn.HostComputeNetwork) (*hcn.HostComputeNetwork, error) {
return network.Create()
return network.Create() // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (Hnsv2wrapper) DeleteNetwork(network *hcn.HostComputeNetwork) error {
return network.Delete()
return network.Delete() // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (Hnsv2wrapper) ModifyNetworkSettings(network *hcn.HostComputeNetwork, request *hcn.ModifyNetworkSettingRequest) error {
return network.ModifyNetworkSettings(request)
return network.ModifyNetworkSettings(request) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (Hnsv2wrapper) AddNetworkPolicy(network *hcn.HostComputeNetwork, networkPolicy hcn.PolicyNetworkRequest) error {
return network.AddPolicy(networkPolicy)
return network.AddPolicy(networkPolicy) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (Hnsv2wrapper) RemoveNetworkPolicy(network *hcn.HostComputeNetwork, networkPolicy hcn.PolicyNetworkRequest) error {
return network.RemovePolicy(networkPolicy)
return network.RemovePolicy(networkPolicy) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (w Hnsv2wrapper) GetNamespaceByID(netNamespacePath string) (*hcn.HostComputeNamespace, error) {
return hcn.GetNamespaceByID(netNamespacePath)
func (Hnsv2wrapper) GetNamespaceByID(netNamespacePath string) (*hcn.HostComputeNamespace, error) {
return hcn.GetNamespaceByID(netNamespacePath) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (w Hnsv2wrapper) AddNamespaceEndpoint(namespaceId string, endpointId string) error {
return hcn.AddNamespaceEndpoint(namespaceId, endpointId)
func (Hnsv2wrapper) AddNamespaceEndpoint(namespaceID, endpointID string) error {
return hcn.AddNamespaceEndpoint(namespaceID, endpointID) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (w Hnsv2wrapper) RemoveNamespaceEndpoint(namespaceId string, endpointId string) error {
return hcn.RemoveNamespaceEndpoint(namespaceId, endpointId)
func (Hnsv2wrapper) RemoveNamespaceEndpoint(namespaceID, endpointID string) error {
return hcn.RemoveNamespaceEndpoint(namespaceID, endpointID) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (w Hnsv2wrapper) GetNetworkByName(networkName string) (*hcn.HostComputeNetwork, error) {
return hcn.GetNetworkByName(networkName)
func (Hnsv2wrapper) GetNetworkByName(networkName string) (*hcn.HostComputeNetwork, error) {
return hcn.GetNetworkByName(networkName) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (w Hnsv2wrapper) GetNetworkByID(networkId string) (*hcn.HostComputeNetwork, error) {
return hcn.GetNetworkByID(networkId)
func (Hnsv2wrapper) GetNetworkByID(networkID string) (*hcn.HostComputeNetwork, error) {
return hcn.GetNetworkByID(networkID) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (f Hnsv2wrapper) GetEndpointByID(endpointId string) (*hcn.HostComputeEndpoint, error) {
return hcn.GetEndpointByID(endpointId)
func (Hnsv2wrapper) GetEndpointByID(endpointID string) (*hcn.HostComputeEndpoint, error) {
return hcn.GetEndpointByID(endpointID) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (f Hnsv2wrapper) ListEndpointsOfNetwork(networkId string) ([]hcn.HostComputeEndpoint, error) {
return hcn.ListEndpointsOfNetwork(networkId)
func (Hnsv2wrapper) ListEndpointsOfNetwork(networkID string) ([]hcn.HostComputeEndpoint, error) {
return hcn.ListEndpointsOfNetwork(networkID) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (f Hnsv2wrapper) ApplyEndpointPolicy(endpoint *hcn.HostComputeEndpoint, requestType hcn.RequestType, endpointPolicy hcn.PolicyEndpointRequest) error {
return endpoint.ApplyPolicy(requestType, endpointPolicy)
func (Hnsv2wrapper) ListEndpointsQuery(query hcn.HostComputeQuery) ([]hcn.HostComputeEndpoint, error) {
return hcn.ListEndpointsQuery(query) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (f Hnsv2wrapper) GetEndpointByName(endpointName string) (*hcn.HostComputeEndpoint, error) {
return hcn.GetEndpointByName(endpointName)
func (Hnsv2wrapper) ApplyEndpointPolicy(endpoint *hcn.HostComputeEndpoint, requestType hcn.RequestType, endpointPolicy hcn.PolicyEndpointRequest) error {
return endpoint.ApplyPolicy(requestType, endpointPolicy) // nolint:wrapcheck // no need to wrap check for this wrapper
}

func (Hnsv2wrapper) GetEndpointByName(endpointName string) (*hcn.HostComputeEndpoint, error) {
return hcn.GetEndpointByName(endpointName) // nolint:wrapcheck // no need to wrap check for this wrapper
}
25 changes: 23 additions & 2 deletions network/hnswrapper/hnsv2wrapperfake.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ func (f Hnsv2wrapperFake) ListEndpointsOfNetwork(networkId string) ([]hcn.HostCo
return endpoints, nil
}

// NOTE: hard assumption that the query just filters for local endpoints via hcn.EndpointFlagsNone
func (f Hnsv2wrapperFake) ListEndpointsQuery(_ hcn.HostComputeQuery) ([]hcn.HostComputeEndpoint, error) {
f.Lock()
defer f.Unlock()
delayHnsCall(f.Delay)
endpoints := make([]hcn.HostComputeEndpoint, 0)
for _, endpoint := range f.Cache.endpoints {
e := *endpoint.GetHCNObj()
if e.Flags == hcn.EndpointFlagsNone {
// only get local endpoints
endpoints = append(endpoints, e)
}
}
return endpoints, nil
}

func (f Hnsv2wrapperFake) ApplyEndpointPolicy(endpoint *hcn.HostComputeEndpoint, requestType hcn.RequestType, endpointPolicy hcn.PolicyEndpointRequest) error {
f.Lock()
defer f.Unlock()
Expand Down Expand Up @@ -386,11 +402,13 @@ func (fCache FakeHNSCache) ACLPolicies(epList map[string]string, policyID string
return aclPols, nil
}

// GetAllACLs maps all Endpoint IDs to ACLs
// GetAllACLs maps all local Endpoint IDs to ACLs
func (fCache FakeHNSCache) GetAllACLs() map[string][]*FakeEndpointPolicy {
aclPols := make(map[string][]*FakeEndpointPolicy)
for _, ep := range fCache.endpoints {
aclPols[ep.ID] = ep.Policies
if ep.Flags == hcn.EndpointFlagsNone {
aclPols[ep.ID] = ep.Policies
}
}
return aclPols
}
Expand Down Expand Up @@ -456,6 +474,7 @@ type FakeHostComputeEndpoint struct {
HostComputeNetwork string
Policies []*FakeEndpointPolicy
IPConfiguration string
Flags hcn.EndpointFlags
}

func NewFakeHostComputeEndpoint(endpoint *hcn.HostComputeEndpoint) *FakeHostComputeEndpoint {
Expand All @@ -468,6 +487,7 @@ func NewFakeHostComputeEndpoint(endpoint *hcn.HostComputeEndpoint) *FakeHostComp
Name: endpoint.Name,
HostComputeNetwork: endpoint.HostComputeNetwork,
IPConfiguration: ip,
Flags: endpoint.Flags,
}
}

Expand Down Expand Up @@ -505,6 +525,7 @@ func (fEndpoint *FakeHostComputeEndpoint) GetHCNObj() *hcn.HostComputeEndpoint {
},
},
Policies: acls,
Flags: fEndpoint.Flags,
}
}

Expand Down
1 change: 1 addition & 0 deletions network/hnswrapper/hnsv2wrapperinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type HnsV2WrapperInterface interface {
GetNetworkByID(networkId string) (*hcn.HostComputeNetwork, error)
GetEndpointByID(endpointId string) (*hcn.HostComputeEndpoint, error)
ListEndpointsOfNetwork(networkId string) ([]hcn.HostComputeEndpoint, error)
ListEndpointsQuery(query hcn.HostComputeQuery) ([]hcn.HostComputeEndpoint, error)
ApplyEndpointPolicy(endpoint *hcn.HostComputeEndpoint, requestType hcn.RequestType, endpointPolicy hcn.PolicyEndpointRequest) error
GetEndpointByName(endpointName string) (*hcn.HostComputeEndpoint, error)
}
24 changes: 24 additions & 0 deletions network/hnswrapper/hnsv2wrapperwithtimeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,30 @@ func (h Hnsv2wrapperwithtimeout) ListEndpointsOfNetwork(networkId string) ([]hcn
}
}

// NOTE see assumptions of hnsv2wrapperfake.ListEndpointsQuery
func (h Hnsv2wrapperwithtimeout) ListEndpointsQuery(query hcn.HostComputeQuery) ([]hcn.HostComputeEndpoint, error) {
// must be a buffered chan of size 1, otherwise it leaks goroutines when trying to send to the channel after the timeout has fired
r := make(chan ListEndpointsFuncResult, 1)
ctx, cancel := context.WithTimeout(context.TODO(), h.HnsCallTimeout)
defer cancel()
go func() {
endpoints, err := h.Hnsv2.ListEndpointsQuery(query)

r <- ListEndpointsFuncResult{
endpoints: endpoints,
Err: err,
}
}()

// Listen on our channel AND a timeout channel - which ever happens first.
select {
case res := <-r:
return res.endpoints, res.Err
case <-ctx.Done():
return nil, errors.Wrapf(ErrHNSCallTimeout, "ListEndpointsOfNetwork, timeout value is %s seconds", h.HnsCallTimeout.String())
}
}

func (h Hnsv2wrapperwithtimeout) ApplyEndpointPolicy(endpoint *hcn.HostComputeEndpoint, requestType hcn.RequestType, endpointPolicy hcn.PolicyEndpointRequest) error {
r := make(chan error)
ctx, cancel := context.WithTimeout(context.TODO(), h.HnsCallTimeout)
Expand Down
Loading