full diff: https://2226e083fc390003ae5aa8325c3c92789afa0e7a...b3f49c06ffaeef24d09c6c08ec8ec8425a0303e2 includes: - microsoft/hcsshim#718 wclayer: Work around Windows bug when expanding sandbox size - fixes microsoft/hcsshim#708 Windows Host Compute Service bug breaks docker (and other) sandboxes bigger than 20G on Windows 1903 - fixes microsoft/hcsshim#624The hcsshim on Windows 10 1903 always fails to build Docker image - fixes/addresses docker/for-win#3884 An error occurred while attempting to build Docker image (especially this comment and the next comments after: https://github.com/docker/for-win/issues/3884#issuecomment-498939672) - fixes/addresses docker/for-win#4100 Windows 1903 fails when storage-opt used - fixes moby/moby#36831 hcsshim::PrepareLayer failed in Win32: The parameter is incorrect (https://github.com/moby/moby/issues/36831#issuecomment-498612392) - fixes Stannieman/audacity-with-asio-builder#5 Docker won't build container - fixes MicrosoftDocs/visualstudio-docs#3523 Error when running build with storage-opts set - fixes moby/moby#39524 Docker build windows 19.03 --storage-opt size>20G Note that this is a temporary workaround for a bug in the platform, and will be reverted once that is addressed: - microsoft/hcsshim#721 Revert 718 when Windows 19H1 has expand sandbox fix Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
105 lines
3.1 KiB
Go
105 lines
3.1 KiB
Go
package hcsshim
|
|
|
|
import (
|
|
"github.com/Microsoft/hcsshim/internal/hns"
|
|
)
|
|
|
|
// HNSEndpoint represents a network endpoint in HNS
|
|
type HNSEndpoint = hns.HNSEndpoint
|
|
|
|
// 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)
|
|
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)
|
|
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)
|
|
}
|