mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #110957 from papagalu/kp_remove_hnsv1
kube-proxy: windows: Removed hnsV1
This commit is contained in:
commit
7d72ccf9a8
@ -29,14 +29,27 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type hnsV2 struct{}
|
||||
type HostNetworkService interface {
|
||||
getNetworkByName(name string) (*hnsNetworkInfo, error)
|
||||
getAllEndpointsByNetwork(networkName string) (map[string]*endpointsInfo, error)
|
||||
getEndpointByID(id string) (*endpointsInfo, error)
|
||||
getEndpointByIpAddress(ip string, networkName string) (*endpointsInfo, error)
|
||||
getEndpointByName(id string) (*endpointsInfo, error)
|
||||
createEndpoint(ep *endpointsInfo, networkName string) (*endpointsInfo, error)
|
||||
deleteEndpoint(hnsID string) error
|
||||
getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFlags, sourceVip string, vip string, protocol uint16, internalPort uint16, externalPort uint16, previousLoadBalancers map[loadBalancerIdentifier]*loadBalancerInfo) (*loadBalancerInfo, error)
|
||||
getAllLoadBalancers() (map[loadBalancerIdentifier]*loadBalancerInfo, error)
|
||||
deleteLoadBalancer(hnsID string) error
|
||||
}
|
||||
|
||||
type hns struct{}
|
||||
|
||||
var (
|
||||
// LoadBalancerFlagsIPv6 enables IPV6.
|
||||
LoadBalancerFlagsIPv6 hcn.LoadBalancerFlags = 2
|
||||
)
|
||||
|
||||
func (hns hnsV2) getNetworkByName(name string) (*hnsNetworkInfo, error) {
|
||||
func (hns hns) getNetworkByName(name string) (*hnsNetworkInfo, error) {
|
||||
hnsnetwork, err := hcn.GetNetworkByName(name)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Error getting network by name")
|
||||
@ -69,7 +82,7 @@ func (hns hnsV2) getNetworkByName(name string) (*hnsNetworkInfo, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (hns hnsV2) getAllEndpointsByNetwork(networkName string) (map[string]*(endpointsInfo), error) {
|
||||
func (hns hns) getAllEndpointsByNetwork(networkName string) (map[string]*(endpointsInfo), error) {
|
||||
hcnnetwork, err := hcn.GetNetworkByName(networkName)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "failed to get HNS network by name", "name", networkName)
|
||||
@ -101,7 +114,7 @@ func (hns hnsV2) getAllEndpointsByNetwork(networkName string) (map[string]*(endp
|
||||
return endpointInfos, nil
|
||||
}
|
||||
|
||||
func (hns hnsV2) getEndpointByID(id string) (*endpointsInfo, error) {
|
||||
func (hns hns) getEndpointByID(id string) (*endpointsInfo, error) {
|
||||
hnsendpoint, err := hcn.GetEndpointByID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -114,7 +127,7 @@ func (hns hnsV2) getEndpointByID(id string) (*endpointsInfo, error) {
|
||||
hns: hns,
|
||||
}, nil
|
||||
}
|
||||
func (hns hnsV2) getEndpointByIpAddress(ip string, networkName string) (*endpointsInfo, error) {
|
||||
func (hns hns) getEndpointByIpAddress(ip string, networkName string) (*endpointsInfo, error) {
|
||||
hnsnetwork, err := hcn.GetNetworkByName(networkName)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "Error getting network by name")
|
||||
@ -146,7 +159,7 @@ func (hns hnsV2) getEndpointByIpAddress(ip string, networkName string) (*endpoin
|
||||
}
|
||||
return nil, fmt.Errorf("Endpoint %v not found on network %s", ip, networkName)
|
||||
}
|
||||
func (hns hnsV2) getEndpointByName(name string) (*endpointsInfo, error) {
|
||||
func (hns hns) getEndpointByName(name string) (*endpointsInfo, error) {
|
||||
hnsendpoint, err := hcn.GetEndpointByName(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -159,7 +172,7 @@ func (hns hnsV2) getEndpointByName(name string) (*endpointsInfo, error) {
|
||||
hns: hns,
|
||||
}, nil
|
||||
}
|
||||
func (hns hnsV2) createEndpoint(ep *endpointsInfo, networkName string) (*endpointsInfo, error) {
|
||||
func (hns hns) createEndpoint(ep *endpointsInfo, networkName string) (*endpointsInfo, error) {
|
||||
hnsNetwork, err := hcn.GetNetworkByName(networkName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -216,7 +229,7 @@ func (hns hnsV2) createEndpoint(ep *endpointsInfo, networkName string) (*endpoin
|
||||
hns: hns,
|
||||
}, nil
|
||||
}
|
||||
func (hns hnsV2) deleteEndpoint(hnsID string) error {
|
||||
func (hns hns) deleteEndpoint(hnsID string) error {
|
||||
hnsendpoint, err := hcn.GetEndpointByID(hnsID)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -228,7 +241,7 @@ func (hns hnsV2) deleteEndpoint(hnsID string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (hns hnsV2) getAllLoadBalancers() (map[loadBalancerIdentifier]*loadBalancerInfo, error) {
|
||||
func (hns hns) getAllLoadBalancers() (map[loadBalancerIdentifier]*loadBalancerInfo, error) {
|
||||
lbs, err := hcn.ListLoadBalancers()
|
||||
var id loadBalancerIdentifier
|
||||
if err != nil {
|
||||
@ -251,7 +264,7 @@ func (hns hnsV2) getAllLoadBalancers() (map[loadBalancerIdentifier]*loadBalancer
|
||||
return loadBalancers, nil
|
||||
}
|
||||
|
||||
func (hns hnsV2) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFlags, sourceVip string, vip string, protocol uint16, internalPort uint16, externalPort uint16, previousLoadBalancers map[loadBalancerIdentifier]*loadBalancerInfo) (*loadBalancerInfo, error) {
|
||||
func (hns hns) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFlags, sourceVip string, vip string, protocol uint16, internalPort uint16, externalPort uint16, previousLoadBalancers map[loadBalancerIdentifier]*loadBalancerInfo) (*loadBalancerInfo, error) {
|
||||
var id loadBalancerIdentifier
|
||||
vips := []string{}
|
||||
if len(vip) > 0 {
|
||||
@ -333,7 +346,7 @@ func (hns hnsV2) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFl
|
||||
return lbInfo, err
|
||||
}
|
||||
|
||||
func (hns hnsV2) deleteLoadBalancer(hnsID string) error {
|
||||
func (hns hns) deleteLoadBalancer(hnsID string) error {
|
||||
lb, err := hcn.GetLoadBalancerByID(hnsID)
|
||||
if err != nil {
|
||||
// Return silently
|
@ -1,315 +0,0 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package winkernel
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/Microsoft/hcsshim"
|
||||
"k8s.io/klog/v2"
|
||||
netutils "k8s.io/utils/net"
|
||||
)
|
||||
|
||||
type HostNetworkService interface {
|
||||
getNetworkByName(name string) (*hnsNetworkInfo, error)
|
||||
getAllEndpointsByNetwork(networkName string) (map[string]*endpointsInfo, error)
|
||||
getEndpointByID(id string) (*endpointsInfo, error)
|
||||
getEndpointByIpAddress(ip string, networkName string) (*endpointsInfo, error)
|
||||
getEndpointByName(id string) (*endpointsInfo, error)
|
||||
createEndpoint(ep *endpointsInfo, networkName string) (*endpointsInfo, error)
|
||||
deleteEndpoint(hnsID string) error
|
||||
getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFlags, sourceVip string, vip string, protocol uint16, internalPort uint16, externalPort uint16, previousLoadBalancers map[loadBalancerIdentifier]*loadBalancerInfo) (*loadBalancerInfo, error)
|
||||
getAllLoadBalancers() (map[loadBalancerIdentifier]*loadBalancerInfo, error)
|
||||
deleteLoadBalancer(hnsID string) error
|
||||
}
|
||||
|
||||
// V1 HNS API
|
||||
type hnsV1 struct{}
|
||||
|
||||
func (hns hnsV1) getNetworkByName(name string) (*hnsNetworkInfo, error) {
|
||||
hnsnetwork, err := hcsshim.GetHNSNetworkByName(name)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "failed to get HNS network by name", "name", name)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &hnsNetworkInfo{
|
||||
id: hnsnetwork.Id,
|
||||
name: hnsnetwork.Name,
|
||||
networkType: hnsnetwork.Type,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (hns hnsV1) getAllEndpointsByNetwork(networkName string) (map[string]*(endpointsInfo), error) {
|
||||
hnsnetwork, err := hcsshim.GetHNSNetworkByName(networkName)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "failed to get HNS network by name", "name", networkName)
|
||||
return nil, err
|
||||
}
|
||||
endpoints, err := hcsshim.HNSListEndpointRequest()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list endpoints: %w", err)
|
||||
}
|
||||
endpointInfos := make(map[string]*(endpointsInfo))
|
||||
for _, endpoint := range endpoints {
|
||||
if strings.EqualFold(endpoint.VirtualNetwork, hnsnetwork.Id) {
|
||||
// Add to map with key endpoint ID or IP address
|
||||
// Storing this is expensive in terms of memory, however there is a bug in Windows Server 2019 that can cause two endpoints to be created with the same IP address.
|
||||
// TODO: Store by IP only and remove any lookups by endpoint ID.
|
||||
endpointInfos[endpoint.Id] = &endpointsInfo{
|
||||
ip: endpoint.IPAddress.String(),
|
||||
isLocal: !endpoint.IsRemoteEndpoint,
|
||||
macAddress: endpoint.MacAddress,
|
||||
hnsID: endpoint.Id,
|
||||
hns: hns,
|
||||
// only ready and not terminating endpoints were added to HNS
|
||||
ready: true,
|
||||
serving: true,
|
||||
terminating: false,
|
||||
}
|
||||
endpointInfos[endpoint.IPAddress.String()] = endpointInfos[endpoint.Id]
|
||||
}
|
||||
}
|
||||
klog.V(3).InfoS("Queried endpoints from network", "network", networkName)
|
||||
return endpointInfos, nil
|
||||
}
|
||||
|
||||
func (hns hnsV1) getEndpointByID(id string) (*endpointsInfo, error) {
|
||||
hnsendpoint, err := hcsshim.GetHNSEndpointByID(id)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "failed to get HNS endpoint by id", "id", id)
|
||||
return nil, err
|
||||
}
|
||||
return &endpointsInfo{
|
||||
ip: hnsendpoint.IPAddress.String(),
|
||||
//TODO: Change isLocal to isRemote
|
||||
isLocal: !hnsendpoint.IsRemoteEndpoint,
|
||||
macAddress: hnsendpoint.MacAddress,
|
||||
hnsID: hnsendpoint.Id,
|
||||
hns: hns,
|
||||
|
||||
// only ready and not terminating endpoints were added to HNS
|
||||
ready: true,
|
||||
serving: true,
|
||||
terminating: false,
|
||||
}, nil
|
||||
}
|
||||
func (hns hnsV1) getEndpointByIpAddress(ip string, networkName string) (*endpointsInfo, error) {
|
||||
hnsnetwork, err := hcsshim.GetHNSNetworkByName(networkName)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "failed to get HNS network by name", "name", networkName)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
endpoints, err := hcsshim.HNSListEndpointRequest()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to list endpoints: %w", err)
|
||||
}
|
||||
for _, endpoint := range endpoints {
|
||||
equal := false
|
||||
if endpoint.IPAddress != nil {
|
||||
equal = endpoint.IPAddress.String() == ip
|
||||
}
|
||||
if equal && strings.EqualFold(endpoint.VirtualNetwork, hnsnetwork.Id) {
|
||||
return &endpointsInfo{
|
||||
ip: endpoint.IPAddress.String(),
|
||||
isLocal: !endpoint.IsRemoteEndpoint,
|
||||
macAddress: endpoint.MacAddress,
|
||||
hnsID: endpoint.Id,
|
||||
hns: hns,
|
||||
|
||||
// only ready and not terminating endpoints were added to HNS
|
||||
ready: true,
|
||||
serving: true,
|
||||
terminating: false,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("Endpoint %v not found on network %s", ip, networkName)
|
||||
}
|
||||
|
||||
func (hns hnsV1) getEndpointByName(name string) (*endpointsInfo, error) {
|
||||
hnsendpoint, err := hcsshim.GetHNSEndpointByName(name)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "failed to get HNS endpoint by name", "name", name)
|
||||
return nil, err
|
||||
}
|
||||
return &endpointsInfo{
|
||||
ip: hnsendpoint.IPAddress.String(),
|
||||
//TODO: Change isLocal to isRemote
|
||||
isLocal: !hnsendpoint.IsRemoteEndpoint,
|
||||
macAddress: hnsendpoint.MacAddress,
|
||||
hnsID: hnsendpoint.Id,
|
||||
hns: hns,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (hns hnsV1) createEndpoint(ep *endpointsInfo, networkName string) (*endpointsInfo, error) {
|
||||
hnsNetwork, err := hcsshim.GetHNSNetworkByName(networkName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hnsEndpoint := &hcsshim.HNSEndpoint{
|
||||
MacAddress: ep.macAddress,
|
||||
IPAddress: netutils.ParseIPSloppy(ep.ip),
|
||||
}
|
||||
|
||||
var createdEndpoint *hcsshim.HNSEndpoint
|
||||
if !ep.isLocal {
|
||||
if len(ep.providerAddress) != 0 {
|
||||
paPolicy := hcsshim.PaPolicy{
|
||||
Type: hcsshim.PA,
|
||||
PA: ep.providerAddress,
|
||||
}
|
||||
paPolicyJson, err := json.Marshal(paPolicy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hnsEndpoint.Policies = append(hnsEndpoint.Policies, paPolicyJson)
|
||||
}
|
||||
createdEndpoint, err = hnsNetwork.CreateRemoteEndpoint(hnsEndpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
} else {
|
||||
createdEndpoint, err = hnsNetwork.CreateEndpoint(hnsEndpoint)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("local endpoint creation failed: %w", err)
|
||||
}
|
||||
}
|
||||
return &endpointsInfo{
|
||||
ip: createdEndpoint.IPAddress.String(),
|
||||
isLocal: createdEndpoint.IsRemoteEndpoint,
|
||||
macAddress: createdEndpoint.MacAddress,
|
||||
hnsID: createdEndpoint.Id,
|
||||
providerAddress: ep.providerAddress, //TODO get from createdEndpoint
|
||||
hns: hns,
|
||||
|
||||
ready: ep.ready,
|
||||
serving: ep.serving,
|
||||
terminating: ep.terminating,
|
||||
}, nil
|
||||
}
|
||||
func (hns hnsV1) deleteEndpoint(hnsID string) error {
|
||||
hnsendpoint, err := hcsshim.GetHNSEndpointByID(hnsID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = hnsendpoint.Delete()
|
||||
if err == nil {
|
||||
klog.V(3).InfoS("Remote endpoint resource deleted id", "id", hnsID)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (hns hnsV1) getAllLoadBalancers() (map[loadBalancerIdentifier]*loadBalancerInfo, error) {
|
||||
plists, err := hcsshim.HNSListPolicyListRequest()
|
||||
var id loadBalancerIdentifier
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
loadBalancers := make(map[loadBalancerIdentifier]*(loadBalancerInfo))
|
||||
for _, plist := range plists {
|
||||
// Validate if input meets any of the policy lists
|
||||
lb := hcsshim.ELBPolicy{}
|
||||
if err = json.Unmarshal(plist.Policies[0], &lb); err != nil {
|
||||
continue
|
||||
}
|
||||
// Policy is ELB policy
|
||||
portMap := lb.LBPolicy
|
||||
if len(lb.VIPs) == 0 {
|
||||
// Leave VIP uninitialized
|
||||
id = loadBalancerIdentifier{protocol: uint16(portMap.Protocol), internalPort: portMap.InternalPort, externalPort: portMap.ExternalPort}
|
||||
} else {
|
||||
id = loadBalancerIdentifier{protocol: portMap.Protocol, internalPort: portMap.InternalPort, externalPort: portMap.ExternalPort, vip: lb.VIPs[0]}
|
||||
}
|
||||
loadBalancers[id] = &loadBalancerInfo{
|
||||
hnsID: plist.ID,
|
||||
}
|
||||
}
|
||||
return loadBalancers, nil
|
||||
}
|
||||
|
||||
func (hns hnsV1) getLoadBalancer(endpoints []endpointsInfo, flags loadBalancerFlags, sourceVip string, vip string, protocol uint16, internalPort uint16, externalPort uint16, previousLoadBalancers map[loadBalancerIdentifier]*loadBalancerInfo) (*loadBalancerInfo, error) {
|
||||
if flags.isDSR {
|
||||
klog.V(3).InfoS("DSR is not supported in V1. Using non DSR instead")
|
||||
}
|
||||
var id loadBalancerIdentifier
|
||||
if len(vip) > 0 {
|
||||
id = loadBalancerIdentifier{protocol: protocol, internalPort: internalPort, externalPort: externalPort, vip: vip, endpointsCount: len(endpoints)}
|
||||
} else {
|
||||
id = loadBalancerIdentifier{protocol: protocol, internalPort: internalPort, externalPort: externalPort, endpointsCount: len(endpoints)}
|
||||
}
|
||||
|
||||
if lb, found := previousLoadBalancers[id]; found {
|
||||
klog.V(1).InfoS("Found existing Hns loadbalancer policy resource", "policies", lb)
|
||||
return lb, nil
|
||||
}
|
||||
|
||||
var hnsEndpoints []hcsshim.HNSEndpoint
|
||||
for _, ep := range endpoints {
|
||||
endpoint, err := hcsshim.GetHNSEndpointByID(ep.hnsID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hnsEndpoints = append(hnsEndpoints, *endpoint)
|
||||
}
|
||||
lb, err := hcsshim.AddLoadBalancer(
|
||||
hnsEndpoints,
|
||||
flags.isILB,
|
||||
sourceVip,
|
||||
vip,
|
||||
protocol,
|
||||
internalPort,
|
||||
externalPort,
|
||||
)
|
||||
|
||||
if err == nil {
|
||||
klog.V(1).InfoS("Hns loadbalancer policy resource", "policies", lb)
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
lbInfo := &loadBalancerInfo{
|
||||
hnsID: lb.ID,
|
||||
}
|
||||
// Add to map of load balancers
|
||||
previousLoadBalancers[id] = lbInfo
|
||||
return lbInfo, err
|
||||
}
|
||||
func (hns hnsV1) deleteLoadBalancer(hnsID string) error {
|
||||
if len(hnsID) == 0 {
|
||||
// Return silently
|
||||
return nil
|
||||
}
|
||||
|
||||
// Cleanup HNS policies
|
||||
hnsloadBalancer, err := hcsshim.GetPolicyListByID(hnsID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
klog.V(2).InfoS("Removing Policy", "policies", hnsloadBalancer)
|
||||
|
||||
_, err = hnsloadBalancer.Delete()
|
||||
return err
|
||||
}
|
@ -45,76 +45,7 @@ const (
|
||||
)
|
||||
|
||||
func TestGetNetworkByName(t *testing.T) {
|
||||
hnsV1 := hnsV1{}
|
||||
hnsV2 := hnsV2{}
|
||||
|
||||
testGetNetworkByName(t, hnsV1)
|
||||
testGetNetworkByName(t, hnsV2)
|
||||
}
|
||||
func TestGetEndpointByID(t *testing.T) {
|
||||
hnsV1 := hnsV1{}
|
||||
hnsV2 := hnsV2{}
|
||||
|
||||
testGetEndpointByID(t, hnsV1)
|
||||
testGetEndpointByID(t, hnsV2)
|
||||
}
|
||||
func TestGetEndpointByIpAddressAndName(t *testing.T) {
|
||||
hnsV1 := hnsV1{}
|
||||
hnsV2 := hnsV2{}
|
||||
|
||||
testGetEndpointByIpAddressAndName(t, hnsV1)
|
||||
testGetEndpointByIpAddressAndName(t, hnsV2)
|
||||
}
|
||||
func TestCreateEndpointLocal(t *testing.T) {
|
||||
hnsV1 := hnsV1{}
|
||||
hnsV2 := hnsV2{}
|
||||
|
||||
testCreateEndpointLocal(t, hnsV1)
|
||||
testCreateEndpointLocal(t, hnsV2)
|
||||
}
|
||||
func TestCreateEndpointRemotePA(t *testing.T) {
|
||||
hnsV1 := hnsV1{}
|
||||
hnsV2 := hnsV2{}
|
||||
|
||||
testCreateEndpointRemote(t, hnsV1, epPaAddress)
|
||||
testCreateEndpointRemote(t, hnsV2, epPaAddress)
|
||||
}
|
||||
func TestCreateEndpointRemoteNoPA(t *testing.T) {
|
||||
hnsV1 := hnsV1{}
|
||||
hnsV2 := hnsV2{}
|
||||
|
||||
testCreateEndpointRemote(t, hnsV1, "")
|
||||
testCreateEndpointRemote(t, hnsV2, "")
|
||||
}
|
||||
func TestDeleteEndpoint(t *testing.T) {
|
||||
hnsV1 := hnsV1{}
|
||||
hnsV2 := hnsV2{}
|
||||
|
||||
testDeleteEndpoint(t, hnsV1)
|
||||
testDeleteEndpoint(t, hnsV2)
|
||||
}
|
||||
func TestGetLoadBalancerExisting(t *testing.T) {
|
||||
hnsV1 := hnsV1{}
|
||||
hnsV2 := hnsV2{}
|
||||
|
||||
testGetLoadBalancerExisting(t, hnsV1)
|
||||
testGetLoadBalancerExisting(t, hnsV2)
|
||||
}
|
||||
func TestGetLoadBalancerNew(t *testing.T) {
|
||||
hnsV1 := hnsV1{}
|
||||
hnsV2 := hnsV2{}
|
||||
|
||||
testGetLoadBalancerNew(t, hnsV1)
|
||||
testGetLoadBalancerNew(t, hnsV2)
|
||||
}
|
||||
func TestDeleteLoadBalancer(t *testing.T) {
|
||||
hnsV1 := hnsV1{}
|
||||
hnsV2 := hnsV2{}
|
||||
|
||||
testDeleteLoadBalancer(t, hnsV1)
|
||||
testDeleteLoadBalancer(t, hnsV2)
|
||||
}
|
||||
func testGetNetworkByName(t *testing.T, hns HostNetworkService) {
|
||||
hns := hns{}
|
||||
Network := mustTestNetwork(t)
|
||||
|
||||
network, err := hns.getNetworkByName(Network.Name)
|
||||
@ -130,7 +61,9 @@ func testGetNetworkByName(t *testing.T, hns HostNetworkService) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func testGetEndpointByID(t *testing.T, hns HostNetworkService) {
|
||||
|
||||
func TestGetEndpointByID(t *testing.T) {
|
||||
hns := hns{}
|
||||
Network := mustTestNetwork(t)
|
||||
|
||||
ipConfig := &hcn.IpConfig{
|
||||
@ -167,7 +100,9 @@ func testGetEndpointByID(t *testing.T, hns HostNetworkService) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func testGetEndpointByIpAddressAndName(t *testing.T, hns HostNetworkService) {
|
||||
|
||||
func TestGetEndpointByIpAddressAndName(t *testing.T) {
|
||||
hns := hns{}
|
||||
Network := mustTestNetwork(t)
|
||||
|
||||
ipConfig := &hcn.IpConfig{
|
||||
@ -215,7 +150,9 @@ func testGetEndpointByIpAddressAndName(t *testing.T, hns HostNetworkService) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func testCreateEndpointLocal(t *testing.T, hns HostNetworkService) {
|
||||
|
||||
func TestCreateEndpointLocal(t *testing.T) {
|
||||
hns := hns{}
|
||||
Network := mustTestNetwork(t)
|
||||
|
||||
endpoint := &endpointsInfo{
|
||||
@ -251,8 +188,11 @@ func testCreateEndpointLocal(t *testing.T, hns HostNetworkService) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func testCreateEndpointRemote(t *testing.T, hns HostNetworkService, providerAddress string) {
|
||||
|
||||
func TestCreateEndpointRemote(t *testing.T) {
|
||||
hns := hns{}
|
||||
Network := mustTestNetwork(t)
|
||||
providerAddress := epPaAddress
|
||||
|
||||
endpoint := &endpointsInfo{
|
||||
ip: epIpAddressRemote,
|
||||
@ -291,7 +231,9 @@ func testCreateEndpointRemote(t *testing.T, hns HostNetworkService, providerAddr
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func testDeleteEndpoint(t *testing.T, hns HostNetworkService) {
|
||||
|
||||
func TestDeleteEndpoint(t *testing.T) {
|
||||
hns := hns{}
|
||||
Network := mustTestNetwork(t)
|
||||
|
||||
ipConfig := &hcn.IpConfig{
|
||||
@ -325,7 +267,8 @@ func testDeleteEndpoint(t *testing.T, hns HostNetworkService) {
|
||||
}
|
||||
}
|
||||
|
||||
func testGetLoadBalancerExisting(t *testing.T, hns HostNetworkService) {
|
||||
func TestGetLoadBalancerExisting(t *testing.T) {
|
||||
hns := hns{}
|
||||
Network := mustTestNetwork(t)
|
||||
lbs := make(map[loadBalancerIdentifier]*(loadBalancerInfo))
|
||||
|
||||
@ -369,6 +312,7 @@ func testGetLoadBalancerExisting(t *testing.T, hns HostNetworkService) {
|
||||
}
|
||||
endpoints := []endpointsInfo{*endpoint}
|
||||
lb, err := hns.getLoadBalancer(endpoints, loadBalancerFlags{}, sourceVip, serviceVip, protocol, internalPort, externalPort, lbs)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -390,7 +334,9 @@ func testGetLoadBalancerExisting(t *testing.T, hns HostNetworkService) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func testGetLoadBalancerNew(t *testing.T, hns HostNetworkService) {
|
||||
|
||||
func TestGetLoadBalancerNew(t *testing.T) {
|
||||
hns := hns{}
|
||||
Network := mustTestNetwork(t)
|
||||
// We keep this empty to ensure we test for new load balancer creation.
|
||||
lbs := make(map[loadBalancerIdentifier]*(loadBalancerInfo))
|
||||
@ -440,7 +386,9 @@ func testGetLoadBalancerNew(t *testing.T, hns HostNetworkService) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func testDeleteLoadBalancer(t *testing.T, hns HostNetworkService) {
|
||||
|
||||
func TestDeleteLoadBalancer(t *testing.T) {
|
||||
hns := hns{}
|
||||
Network := mustTestNetwork(t)
|
||||
|
||||
ipConfig := &hcn.IpConfig{
|
||||
@ -492,6 +440,7 @@ func testDeleteLoadBalancer(t *testing.T, hns HostNetworkService) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func mustTestNetwork(t *testing.T) *hcn.HostComputeNetwork {
|
||||
network, err := createTestNetwork()
|
||||
if err != nil {
|
||||
@ -502,6 +451,7 @@ func mustTestNetwork(t *testing.T) *hcn.HostComputeNetwork {
|
||||
}
|
||||
return network
|
||||
}
|
||||
|
||||
func createTestNetwork() (*hcn.HostComputeNetwork, error) {
|
||||
network := &hcn.HostComputeNetwork{
|
||||
Type: NETWORK_TYPE_OVERLAY,
|
||||
|
@ -146,14 +146,15 @@ type remoteSubnetInfo struct {
|
||||
const NETWORK_TYPE_OVERLAY = "overlay"
|
||||
|
||||
func newHostNetworkService() (HostNetworkService, hcn.SupportedFeatures) {
|
||||
var hns HostNetworkService
|
||||
hns = hnsV1{}
|
||||
var h HostNetworkService
|
||||
supportedFeatures := hcn.GetSupportedFeatures()
|
||||
if supportedFeatures.Api.V2 {
|
||||
hns = hnsV2{}
|
||||
h = hns{}
|
||||
} else {
|
||||
panic("Windows HNS Api V2 required. This version of windows does not support API V2")
|
||||
}
|
||||
|
||||
return hns, supportedFeatures
|
||||
return h, supportedFeatures
|
||||
}
|
||||
|
||||
func getNetworkName(hnsNetworkName string) (string, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user