k8s.io/kubernetes@v1.29.3/pkg/proxy/winkernel/hcnutils.go (about) 1 //go:build windows 2 // +build windows 3 4 /* 5 Copyright 2018 The Kubernetes Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 */ 19 20 package winkernel 21 22 import ( 23 "github.com/Microsoft/hcsshim" 24 "github.com/Microsoft/hcsshim/hcn" 25 "k8s.io/klog/v2" 26 ) 27 28 type HcnService interface { 29 // Network functions 30 GetNetworkByName(networkName string) (*hcn.HostComputeNetwork, error) 31 GetNetworkByID(networkID string) (*hcn.HostComputeNetwork, error) 32 // Endpoint functions 33 ListEndpoints() ([]hcn.HostComputeEndpoint, error) 34 ListEndpointsOfNetwork(networkId string) ([]hcn.HostComputeEndpoint, error) 35 GetEndpointByID(endpointId string) (*hcn.HostComputeEndpoint, error) 36 GetEndpointByName(endpointName string) (*hcn.HostComputeEndpoint, error) 37 CreateEndpoint(network *hcn.HostComputeNetwork, endpoint *hcn.HostComputeEndpoint) (*hcn.HostComputeEndpoint, error) 38 CreateRemoteEndpoint(network *hcn.HostComputeNetwork, endpoint *hcn.HostComputeEndpoint) (*hcn.HostComputeEndpoint, error) 39 DeleteEndpoint(endpoint *hcn.HostComputeEndpoint) error 40 // LoadBalancer functions 41 ListLoadBalancers() ([]hcn.HostComputeLoadBalancer, error) 42 GetLoadBalancerByID(loadBalancerId string) (*hcn.HostComputeLoadBalancer, error) 43 CreateLoadBalancer(loadBalancer *hcn.HostComputeLoadBalancer) (*hcn.HostComputeLoadBalancer, error) 44 DeleteLoadBalancer(loadBalancer *hcn.HostComputeLoadBalancer) error 45 // Features functions 46 GetSupportedFeatures() hcn.SupportedFeatures 47 Ipv6DualStackSupported() error 48 DsrSupported() error 49 // Policy functions 50 DeleteAllHnsLoadBalancerPolicy() 51 } 52 53 type hcnImpl struct{} 54 55 func newHcnImpl() hcnImpl { 56 return hcnImpl{} 57 } 58 59 func (hcnObj hcnImpl) GetNetworkByName(networkName string) (*hcn.HostComputeNetwork, error) { 60 return hcn.GetNetworkByName(networkName) 61 } 62 63 func (hcnObj hcnImpl) GetNetworkByID(networkID string) (*hcn.HostComputeNetwork, error) { 64 return hcn.GetNetworkByID(networkID) 65 } 66 67 func (hcnObj hcnImpl) ListEndpoints() ([]hcn.HostComputeEndpoint, error) { 68 return hcn.ListEndpoints() 69 } 70 71 func (hcnObj hcnImpl) ListEndpointsOfNetwork(networkId string) ([]hcn.HostComputeEndpoint, error) { 72 return hcn.ListEndpointsOfNetwork(networkId) 73 } 74 75 func (hcnObj hcnImpl) GetEndpointByID(endpointId string) (*hcn.HostComputeEndpoint, error) { 76 return hcn.GetEndpointByID(endpointId) 77 } 78 79 func (hcnObj hcnImpl) GetEndpointByName(endpointName string) (*hcn.HostComputeEndpoint, error) { 80 return hcn.GetEndpointByName(endpointName) 81 } 82 83 func (hcnObj hcnImpl) CreateEndpoint(network *hcn.HostComputeNetwork, endpoint *hcn.HostComputeEndpoint) (*hcn.HostComputeEndpoint, error) { 84 return network.CreateEndpoint(endpoint) 85 } 86 87 func (hcnObj hcnImpl) CreateRemoteEndpoint(network *hcn.HostComputeNetwork, endpoint *hcn.HostComputeEndpoint) (*hcn.HostComputeEndpoint, error) { 88 return network.CreateRemoteEndpoint(endpoint) 89 } 90 91 func (hcnObj hcnImpl) DeleteEndpoint(endpoint *hcn.HostComputeEndpoint) error { 92 return endpoint.Delete() 93 } 94 95 func (hcnObj hcnImpl) ListLoadBalancers() ([]hcn.HostComputeLoadBalancer, error) { 96 return hcn.ListLoadBalancers() 97 } 98 99 func (hcnObj hcnImpl) GetLoadBalancerByID(loadBalancerId string) (*hcn.HostComputeLoadBalancer, error) { 100 return hcn.GetLoadBalancerByID(loadBalancerId) 101 } 102 103 func (hcnObj hcnImpl) CreateLoadBalancer(loadBalancer *hcn.HostComputeLoadBalancer) (*hcn.HostComputeLoadBalancer, error) { 104 return loadBalancer.Create() 105 } 106 107 func (hcnObj hcnImpl) DeleteLoadBalancer(loadBalancer *hcn.HostComputeLoadBalancer) error { 108 return loadBalancer.Delete() 109 } 110 111 func (hcnObj hcnImpl) GetSupportedFeatures() hcn.SupportedFeatures { 112 return hcn.GetSupportedFeatures() 113 } 114 115 func (hcnObj hcnImpl) Ipv6DualStackSupported() error { 116 return hcn.IPv6DualStackSupported() 117 } 118 119 func (hcnObj hcnImpl) DsrSupported() error { 120 return hcn.DSRSupported() 121 } 122 123 func (hcnObj hcnImpl) DeleteAllHnsLoadBalancerPolicy() { 124 plists, err := hcsshim.HNSListPolicyListRequest() 125 if err != nil { 126 return 127 } 128 for _, plist := range plists { 129 klog.V(3).InfoS("Remove policy", "policies", plist) 130 _, err = plist.Delete() 131 if err != nil { 132 klog.ErrorS(err, "Failed to delete policy list") 133 } 134 } 135 }