Skip to content

Commit a91b05d

Browse files
authored
Merge pull request containerd#9736 from abel-von/sandbox-task-0201
sandbox: Store bootstrap parameters in sandbox metadata and shim get them from sandbox metadata rather than other shim's bootstrap.json file.
2 parents 182a5fc + de38490 commit a91b05d

File tree

19 files changed

+473
-238
lines changed

19 files changed

+473
-238
lines changed

api/next.pb.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5506,6 +5506,20 @@ file {
55065506
type_name: ".containerd.services.sandbox.v1.ControllerStartResponse.LabelsEntry"
55075507
json_name: "labels"
55085508
}
5509+
field {
5510+
name: "address"
5511+
number: 5
5512+
label: LABEL_OPTIONAL
5513+
type: TYPE_STRING
5514+
json_name: "address"
5515+
}
5516+
field {
5517+
name: "version"
5518+
number: 6
5519+
label: LABEL_OPTIONAL
5520+
type: TYPE_UINT32
5521+
json_name: "version"
5522+
}
55095523
nested_type {
55105524
name: "LabelsEntry"
55115525
field {
@@ -5696,6 +5710,20 @@ file {
56965710
type_name: ".google.protobuf.Any"
56975711
json_name: "extra"
56985712
}
5713+
field {
5714+
name: "address"
5715+
number: 8
5716+
label: LABEL_OPTIONAL
5717+
type: TYPE_STRING
5718+
json_name: "address"
5719+
}
5720+
field {
5721+
name: "version"
5722+
number: 9
5723+
label: LABEL_OPTIONAL
5724+
type: TYPE_UINT32
5725+
json_name: "version"
5726+
}
56995727
nested_type {
57005728
name: "InfoEntry"
57015729
field {

api/services/sandbox/v1/sandbox.pb.go

Lines changed: 223 additions & 178 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/services/sandbox/v1/sandbox.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ message ControllerStartResponse {
120120
uint32 pid = 2;
121121
google.protobuf.Timestamp created_at = 3;
122122
map<string, string> labels = 4;
123+
// Address of the sandbox for containerd to connect,
124+
// for calling Task or other APIs serving in the sandbox.
125+
// it is in the form of ttrpc+unix://path/to/uds or grpc+vsock://<vsock cid>:<port>.
126+
string address = 5;
127+
uint32 version = 6;
123128
}
124129

125130
message ControllerPlatformRequest {
@@ -163,6 +168,11 @@ message ControllerStatusResponse {
163168
google.protobuf.Timestamp created_at = 5;
164169
google.protobuf.Timestamp exited_at = 6;
165170
google.protobuf.Any extra = 7;
171+
// Address of the sandbox for containerd to connect,
172+
// for calling Task or other APIs serving in the sandbox.
173+
// it is in the form of ttrpc+unix://path/to/uds or grpc+vsock://<vsock cid>:<port>.
174+
string address = 8;
175+
uint32 version = 9;
166176
}
167177

168178
message ControllerShutdownRequest {

client/task_opts.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ func WithRuntimePath(absRuntimePath string) NewTaskOpts {
5050
}
5151
}
5252

53+
// WithTaskAPIEndpoint allow task service to manage a task through a given endpoint,
54+
// usually it is served inside a sandbox, and we can get it from sandbox status.
55+
func WithTaskAPIEndpoint(address string, version uint32) NewTaskOpts {
56+
return func(ctx context.Context, client *Client, info *TaskInfo) error {
57+
if info.Options == nil {
58+
info.Options = &options.Options{}
59+
}
60+
opts, ok := info.Options.(*options.Options)
61+
if !ok {
62+
return errors.New("invalid runtime v2 options format")
63+
}
64+
opts.TaskApiAddress = address
65+
opts.TaskApiVersion = version
66+
return nil
67+
}
68+
}
69+
5370
// WithTaskCheckpoint allows a task to be created with live runtime and memory data from a
5471
// previous checkpoint. Additional software such as CRIU may be required to
5572
// restore a task from a checkpoint

core/runtime/runtime.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ type CreateOpts struct {
5151
Runtime string
5252
// SandboxID is an optional ID of sandbox this container belongs to
5353
SandboxID string
54+
// Address is an optional Address for Task API server
55+
Address string
56+
// Version is an optional Version of the Task API
57+
Version uint32
5458
}
5559

5660
// Exit information for a process

core/runtime/v2/binary.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,12 @@ func (b *binary) Start(ctx context.Context, opts *types.Any, onClose func()) (_
143143
if err := writeBootstrapParams(filepath.Join(b.bundle.Path, "bootstrap.json"), params); err != nil {
144144
return nil, fmt.Errorf("failed to write bootstrap.json: %w", err)
145145
}
146-
146+
// The address is in the form like ttrpc+unix://<uds-path> or grpc+vsock://<cid>:<port>
147+
address := fmt.Sprintf("%s+%s", params.Protocol, params.Address)
147148
return &shim{
148149
bundle: b.bundle,
149150
client: conn,
151+
address: address,
150152
version: params.Version,
151153
}, nil
152154
}

core/runtime/v2/runc/options/next.pb.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ file {
7373
type: TYPE_STRING
7474
json_name: "criuWorkPath"
7575
}
76+
field {
77+
name: "task_api_address"
78+
number: 12
79+
label: LABEL_OPTIONAL
80+
type: TYPE_STRING
81+
json_name: "taskApiAddress"
82+
}
83+
field {
84+
name: "task_api_version"
85+
number: 13
86+
label: LABEL_OPTIONAL
87+
type: TYPE_UINT32
88+
json_name: "taskApiVersion"
89+
}
7690
reserved_range {
7791
start: 8
7892
end: 9

core/runtime/v2/runc/options/oci.pb.go

Lines changed: 55 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/runtime/v2/runc/options/oci.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ message Options {
2929
string criu_image_path = 10;
3030
// criu work path
3131
string criu_work_path = 11;
32+
// task api address, can be a unix domain socket, or vsock address.
33+
// it is in the form of ttrpc+unix://path/to/uds or grpc+vsock://<vsock cid>:<port>.
34+
string task_api_address = 12;
35+
// task api version, currently supported value is 2 and 3.
36+
uint32 task_api_version = 13;
3237
}
3338

3439
message CheckpointOptions {

core/runtime/v2/shim.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,13 @@ func loadShim(ctx context.Context, bundle *Bundle, onClose func()) (_ ShimInstan
113113
}
114114
}()
115115

116+
// The address is in the form like ttrpc+unix://<uds-path> or grpc+vsock://<cid>:<port>
117+
address := fmt.Sprintf("%s+%s", params.Protocol, params.Address)
118+
116119
shim := &shim{
117120
bundle: bundle,
118121
client: conn,
122+
address: address,
119123
version: params.Version,
120124
}
121125

@@ -185,8 +189,9 @@ type ShimInstance interface {
185189
Client() any
186190
// Delete will close the client and remove bundle from disk.
187191
Delete(ctx context.Context) error
188-
// Version returns shim's features compatibility version.
189-
Version() int
192+
// Endpoint returns shim's endpoint information,
193+
// including address and version.
194+
Endpoint() (string, int)
190195
}
191196

192197
func parseStartResponse(response []byte) (client.BootstrapParams, error) {
@@ -361,6 +366,7 @@ func (gc *grpcConn) UserOnCloseWait(ctx context.Context) error {
361366
type shim struct {
362367
bundle *Bundle
363368
client any
369+
address string
364370
version int
365371
}
366372

@@ -371,8 +377,8 @@ func (s *shim) ID() string {
371377
return s.bundle.ID
372378
}
373379

374-
func (s *shim) Version() int {
375-
return s.version
380+
func (s *shim) Endpoint() (string, int) {
381+
return s.address, s.version
376382
}
377383

378384
func (s *shim) Namespace() string {
@@ -440,7 +446,8 @@ type shimTask struct {
440446
}
441447

442448
func newShimTask(shim ShimInstance) (*shimTask, error) {
443-
taskClient, err := NewTaskClient(shim.Client(), shim.Version())
449+
_, version := shim.Endpoint()
450+
taskClient, err := NewTaskClient(shim.Client(), version)
444451
if err != nil {
445452
return nil, err
446453
}

0 commit comments

Comments
 (0)