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 81eba79
Show file tree
Hide file tree
Showing 30 changed files with 514 additions and 191 deletions.
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
35 changes: 21 additions & 14 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,58 @@ 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"
)

// The following declarations have been moved to hcs/helpers.go .
// They have been retained here only to avoid breaking any
// downstream users.
// TODO (kiashok): Once hcsshim moves to a new major version, we can
// remove these declarations from here.

// 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
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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 @@ -120,3 +121,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
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

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

require golang.org/x/sys v0.10.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.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7 changes: 7 additions & 0 deletions hcs/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hcs

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

type Version = hcsschema.Version
48 changes: 48 additions & 0 deletions hcs/helpers_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//go:build windows

package hcs

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

// 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

type GuestDefinedCapabilities = schema1.GuestDefinedCapabilities

type ResourceModificationRequestResponse = schema1.ResourceModificationRequestResponse

// RequestType const
const (
Add RequestType = "Add"
Remove RequestType = "Remove"
Network ResourceType = "Network"
)
133 changes: 133 additions & 0 deletions hcs/internal/schema1/schema1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//go:build windows

package schema1

import (
"time"

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

// ContainerProperties holds the properties for a container and the processes running in that container
type ContainerProperties struct {
ID string `json:"Id"`
State string
Name string
SystemType string
RuntimeOSType string `json:"RuntimeOsType,omitempty"`
Owner string
SiloGUID string `json:"SiloGuid,omitempty"`
RuntimeID guid.GUID `json:"RuntimeId,omitempty"`
IsRuntimeTemplate bool `json:",omitempty"`
RuntimeImagePath string `json:",omitempty"`
Stopped bool `json:",omitempty"`
ExitType string `json:",omitempty"`
AreUpdatesPending bool `json:",omitempty"`
ObRoot string `json:",omitempty"`
Statistics Statistics `json:",omitempty"`
ProcessList []ProcessListItem `json:",omitempty"`
MappedVirtualDiskControllers map[int]MappedVirtualDiskController `json:",omitempty"`
GuestConnectionInfo GuestConnectionInfo `json:",omitempty"`
}

// MemoryStats holds the memory statistics for a container
type MemoryStats struct {
UsageCommitBytes uint64 `json:"MemoryUsageCommitBytes,omitempty"`
UsageCommitPeakBytes uint64 `json:"MemoryUsageCommitPeakBytes,omitempty"`
UsagePrivateWorkingSetBytes uint64 `json:"MemoryUsagePrivateWorkingSetBytes,omitempty"`
}

// ProcessorStats holds the processor statistics for a container
type ProcessorStats struct {
TotalRuntime100ns uint64 `json:",omitempty"`
RuntimeUser100ns uint64 `json:",omitempty"`
RuntimeKernel100ns uint64 `json:",omitempty"`
}

// StorageStats holds the storage statistics for a container
type StorageStats struct {
ReadCountNormalized uint64 `json:",omitempty"`
ReadSizeBytes uint64 `json:",omitempty"`
WriteCountNormalized uint64 `json:",omitempty"`
WriteSizeBytes uint64 `json:",omitempty"`
}

// NetworkStats holds the network statistics for a container
type NetworkStats struct {
BytesReceived uint64 `json:",omitempty"`
BytesSent uint64 `json:",omitempty"`
PacketsReceived uint64 `json:",omitempty"`
PacketsSent uint64 `json:",omitempty"`
DroppedPacketsIncoming uint64 `json:",omitempty"`
DroppedPacketsOutgoing uint64 `json:",omitempty"`
EndpointId string `json:",omitempty"`
InstanceId string `json:",omitempty"`
}

// Statistics is the structure returned by a statistics call on a container
type Statistics struct {
Timestamp time.Time `json:",omitempty"`
ContainerStartTime time.Time `json:",omitempty"`
Uptime100ns uint64 `json:",omitempty"`
Memory MemoryStats `json:",omitempty"`
Processor ProcessorStats `json:",omitempty"`
Storage StorageStats `json:",omitempty"`
Network []NetworkStats `json:",omitempty"`
}

// ProcessList is the structure of an item returned by a ProcessList call on a container
type ProcessListItem struct {
CreateTimestamp time.Time `json:",omitempty"`
ImageName string `json:",omitempty"`
KernelTime100ns uint64 `json:",omitempty"`
MemoryCommitBytes uint64 `json:",omitempty"`
MemoryWorkingSetPrivateBytes uint64 `json:",omitempty"`
MemoryWorkingSetSharedBytes uint64 `json:",omitempty"`
ProcessId uint32 `json:",omitempty"`
UserTime100ns uint64 `json:",omitempty"`
}

// MappedVirtualDiskController is the structure of an item returned by a MappedVirtualDiskList call on a container
type MappedVirtualDiskController struct {
MappedVirtualDisks map[int]MappedVirtualDisk `json:",omitempty"`
}

type MappedVirtualDisk struct {
HostPath string `json:",omitempty"` // Path to VHD on the host
ContainerPath string // Platform-specific mount point path in the container
CreateInUtilityVM bool `json:",omitempty"`
ReadOnly bool `json:",omitempty"`
Cache string `json:",omitempty"` // "" (Unspecified); "Disabled"; "Enabled"; "Private"; "PrivateAllowSharing"
AttachOnly bool `json:",omitempty"`
}

// GuestDefinedCapabilities is part of the GuestConnectionInfo returned by a GuestConnection call on a utility VM
type GuestDefinedCapabilities struct {
NamespaceAddRequestSupported bool `json:",omitempty"`
SignalProcessSupported bool `json:",omitempty"`
DumpStacksSupported bool `json:",omitempty"`
DeleteContainerStateSupported bool `json:",omitempty"`
UpdateContainerSupported bool `json:",omitempty"`
}

// GuestConnectionInfo is the structure of an iterm return by a GuestConnection call on a utility VM
type GuestConnectionInfo struct {
SupportedSchemaVersions []hcsschema.Version `json:",omitempty"`
ProtocolVersion uint32 `json:",omitempty"`
GuestDefinedCapabilities GuestDefinedCapabilities `json:",omitempty"`
}

// Type of Request Support in ModifySystem
type RequestType string

// Type of Resource Support in ModifySystem
type ResourceType string

// 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 struct {
Resource ResourceType `json:"ResourceType"`
Data interface{} `json:"Settings"`
Request RequestType `json:"RequestType,omitempty"`
}
File renamed without changes.
3 changes: 2 additions & 1 deletion internal/cow/cow.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"io"

hcstypes "github.com/Microsoft/hcsshim/hcs"
"github.com/Microsoft/hcsshim/internal/hcs/schema1"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
)
Expand Down Expand Up @@ -73,7 +74,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 ...schema1.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
5 changes: 3 additions & 2 deletions internal/gcs/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

hcstypes "github.com/Microsoft/hcsshim/hcs"
"github.com/Microsoft/hcsshim/internal/cow"
"github.com/Microsoft/hcsshim/internal/hcs/schema1"
hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
Expand Down Expand Up @@ -138,7 +139,7 @@ func (c *Container) Modify(ctx context.Context, config interface{}) (err error)
}

// Properties returns the requested container properties targeting a V1 schema container.
func (c *Container) Properties(ctx context.Context, types ...schema1.PropertyType) (_ *schema1.ContainerProperties, err error) {
func (c *Container) Properties(ctx context.Context, types ...schema1.PropertyType) (_ *hcstypes.ContainerProperties, err error) {
ctx, span := oc.StartSpan(ctx, "gcs::Container::Properties", oc.WithClientSpanKind)
defer span.End()
defer func() { oc.SetSpanStatus(span, err) }()
Expand All @@ -153,7 +154,7 @@ func (c *Container) Properties(ctx context.Context, types ...schema1.PropertyTyp
if err != nil {
return nil, err
}
return (*schema1.ContainerProperties)(&resp.Properties), nil
return (*hcstypes.ContainerProperties)(&resp.Properties), nil
}

// PropertiesV2 returns the requested container properties targeting a V2 schema container.
Expand Down
4 changes: 2 additions & 2 deletions internal/gcs/guestcaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/json"
"fmt"

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

// GuestDefinedCapabilities is an interface for different guest defined capabilities.
Expand Down Expand Up @@ -82,7 +82,7 @@ func (l *LCOWGuestDefinedCapabilities) IsDeleteContainerStateSupported() bool {
var _ GuestDefinedCapabilities = &WCOWGuestDefinedCapabilities{}

type WCOWGuestDefinedCapabilities struct {
schema1.GuestDefinedCapabilities
hcstypes.GuestDefinedCapabilities
}

func (w *WCOWGuestDefinedCapabilities) IsNamespaceAddRequestSupported() bool {
Expand Down
Loading

0 comments on commit 81eba79

Please sign in to comment.