Skip to content

Commit 95ba6e9

Browse files
Add annotations to task update request api
Signed-off-by: Kathryn Baldauf <[email protected]>
1 parent ba83775 commit 95ba6e9

File tree

11 files changed

+566
-179
lines changed

11 files changed

+566
-179
lines changed

api/next.pb.txt

+28
Original file line numberDiff line numberDiff line change
@@ -4217,6 +4217,34 @@ file {
42174217
type_name: ".google.protobuf.Any"
42184218
json_name: "resources"
42194219
}
4220+
field {
4221+
name: "annotations"
4222+
number: 3
4223+
label: LABEL_REPEATED
4224+
type: TYPE_MESSAGE
4225+
type_name: ".containerd.services.tasks.v1.UpdateTaskRequest.AnnotationsEntry"
4226+
json_name: "annotations"
4227+
}
4228+
nested_type {
4229+
name: "AnnotationsEntry"
4230+
field {
4231+
name: "key"
4232+
number: 1
4233+
label: LABEL_OPTIONAL
4234+
type: TYPE_STRING
4235+
json_name: "key"
4236+
}
4237+
field {
4238+
name: "value"
4239+
number: 2
4240+
label: LABEL_OPTIONAL
4241+
type: TYPE_STRING
4242+
json_name: "value"
4243+
}
4244+
options {
4245+
map_entry: true
4246+
}
4247+
}
42204248
}
42214249
message_type {
42224250
name: "MetricsRequest"

api/services/tasks/v1/tasks.pb.go

+260-89
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/services/tasks/v1/tasks.proto

+1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ message CheckpointTaskResponse {
188188
message UpdateTaskRequest {
189189
string container_id = 1;
190190
google.protobuf.Any resources = 2;
191+
map<string, string> annotations = 3;
191192
}
192193

193194
message MetricsRequest {

runtime/task.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type Task interface {
7070
// Checkpoint checkpoints a container to an image with live system data
7171
Checkpoint(context.Context, string, *types.Any) error
7272
// Update sets the provided resources to a running task
73-
Update(context.Context, *types.Any) error
73+
Update(context.Context, *types.Any, map[string]string) error
7474
// Process returns a process within the task for the provided id
7575
Process(context.Context, string) (Process, error)
7676
// Stats returns runtime specific metrics for a task

runtime/v1/linux/task.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func (t *Task) Checkpoint(ctx context.Context, path string, options *types.Any)
306306
}
307307

308308
// Update changes runtime information of a running task
309-
func (t *Task) Update(ctx context.Context, resources *types.Any) error {
309+
func (t *Task) Update(ctx context.Context, resources *types.Any, _ map[string]string) error {
310310
if _, err := t.shim.Update(ctx, &shim.UpdateTaskRequest{
311311
Resources: resources,
312312
}); err != nil {

runtime/v2/shim.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -420,10 +420,11 @@ func (s *shim) Checkpoint(ctx context.Context, path string, options *ptypes.Any)
420420
return nil
421421
}
422422

423-
func (s *shim) Update(ctx context.Context, resources *ptypes.Any) error {
423+
func (s *shim) Update(ctx context.Context, resources *ptypes.Any, annotations map[string]string) error {
424424
if _, err := s.task.Update(ctx, &task.UpdateTaskRequest{
425-
ID: s.ID(),
426-
Resources: resources,
425+
ID: s.ID(),
426+
Resources: resources,
427+
Annotations: annotations,
427428
}); err != nil {
428429
return errdefs.FromGRPC(err)
429430
}

runtime/v2/task/shim.pb.go

+256-84
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

runtime/v2/task/shim.proto

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ message CheckpointTaskRequest {
132132
message UpdateTaskRequest {
133133
string id = 1;
134134
google.protobuf.Any resources = 2;
135+
map<string, string> annotations = 3;
135136
}
136137

137138
message StartRequest {

services/tasks/local.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ func (l *local) Update(ctx context.Context, r *api.UpdateTaskRequest, _ ...grpc.
560560
if err != nil {
561561
return nil, err
562562
}
563-
if err := t.Update(ctx, r.Resources); err != nil {
563+
if err := t.Update(ctx, r.Resources, r.Annotations); err != nil {
564564
return nil, errdefs.ToGRPC(err)
565565
}
566566
return empty, nil

task.go

+5
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag
503503
type UpdateTaskInfo struct {
504504
// Resources updates a tasks resource constraints
505505
Resources interface{}
506+
// Annotations allows arbitrary and/or experimental resource constraints for task update
507+
Annotations map[string]string
506508
}
507509

508510
// UpdateTaskOpts allows a caller to update task settings
@@ -525,6 +527,9 @@ func (t *task) Update(ctx context.Context, opts ...UpdateTaskOpts) error {
525527
}
526528
request.Resources = any
527529
}
530+
if i.Annotations != nil {
531+
request.Annotations = i.Annotations
532+
}
528533
_, err := t.client.TaskService().Update(ctx, request)
529534
return errdefs.FromGRPC(err)
530535
}

task_opts.go

+8
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,11 @@ func WithResources(resources interface{}) UpdateTaskOpts {
209209
return nil
210210
}
211211
}
212+
213+
// WithAnnotations sets the provided annotations for task updates.
214+
func WithAnnotations(annotations map[string]string) UpdateTaskOpts {
215+
return func(ctx context.Context, client *Client, r *UpdateTaskInfo) error {
216+
r.Annotations = annotations
217+
return nil
218+
}
219+
}

0 commit comments

Comments
 (0)