Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Conversation

@yanxuean
Copy link
Member

fix #251

Signed-off-by: yanxuean [email protected]

@yanxuean
Copy link
Member Author

wait to rebase after #209 is merged.

@yanxuean yanxuean force-pushed the use-containerd-extension branch from bd64262 to 76154bc Compare September 19, 2017 08:10
// 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
Copy link
Contributor

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".

Copy link
Member Author

@yanxuean yanxuean Sep 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Thanks for review

@yanxuean yanxuean force-pushed the use-containerd-extension branch from 76154bc to e222056 Compare September 19, 2017 10:53
containerd.WithSpec(spec, specOpts...),
containerd.WithRuntime(defaultRuntime, nil),
containerd.WithContainerLabels(labels))
containerd.WithContainerExtension(containerMetadataExtension, &meta))
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// 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"
Copy link
Member

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.

Copy link
Member Author

@yanxuean yanxuean Sep 20, 2017

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

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

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...)

)

func init() {
typeurl.Register(&containerstore.Metadata{}, "github.com/kubernetes-incubator/cri-containerd/pkg/store/container", "Metadata")
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

)

func init() {
typeurl.Register(&sandboxstore.Metadata{}, "github.com/kubernetes-incubator/cri-containerd/pkg/store/sandbox", "Metadata")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Random-Liu Random-Liu self-assigned this Sep 19, 2017
@Random-Liu Random-Liu added this to the v1.0.0-alpha.0 milestone Sep 19, 2017
@yanxuean yanxuean force-pushed the use-containerd-extension branch from e222056 to 4479718 Compare September 20, 2017 06:32
Version string
Metadata
Version string
Metadata metadataInternal
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense.

@yanxuean yanxuean force-pushed the use-containerd-extension branch 4 times, most recently from 461969c to ee4667a Compare September 20, 2017 08:03
data, err := json.Marshal(meta)
assert.NoError(err)
assert.NoError(json.Unmarshal(data, newMeta))
assert.Equal(meta, newMeta)
Copy link
Member

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?

  1. Your first case. (verify that data could be stored and recovered)
  2. Make sure json.Marshal(Metadata) and json.Marshal(versionedMetadata) get the same bytes result; (verify that data is stored as versioned data, case1) has proved that versioned data could be recovered)
  3. json.Marshal(unsupportedVersionedMetadata) and then json.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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Random-Liu
Copy link
Member

Random-Liu commented Sep 20, 2017

LGTM overall with a comment for the test.
Please update the test, and I'll merge this tomorrow! @yanxuean Thanks for working on this.

// 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"
Copy link
Member

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"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@yanxuean yanxuean force-pushed the use-containerd-extension branch from ee4667a to e1a7a0e Compare September 20, 2017 16:23
@Random-Liu
Copy link
Member

LGTM

@Random-Liu Random-Liu merged commit 5dbba59 into containerd:master Sep 20, 2017
@yanxuean yanxuean deleted the use-containerd-extension branch September 21, 2017 02:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch to containerd extension

5 participants