Skip to content

Commit

Permalink
Refactor hcs internal pkg
Browse files Browse the repository at this point in the history
k/k repo using ContainerProperties and NetworkStats struct from hcs internal pkg.
Due to this the whole hcsshim pkg is having to be imported in k/k. This commit
helps to restructure the pkg and maintain submodule to ensure that only this pkg
is imported in k/k

Signed-off-by: Kirtana Ashok <[email protected]>
  • Loading branch information
kiashok committed Sep 18, 2024
1 parent 0b833cc commit 7aa4739
Show file tree
Hide file tree
Showing 36 changed files with 600 additions and 123 deletions.
4 changes: 2 additions & 2 deletions cmd/containerd-shim-runhcs-v1/task_hcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import (
"github.com/Microsoft/go-winio/pkg/fs"
runhcsopts "github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/stats"
hcstypes "github.com/Microsoft/hcsshim/hcs"
"github.com/Microsoft/hcsshim/internal/cmd"
"github.com/Microsoft/hcsshim/internal/cow"
"github.com/Microsoft/hcsshim/internal/guestpath"
"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/hcs/resourcepaths"
"github.com/Microsoft/hcsshim/internal/hcs/schema1"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
"github.com/Microsoft/hcsshim/internal/hcsoci"
"github.com/Microsoft/hcsshim/internal/jobcontainers"
Expand Down Expand Up @@ -570,7 +570,7 @@ func (ht *hcsTask) Pids(ctx context.Context) ([]*runhcsopts.ProcessDetails, erro
pidMap[ht.init.Pid()] = ht.init.ID()

// Get the guest pids
props, err := ht.c.Properties(ctx, schema1.PropertyTypeProcessList)
props, err := ht.c.Properties(ctx, hcstypes.PropertyTypeProcessList)
if err != nil {
if isStatsNotFound(err) {
return nil, errors.Wrapf(errdefs.ErrNotFound, "failed to fetch pids: %s", err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/runhcs/kill.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package main
import (
gcontext "context"

hcstypes "github.com/Microsoft/hcsshim/hcs"
"github.com/Microsoft/hcsshim/internal/appargs"
"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/hcs/schema1"
"github.com/Microsoft/hcsshim/internal/signals"
"github.com/Microsoft/hcsshim/osversion"
"github.com/urfave/cli"
Expand Down Expand Up @@ -61,7 +61,7 @@ signal to the init process of the "ubuntu01" container:
return err
}
defer uvm.Close()
if props, err := uvm.Properties(gcontext.Background(), schema1.PropertyTypeGuestConnection); err == nil &&
if props, err := uvm.Properties(gcontext.Background(), hcstypes.PropertyTypeGuestConnection); err == nil &&
props.GuestConnectionInfo.GuestDefinedCapabilities.SignalProcessSupported {
signalsSupported = true
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/runhcs/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"fmt"
"os"

hcstypes "github.com/Microsoft/hcsshim/hcs"
"github.com/Microsoft/hcsshim/internal/appargs"
"github.com/Microsoft/hcsshim/internal/hcs/schema1"
"github.com/urfave/cli"
)

Expand All @@ -33,7 +33,7 @@ var psCommand = cli.Command{
}
defer container.Close()

props, err := container.hc.Properties(gcontext.Background(), schema1.PropertyTypeProcessList)
props, err := container.hc.Properties(gcontext.Background(), hcstypes.PropertyTypeProcessList)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion computestorage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package computestorage

import (
hcstypes "github.com/Microsoft/hcsshim/hcs"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
)

Expand All @@ -22,7 +23,7 @@ import (
//sys hcsAttachOverlayFilter(volumePath string, layerData string) (hr error) = computestorage.HcsAttachOverlayFilter?
//sys hcsDetachOverlayFilter(volumePath string, layerData string) (hr error) = computestorage.HcsDetachOverlayFilter?

type Version = hcsschema.Version
type Version = hcstypes.Version
type Layer = hcsschema.Layer

// LayerData is the data used to describe parent layer information.
Expand Down
36 changes: 18 additions & 18 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,51 @@ import (
"sync"
"time"

hcstypes "github.com/Microsoft/hcsshim/hcs"
"github.com/Microsoft/hcsshim/internal/hcs"
"github.com/Microsoft/hcsshim/internal/hcs/schema1"
"github.com/Microsoft/hcsshim/internal/mergemaps"
)

// ContainerProperties holds the properties for a container and the processes running in that container
type ContainerProperties = schema1.ContainerProperties
type ContainerProperties = hcstypes.ContainerProperties

// MemoryStats holds the memory statistics for a container
type MemoryStats = schema1.MemoryStats
type MemoryStats = hcstypes.MemoryStats

// ProcessorStats holds the processor statistics for a container
type ProcessorStats = schema1.ProcessorStats
type ProcessorStats = hcstypes.ProcessorStats

// StorageStats holds the storage statistics for a container
type StorageStats = schema1.StorageStats
type StorageStats = hcstypes.StorageStats

// NetworkStats holds the network statistics for a container
type NetworkStats = schema1.NetworkStats
type NetworkStats = hcstypes.NetworkStats

// Statistics is the structure returned by a statistics call on a container
type Statistics = schema1.Statistics
type Statistics = hcstypes.Statistics

// ProcessList is the structure of an item returned by a ProcessList call on a container
type ProcessListItem = schema1.ProcessListItem
type ProcessListItem = hcstypes.ProcessListItem

// MappedVirtualDiskController is the structure of an item returned by a MappedVirtualDiskList call on a container
type MappedVirtualDiskController = schema1.MappedVirtualDiskController
type MappedVirtualDiskController = hcstypes.MappedVirtualDiskController

// Type of Request Support in ModifySystem
type RequestType = schema1.RequestType
type RequestType = hcstypes.RequestType

// Type of Resource Support in ModifySystem
type ResourceType = schema1.ResourceType
type ResourceType = hcstypes.ResourceType

// RequestType const
const (
Add = schema1.Add
Remove = schema1.Remove
Network = schema1.Network
Add = hcstypes.Add
Remove = hcstypes.Remove
Network = hcstypes.Network
)

// ResourceModificationRequestResponse 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 ResourceModificationRequestResponse = schema1.ResourceModificationRequestResponse
type ResourceModificationRequestResponse = hcstypes.ResourceModificationRequestResponse

type container struct {
system *hcs.System
Expand Down Expand Up @@ -168,7 +168,7 @@ func (container *container) HasPendingUpdates() (bool, error) {

// Statistics returns statistics for the container. This is a legacy v1 call
func (container *container) Statistics() (Statistics, error) {
properties, err := container.system.Properties(context.Background(), schema1.PropertyTypeStatistics)
properties, err := container.system.Properties(context.Background(), hcstypes.PropertyTypeStatistics)
if err != nil {
return Statistics{}, convertSystemError(err, container)
}
Expand All @@ -178,7 +178,7 @@ func (container *container) Statistics() (Statistics, error) {

// ProcessList returns an array of ProcessListItems for the container. This is a legacy v1 call
func (container *container) ProcessList() ([]ProcessListItem, error) {
properties, err := container.system.Properties(context.Background(), schema1.PropertyTypeProcessList)
properties, err := container.system.Properties(context.Background(), hcstypes.PropertyTypeProcessList)
if err != nil {
return nil, convertSystemError(err, container)
}
Expand All @@ -188,7 +188,7 @@ func (container *container) ProcessList() ([]ProcessListItem, error) {

// This is a legacy v1 call
func (container *container) MappedVirtualDisks() (map[int]MappedVirtualDiskController, error) {
properties, err := container.system.Properties(context.Background(), schema1.PropertyTypeMappedVirtualDisk)
properties, err := container.system.Properties(context.Background(), hcstypes.PropertyTypeMappedVirtualDisk)
if err != nil {
return nil, convertSystemError(err, container)
}
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module github.com/Microsoft/hcsshim

go 1.21
go 1.21.5

require (
github.com/Microsoft/cosesign1go v1.2.0
github.com/Microsoft/didx509go v0.0.3
github.com/Microsoft/go-winio v0.6.2
github.com/Microsoft/hcsshim/hcs v0.0.0
github.com/blang/semver/v4 v4.0.0
github.com/cenkalti/backoff/v4 v4.3.0
github.com/containerd/cgroups/v3 v3.0.3
Expand Down Expand Up @@ -91,7 +92,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.20.2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
Expand Down Expand Up @@ -120,3 +120,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace github.com/Microsoft/hcsshim/hcs => ./hcs
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.20.2 h1:5ctymQzZlyOON1666svgwn3s6IKWgfbjsejTMiXIyjg=
github.com/prometheus/client_golang v1.20.2/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down
7 changes: 7 additions & 0 deletions hcs/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/Microsoft/hcsshim/hcs

go 1.21.5

require github.com/Microsoft/go-winio v0.6.2

require golang.org/x/sys v0.23.0 // indirect
4 changes: 4 additions & 0 deletions hcs/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
83 changes: 83 additions & 0 deletions hcs/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package hcs

import (
"github.com/Microsoft/hcsshim/hcs/internal/schema1"
hcsschema "github.com/Microsoft/hcsshim/hcs/internal/schema2"
)

// ContainerProperties holds the properties for a container and the processes running in that container
type ContainerProperties = schema1.ContainerProperties

// MemoryStats holds the memory statistics for a container
type MemoryStats = schema1.MemoryStats

// ProcessorStats holds the processor statistics for a container
type ProcessorStats = schema1.ProcessorStats

// StorageStats holds the storage statistics for a container
type StorageStats = schema1.StorageStats

// NetworkStats holds the network statistics for a container
type NetworkStats = schema1.NetworkStats

// Statistics is the structure returned by a statistics call on a container
type Statistics = schema1.Statistics

// ProcessList is the structure of an item returned by a ProcessList call on a container
type ProcessListItem = schema1.ProcessListItem

// MappedVirtualDiskController is the structure of an item returned by a MappedVirtualDiskList call on a container
type MappedVirtualDiskController = schema1.MappedVirtualDiskController

// Type of Request Support in ModifySystem
type RequestType = schema1.RequestType

// Type of Resource Support in ModifySystem
type ResourceType = schema1.ResourceType

// RequestType const
const (
Add = schema1.Add
Remove = schema1.Remove
Network = schema1.Network
)

// ResourceModificationRequestResponse 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 ResourceModificationRequestResponse = schema1.ResourceModificationRequestResponse

type Version = hcsschema.Version

// ProcessConfig is used as both the input of Container.CreateProcess
// and to convert the parameters to JSON for passing onto the HCS
type ProcessConfig = schema1.ProcessConfig

type Layer = schema1.Layer
type MappedDir = schema1.MappedDir
type MappedPipe = schema1.MappedPipe
type HvRuntime = schema1.HvRuntime
type MappedVirtualDisk = schema1.MappedVirtualDisk

// AssignedDevice represents a device that has been directly assigned to a container
//
// NOTE: Support added in RS5
type AssignedDevice = schema1.AssignedDevice

// ContainerConfig is used as both the input of CreateContainer
// and to convert the parameters to JSON for passing onto the HCS
type ContainerConfig = schema1.ContainerConfig

type ComputeSystemQuery = schema1.ComputeSystemQuery

type PropertyType = schema1.PropertyType

type PropertyQuery = schema1.PropertyQuery

type GuestDefinedCapabilities = schema1.GuestDefinedCapabilities

const (
PropertyTypeStatistics PropertyType = "Statistics" // V1 and V2
PropertyTypeProcessList PropertyType = "ProcessList" // V1 and V2
PropertyTypeMappedVirtualDisk PropertyType = "MappedVirtualDisk" // Not supported in V2 schema call
PropertyTypeGuestConnection PropertyType = "GuestConnection" // V1 and V2. Nil return from HCS before RS5
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/Microsoft/go-winio/pkg/guid"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
hcsschema "github.com/Microsoft/hcsshim/hcs/internal/schema2"
)

// ProcessConfig is used as both the input of Container.CreateProcess
Expand Down Expand Up @@ -119,13 +119,16 @@ type ComputeSystemQuery struct {

type PropertyType string

/*
const (
PropertyTypeStatistics PropertyType = "Statistics" // V1 and V2
PropertyTypeProcessList PropertyType = "ProcessList" // V1 and V2
PropertyTypeMappedVirtualDisk PropertyType = "MappedVirtualDisk" // Not supported in V2 schema call
PropertyTypeGuestConnection PropertyType = "GuestConnection" // V1 and V2. Nil return from HCS before RS5
)
)
*/
type PropertyQuery struct {
PropertyTypes []PropertyType `json:",omitempty"`
}
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ import (
"io"
"time"

"github.com/Microsoft/hcsshim/internal/hcs/schema1"
hcstypes "github.com/Microsoft/hcsshim/hcs"
)

// ProcessConfig is used as both the input of Container.CreateProcess
// and to convert the parameters to JSON for passing onto the HCS
type ProcessConfig = schema1.ProcessConfig
type ProcessConfig = hcstypes.ProcessConfig

type Layer = schema1.Layer
type MappedDir = schema1.MappedDir
type MappedPipe = schema1.MappedPipe
type HvRuntime = schema1.HvRuntime
type MappedVirtualDisk = schema1.MappedVirtualDisk
type Layer = hcstypes.Layer
type MappedDir = hcstypes.MappedDir
type MappedPipe = hcstypes.MappedPipe
type HvRuntime = hcstypes.HvRuntime
type MappedVirtualDisk = hcstypes.MappedVirtualDisk

// AssignedDevice represents a device that has been directly assigned to a container
//
// NOTE: Support added in RS5
type AssignedDevice = schema1.AssignedDevice
type AssignedDevice = hcstypes.AssignedDevice

// ContainerConfig is used as both the input of CreateContainer
// and to convert the parameters to JSON for passing onto the HCS
type ContainerConfig = schema1.ContainerConfig
type ContainerConfig = hcstypes.ContainerConfig

type ComputeSystemQuery = schema1.ComputeSystemQuery
type ComputeSystemQuery = hcstypes.ComputeSystemQuery

// Container represents a created (but not necessarily running) container.
type Container interface {
Expand Down
4 changes: 2 additions & 2 deletions internal/cow/cow.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"
"io"

"github.com/Microsoft/hcsshim/internal/hcs/schema1"
hcstypes "github.com/Microsoft/hcsshim/hcs"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
)

Expand Down Expand Up @@ -73,7 +73,7 @@ type Container interface {
// ID returns the container ID.
ID() string
// Properties returns the requested container properties targeting a V1 schema container.
Properties(ctx context.Context, types ...schema1.PropertyType) (*schema1.ContainerProperties, error)
Properties(ctx context.Context, types ...hcstypes.PropertyType) (*hcstypes.ContainerProperties, error)
// PropertiesV2 returns the requested container properties targeting a V2 schema container.
PropertiesV2(ctx context.Context, types ...hcsschema.PropertyType) (*hcsschema.Properties, error)
// Start starts a container.
Expand Down
Loading

0 comments on commit 7aa4739

Please sign in to comment.