Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions cmd/containerd-shim-lcow-v2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
"github.com/Microsoft/hcsshim/internal/shim"
"github.com/Microsoft/hcsshim/osversion"

"github.com/containerd/errdefs"
bootapi "github.com/containerd/containerd/api/runtime/bootstrap/v1"
"github.com/sirupsen/logrus"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"google.golang.org/protobuf/proto"
)

// Add a manifest to get proper Windows version detection.
Expand Down Expand Up @@ -99,14 +100,23 @@ func setLogConfiguration() error {
// bypassing os.Stderr, so it will still go to panic.log.
os.Stderr = os.Stdout

opts, err := shim.ReadRuntimeOptions[*runhcsopts.Options](os.Stdin)
data, err := io.ReadAll(os.Stdin)
if err != nil {
if !errors.Is(err, errdefs.ErrNotFound) {
return fmt.Errorf("failed to read runtime options from stdin: %w", err)
}
return fmt.Errorf("failed to read runtime options from stdin: %w", err)
}
_ = os.Stdin.Close()

if opts != nil {
// containerd 2.3+ delivers the options as an extension inside BootstrapParams.
var params bootapi.BootstrapParams
if err := proto.Unmarshal(data, &params); err != nil {
return fmt.Errorf("failed to unmarshal bootstrap params: %w", err)
}
var opts runhcsopts.Options
found, err := params.FindExtension(&opts)
if err != nil {
return fmt.Errorf("failed to extract runtime options from bootstrap params: %w", err)
}
if found {
if opts.LogLevel != "" {
// If log level is specified, set the corresponding logrus logging level.
lvl, err := logrus.ParseLevel(opts.LogLevel)
Expand All @@ -122,7 +132,6 @@ func setLogConfiguration() error {
log.SetScrubbing(false)
}
}
_ = os.Stdin.Close()
}
return nil
}
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/options/runhcs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 35 additions & 11 deletions cmd/containerd-shim-runhcs-v1/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"unsafe"

"github.com/Microsoft/go-winio"
bootapi "github.com/containerd/containerd/api/runtime/bootstrap/v1"
_ "github.com/containerd/containerd/api/runtime/sandbox/v1"
task "github.com/containerd/containerd/api/runtime/task/v2"
"github.com/containerd/ttrpc"
Expand Down Expand Up @@ -200,7 +201,7 @@ var serveCommand = cli.Command{
return err
}
defer s.Close()
task.RegisterTaskService(s, svc)
task.RegisterTTRPCTaskService(s, svc)
shimdiag.RegisterShimDiagService(s, svc)
extendedtask.RegisterExtendedTaskService(s, svc)

Expand Down Expand Up @@ -272,22 +273,45 @@ func trapClosedConnErr(err error) error {
}

// readOptions reads in bytes from the reader and converts it to a shim options
// struct. If no data is available from the reader, returns (nil, nil).
// struct. If no options are available from the reader, returns (nil, nil).
//
// containerd 2.3+ passes the options as an extension inside a BootstrapParams
// message, while older containerd passes them as a bare Any; both are accepted.
func readOptions(r io.Reader) (*runhcsopts.Options, error) {
d, err := io.ReadAll(r)
if err != nil {
return nil, errors.Wrap(err, "failed to read input")
}
if len(d) > 0 {
var a anypb.Any
if err := proto.Unmarshal(d, &a); err != nil {
return nil, errors.Wrap(err, "failed unmarshalling into Any")
}
v, err := typeurl.UnmarshalAny(&a)
if err != nil {
return nil, errors.Wrap(err, "failed unmarshalling by typeurl")
if len(d) == 0 {
return nil, nil
}

// Legacy: options passed as a bare Any (older/special-cased containerd).
var a anypb.Any
if err := proto.Unmarshal(d, &a); err != nil {
return nil, errors.Wrap(err, "failed unmarshalling into Any")
}
if v, err := typeurl.UnmarshalAny(&a); err == nil {
opts, ok := v.(*runhcsopts.Options)
if !ok {
return nil, errors.Errorf("unexpected runtime options type %T", v)
}
return v.(*runhcsopts.Options), nil
return opts, nil
}

// containerd 2.3+ delivers the options as an extension inside BootstrapParams.
var params bootapi.BootstrapParams
if err = proto.Unmarshal(d, &params); err != nil {
return nil, errors.Wrap(err, "failed unmarshalling into BootstrapParams")
}
var opts runhcsopts.Options
found, err := params.FindExtension(&opts)
if err != nil {
return nil, errors.Wrap(err, "failed extracting options from BootstrapParams")
}

if found {
return &opts, nil
}
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type service struct {
gracefulShutdown bool
}

var _ task.TaskService = &service{}
var _ task.TTRPCTaskService = &service{}

func NewService(o ...ServiceOption) (svc *service, err error) {
var opts ServiceOptions
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ The start command can either start a new shim or return an address to an existin
return errors.Wrap(err, "failed to connect to hosting shim")
}
cl := ttrpc.NewClient(c, ttrpc.WithOnClose(func() { c.Close() }))
t := task.NewTaskClient(cl)
t := task.NewTTRPCTaskClient(cl)
ctx := gocontext.Background()
req := &task.ConnectRequest{ID: sbid}
cr, err := t.Connect(ctx, req)
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/stats/stats.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Microsoft/hcsshim

go 1.26.0
go 1.26.3

// protobuf/gRPC/ttrpc generation
tool (
Expand Down Expand Up @@ -28,8 +28,8 @@ require (
github.com/cenkalti/backoff/v4 v4.3.0
github.com/containerd/cgroups/v3 v3.1.3
github.com/containerd/console v1.0.5
github.com/containerd/containerd/api v1.10.0
github.com/containerd/containerd/v2 v2.2.5
github.com/containerd/containerd/api v1.11.1
github.com/containerd/containerd/v2 v2.3.1
github.com/containerd/errdefs v1.0.0
github.com/containerd/errdefs/pkg v0.3.0
github.com/containerd/go-runc v1.1.0
Expand Down Expand Up @@ -67,7 +67,7 @@ require (
golang.org/x/sync v0.22.0
golang.org/x/sys v0.47.0
google.golang.org/grpc v1.83.0
google.golang.org/protobuf v1.36.11
google.golang.org/protobuf v1.36.12
)

require (
Expand Down
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,10 @@ github.com/containerd/cgroups/v3 v3.1.3 h1:eUNflyMddm18+yrDmZPn3jI7C5hJ9ahABE5q6
github.com/containerd/cgroups/v3 v3.1.3/go.mod h1:PKZ2AcWmSBsY/tJUVhtS/rluX0b1uq1GmPO1ElCmbOw=
github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/qqsc=
github.com/containerd/console v1.0.5/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/containerd/containerd/api v1.10.0 h1:5n0oHYVBwN4VhoX9fFykCV9dF1/BvAXeg2F8W6UYq1o=
github.com/containerd/containerd/api v1.10.0/go.mod h1:NBm1OAk8ZL+LG8R0ceObGxT5hbUYj7CzTmR3xh0DlMM=
github.com/containerd/containerd/v2 v2.2.5 h1:KTFzB02LviYmmfRmz8r9UFd+n6YlddVFK+5lbgQXUTU=
github.com/containerd/containerd/v2 v2.2.5/go.mod h1:5t2+xFv2dGd/iDYp9Z8DXB4cmWrWQi1XqxGJPS2gBzU=
github.com/containerd/containerd/api v1.11.1 h1:h8nfoDW9+fNsC/9TwiAHj8B1GzXKtR4eFtkhi/X5RLU=
github.com/containerd/containerd/api v1.11.1/go.mod h1:CaQFRu+N1MtbgL6JDOJLUB1hCKESU1lD6MuTJhgtdlw=
github.com/containerd/containerd/v2 v2.3.1 h1:4dVXBdlvotRBlaP2TmNbY/EGc06KJrMDDUqQdxX/HOk=
github.com/containerd/containerd/v2 v2.3.1/go.mod h1:xVoxGPWZBwwph8DF2IbDhriLKdHfjdpO0b3wFP9wQ1I=
github.com/containerd/continuity v0.5.0 h1:7a85HZpCSs+1Zps0Ee3DPSuAWY+0SJM1JNM51nlEVDg=
github.com/containerd/continuity v0.5.0/go.mod h1:/lNJvtJKUQStBzpVQ1+rasXO1LAWtUQssk28EZvJ3nE=
github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI=
Expand Down Expand Up @@ -478,8 +478,9 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/cyphar/filepath-securejoin v0.6.1 h1:5CeZ1jPXEiYt3+Z6zqprSAgSWiggmpVyciv8syjIpVE=
github.com/cyphar/filepath-securejoin v0.6.1/go.mod h1:A8hd4EnAeyujCJRrICiOWqjS1AX0a9kM5XL+NwKoYSc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 h1:5RVFMOWjMyRy8cARdy79nAmgYw3hK/4HUq48LQ6Wwqo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
github.com/dgraph-io/badger/v4 v4.9.4 h1:bcw+waCpzRZ2nmcSPbnPvDVhiEsn98TKmvnAhK7r7LM=
Expand Down Expand Up @@ -872,8 +873,9 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
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.24.0 h1:5XStIklKuAtJSNpdD3s8XJj/Yv78IQmE1kbNk87JrAI=
github.com/prometheus/client_golang v1.24.0/go.mod h1:QcsNdotprC2nS4BTM2ucbcqxd2CeXTEa9jW7zHO9iDE=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down Expand Up @@ -2048,8 +2050,8 @@ google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojt
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
2 changes: 1 addition & 1 deletion internal/computeagent/computeagent.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/controller/device/scsi/save/payload.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/controller/linuxcontainer/save/payload.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/controller/migration/save/payload.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/controller/network/save/payload.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/controller/pod/save/payload.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/controller/process/save/payload.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/controller/vm/save/payload.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/extendedtask/extendedtask.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/ncproxyttrpc/networkconfigproxy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/shimdiag/shimdiag.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/migration/migration.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/migration/migration_options.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/ncproxy/ncproxygrpc/v0/networkconfigproxy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/ncproxy/ncproxygrpc/v1/networkconfigproxy.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/ncproxy/nodenetsvc/v0/nodenetsvc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/ncproxy/nodenetsvc/v1/nodenetsvc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/containerd-shim-runhcs-v1/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func verifyStartCommandSuccess(t *testing.T, expectedNamespace, expectedID strin
t.Fatalf("failed to connect to hosting shim at: %s, with: %v", sout, err)
}
cl := ttrpc.NewClient(c, ttrpc.WithOnClose(func() { c.Close() }))
tc := task.NewTaskClient(cl)
tc := task.NewTTRPCTaskClient(cl)
ctx := context.Background()
req := &task.ShutdownRequest{ID: expectedID, Now: true}
_, err = tc.Shutdown(ctx, req)
Expand Down
Loading
Loading