mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
This tag of hcsshim brings in a couple welcome features/improvements. One being exposing a way to query for hns endpoint statistics (Packets received/sent etc.). This tag also contains some optimizations for querying whether a certain HCN feature is supported, which is a common workflow in kube-proxy on Windows. The first result from querying HCN is now cached so further calls can skip the hcn query as well as the version range parsing that was performed. This also gets rid of some redundant logs that used to hit everytime the version range parsing occurred. The Go-winio dep bump, and all of the ctrd deps are transitive only. Nothing new is needed/intended to be used. Signed-off-by: Daniel Canter <dcanter@microsoft.com>
119 lines
3.4 KiB
Go
119 lines
3.4 KiB
Go
package hcsshim
|
|
|
|
import (
|
|
"github.com/Microsoft/hcsshim/internal/hns"
|
|
)
|
|
|
|
// HNSEndpoint represents a network endpoint in HNS
|
|
type HNSEndpoint = hns.HNSEndpoint
|
|
|
|
// HNSEndpointStats represent the stats for an networkendpoint in HNS
|
|
type HNSEndpointStats = hns.EndpointStats
|
|
|
|
// Namespace represents a Compartment.
|
|
type Namespace = hns.Namespace
|
|
|
|
//SystemType represents the type of the system on which actions are done
|
|
type SystemType string
|
|
|
|
// SystemType const
|
|
const (
|
|
ContainerType SystemType = "Container"
|
|
VirtualMachineType SystemType = "VirtualMachine"
|
|
HostType SystemType = "Host"
|
|
)
|
|
|
|
// EndpointAttachDetachRequest is the structure used to send request to the container to modify the system
|
|
// Supported resource types are Network and Request Types are Add/Remove
|
|
type EndpointAttachDetachRequest = hns.EndpointAttachDetachRequest
|
|
|
|
// EndpointResquestResponse is object to get the endpoint request response
|
|
type EndpointResquestResponse = hns.EndpointResquestResponse
|
|
|
|
// HNSEndpointRequest makes a HNS call to modify/query a network endpoint
|
|
func HNSEndpointRequest(method, path, request string) (*HNSEndpoint, error) {
|
|
return hns.HNSEndpointRequest(method, path, request)
|
|
}
|
|
|
|
// HNSListEndpointRequest makes a HNS call to query the list of available endpoints
|
|
func HNSListEndpointRequest() ([]HNSEndpoint, error) {
|
|
return hns.HNSListEndpointRequest()
|
|
}
|
|
|
|
// HotAttachEndpoint makes a HCS Call to attach the endpoint to the container
|
|
func HotAttachEndpoint(containerID string, endpointID string) error {
|
|
endpoint, err := GetHNSEndpointByID(endpointID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
isAttached, err := endpoint.IsAttached(containerID)
|
|
if isAttached {
|
|
return err
|
|
}
|
|
return modifyNetworkEndpoint(containerID, endpointID, Add)
|
|
}
|
|
|
|
// HotDetachEndpoint makes a HCS Call to detach the endpoint from the container
|
|
func HotDetachEndpoint(containerID string, endpointID string) error {
|
|
endpoint, err := GetHNSEndpointByID(endpointID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
isAttached, err := endpoint.IsAttached(containerID)
|
|
if !isAttached {
|
|
return err
|
|
}
|
|
return modifyNetworkEndpoint(containerID, endpointID, Remove)
|
|
}
|
|
|
|
// ModifyContainer corresponding to the container id, by sending a request
|
|
func modifyContainer(id string, request *ResourceModificationRequestResponse) error {
|
|
container, err := OpenContainer(id)
|
|
if err != nil {
|
|
if IsNotExist(err) {
|
|
return ErrComputeSystemDoesNotExist
|
|
}
|
|
return getInnerError(err)
|
|
}
|
|
defer container.Close()
|
|
err = container.Modify(request)
|
|
if err != nil {
|
|
if IsNotSupported(err) {
|
|
return ErrPlatformNotSupported
|
|
}
|
|
return getInnerError(err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func modifyNetworkEndpoint(containerID string, endpointID string, request RequestType) error {
|
|
requestMessage := &ResourceModificationRequestResponse{
|
|
Resource: Network,
|
|
Request: request,
|
|
Data: endpointID,
|
|
}
|
|
err := modifyContainer(containerID, requestMessage)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// GetHNSEndpointByID get the Endpoint by ID
|
|
func GetHNSEndpointByID(endpointID string) (*HNSEndpoint, error) {
|
|
return hns.GetHNSEndpointByID(endpointID)
|
|
}
|
|
|
|
// GetHNSEndpointByName gets the endpoint filtered by Name
|
|
func GetHNSEndpointByName(endpointName string) (*HNSEndpoint, error) {
|
|
return hns.GetHNSEndpointByName(endpointName)
|
|
}
|
|
|
|
// GetHNSEndpointStats gets the endpoint stats by ID
|
|
func GetHNSEndpointStats(endpointName string) (*HNSEndpointStats, error) {
|
|
return hns.GetHNSEndpointStats(endpointName)
|
|
}
|