 1f8db2467b
			
		
	
	1f8db2467b
	
	
	
		
			
			This contains quite a bit (also bumps google/uuid to 1.3.0). Some HostProcess container improvements to get ready for whenever it goes to stable in Kubernetes, Hyper-V (windows) container support for CRI, and a plethora of other small additions and fixes. Signed-off-by: Daniel Canter <dcanter@microsoft.com>
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| //go:build windows
 | |
| 
 | |
| package computestorage
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"encoding/json"
 | |
| 
 | |
| 	"github.com/Microsoft/hcsshim/internal/oc"
 | |
| 	"github.com/Microsoft/hcsshim/osversion"
 | |
| 	"github.com/pkg/errors"
 | |
| 	"go.opencensus.io/trace"
 | |
| 	"golang.org/x/sys/windows"
 | |
| )
 | |
| 
 | |
| // SetupBaseOSLayer sets up a layer that contains a base OS for a container.
 | |
| //
 | |
| // `layerPath` is a path to a directory containing the layer.
 | |
| //
 | |
| // `vhdHandle` is an empty file handle of `options.Type == OsLayerTypeContainer`
 | |
| // or else it is a file handle to the 'SystemTemplateBase.vhdx' if `options.Type
 | |
| // == OsLayerTypeVm`.
 | |
| //
 | |
| // `options` are the options applied while processing the layer.
 | |
| func SetupBaseOSLayer(ctx context.Context, layerPath string, vhdHandle windows.Handle, options OsLayerOptions) (err error) {
 | |
| 	title := "hcsshim::SetupBaseOSLayer"
 | |
| 	ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
 | |
| 	defer span.End()
 | |
| 	defer func() { oc.SetSpanStatus(span, err) }()
 | |
| 	span.AddAttributes(
 | |
| 		trace.StringAttribute("layerPath", layerPath),
 | |
| 	)
 | |
| 
 | |
| 	bytes, err := json.Marshal(options)
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 
 | |
| 	err = hcsSetupBaseOSLayer(layerPath, vhdHandle, string(bytes))
 | |
| 	if err != nil {
 | |
| 		return errors.Wrap(err, "failed to setup base OS layer")
 | |
| 	}
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| // SetupBaseOSVolume sets up a volume that contains a base OS for a container.
 | |
| //
 | |
| // `layerPath` is a path to a directory containing the layer.
 | |
| //
 | |
| // `volumePath` is the path to the volume to be used for setup.
 | |
| //
 | |
| // `options` are the options applied while processing the layer.
 | |
| //
 | |
| // NOTE: This API is only available on builds of Windows greater than 19645. Inside we
 | |
| // check if the hosts build has the API available by using 'GetVersion' which requires
 | |
| // the calling application to be manifested. https://docs.microsoft.com/en-us/windows/win32/sbscs/manifests
 | |
| func SetupBaseOSVolume(ctx context.Context, layerPath, volumePath string, options OsLayerOptions) (err error) {
 | |
| 	if osversion.Build() < 19645 {
 | |
| 		return errors.New("SetupBaseOSVolume is not present on builds older than 19645")
 | |
| 	}
 | |
| 	title := "hcsshim::SetupBaseOSVolume"
 | |
| 	ctx, span := oc.StartSpan(ctx, title) //nolint:ineffassign,staticcheck
 | |
| 	defer span.End()
 | |
| 	defer func() { oc.SetSpanStatus(span, err) }()
 | |
| 	span.AddAttributes(
 | |
| 		trace.StringAttribute("layerPath", layerPath),
 | |
| 		trace.StringAttribute("volumePath", volumePath),
 | |
| 	)
 | |
| 
 | |
| 	bytes, err := json.Marshal(options)
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 
 | |
| 	err = hcsSetupBaseOSVolume(layerPath, volumePath, string(bytes))
 | |
| 	if err != nil {
 | |
| 		return errors.Wrap(err, "failed to setup base OS layer")
 | |
| 	}
 | |
| 	return nil
 | |
| }
 |