-
Notifications
You must be signed in to change notification settings - Fork 347
Switch to containerd extension #260
Switch to containerd extension #260
Conversation
|
wait to rebase after #209 is merged. |
bd64262 to
76154bc
Compare
pkg/server/helpers.go
Outdated
| // sandboxMetadataLabel is label name that identify metadata of sandbox in CreateContainerRequest | ||
| sandboxMetadataLabel = "io.cri-containerd.sandbox.metadata" | ||
| // sandboxMetadataLabel is label name that identify metadata of container in CreateContainerRequest | ||
| // containerMetadataLabel is label name that identify metadata of container in CreateContainerRequest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not a label name any more, so perhaps "...is an extension name..."?
BTW The "sandboxMetadataLabel is label name" should really be "sandboxMetadataLabel is a label name".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. Thanks for review
76154bc to
e222056
Compare
| containerd.WithSpec(spec, specOpts...), | ||
| containerd.WithRuntime(defaultRuntime, nil), | ||
| containerd.WithContainerLabels(labels)) | ||
| containerd.WithContainerExtension(containerMetadataExtension, &meta)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to handle versioning ourselves, I think.
Containerd is using json marshal/unmarshal for non-proto message now. Could we update Encode/Decode in container/sandbox metadata and container status to MarshalJSON, and UnmarshalJSON? So that golang will call our customized marshal/unmarshal functions which should automatically handle versioning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please add unit test to make sure typeurl.Marshal and typeurl.Unmarshal does properly handle the versioning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/server/helpers.go
Outdated
| // sandboxMetadataExtension is a extension name that identify metadata of sandbox in CreateContainerRequest | ||
| sandboxMetadataExtension = "io.cri-containerd.sandbox.metadata" | ||
| // containerMetadataExtension is a extension name that identify metadata of container in CreateContainerRequest | ||
| containerMetadataExtension = "io.cri-containerd.container.metadata" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need a label to select containers and sandboxes.
Can we add a label containerKindLabel = "io.cri-containerd.kind"? And we should put "sandbox" on sandbox container, and "container" on application container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? Should we use containerKindLabel but containerMetadataExtension? @Random-Liu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean instead of extension, we still need a label to indicate whether a container is sandbox container or regular container.
We could add a label io.cri-containerd.kind on each container, io.cri-containerd.kind=sandbox means it is a sandbox container, io.cri-containerd.kind=container means it is a regular container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean we shoule add both lable and extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example
opts := []containerd.NewContainerOpts{
containerd.WithSnapshotter(c.config.ContainerdSnapshotter),
containerd.WithNewSnapshot(id, image.Image),
containerd.WithSpec(spec, specOpts...),
containerd.WithContainerLabels(map[string]string{containerKindLabel: "sandbox"})
containerd.WithContainerExtension(sandboxMetadataExtension, &sandbox.Metadata),
containerd.WithRuntime(defaultRuntime, nil)}
container, err := c.client.NewContainer(ctx, id, opts...)
pkg/server/container_create.go
Outdated
| ) | ||
|
|
||
| func init() { | ||
| typeurl.Register(&containerstore.Metadata{}, "github.com/kubernetes-incubator/cri-containerd/pkg/store/container", "Metadata") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Line too long, add new line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/server/sandbox_run.go
Outdated
| ) | ||
|
|
||
| func init() { | ||
| typeurl.Register(&sandboxstore.Metadata{}, "github.com/kubernetes-incubator/cri-containerd/pkg/store/sandbox", "Metadata") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
e222056 to
4479718
Compare
| Version string | ||
| Metadata | ||
| Version string | ||
| Metadata metadataInternal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a recursive call if we use Metadata in versionedMetadata derectly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense.
461969c to
ee4667a
Compare
pkg/store/container/metadata_test.go
Outdated
| data, err := json.Marshal(meta) | ||
| assert.NoError(err) | ||
| assert.NoError(json.Unmarshal(data, newMeta)) | ||
| assert.Equal(meta, newMeta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't know whether MarshalJSON or UnmarshalJSON is actually called during this.
The test is a little bit confusing.
How about this?
- Your first case. (verify that data could be stored and recovered)
- Make sure
json.Marshal(Metadata)andjson.Marshal(versionedMetadata)get the same bytes result; (verify that data is stored as versioned data, case1) has proved that versioned data could be recovered) json.Marshal(unsupportedVersionedMetadata)and thenjson.Unmarshal(data)should get an error; (verify that unsupported versioned data won't be unmarshalled)
We may want to add some t.Logf to make the test more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
LGTM overall with a comment for the test. |
pkg/server/helpers.go
Outdated
| // sandboxMetadataLabel is label name that identify metadata of container in CreateContainerRequest | ||
| containerMetadataLabel = "io.cri-containerd.container.metadata" | ||
| // containerKindLabel is a label key indicating container is sandbox container or application container | ||
| containerKindLabel = "io.cri-containerd.kind" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit: Can we add a constant prefix = "io.cri-containerd"
And then use this for all the constants ?
for eg: containerKindLabel= prefix + "kind"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
fix containerd#251 Signed-off-by: yanxuean <[email protected]>
ee4667a to
e1a7a0e
Compare
|
LGTM |
fix #251
Signed-off-by: yanxuean [email protected]