Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

cli: implement spec command#196

Merged
jodh-intel merged 1 commit intokata-containers:masterfrom
caoruidong:add-spec
Apr 17, 2018
Merged

cli: implement spec command#196
jodh-intel merged 1 commit intokata-containers:masterfrom
caoruidong:add-spec

Conversation

@caoruidong
Copy link
Copy Markdown
Member

Add spec command that that generates a basic config.json for kata.

fixes #188

Signed-off-by: Ruidong Cao caoruidong@huawei.com

@caoruidong caoruidong force-pushed the add-spec branch 3 times, most recently from c7e05a3 to b2c2805 Compare April 10, 2018 16:05
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2018

Codecov Report

Merging #196 into master will decrease coverage by 0.07%.
The diff coverage is 38.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #196      +/-   ##
==========================================
- Coverage   65.33%   65.26%   -0.08%     
==========================================
  Files          73       74       +1     
  Lines        7709     7730      +21     
==========================================
+ Hits         5037     5045       +8     
- Misses       2128     2135       +7     
- Partials      544      550       +6
Impacted Files Coverage Δ
cli/main.go 92.37% <ø> (ø) ⬆️
cli/spec.go 38.09% <38.09%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 427b97c...b528ef2. Read the comment docs.

@@ -0,0 +1,108 @@
package main
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

missing license

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

cli/spec.go Outdated
if err != nil {
return err
}
if err := ioutil.WriteFile(specConfig, data, 0666); err != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pure evil ehh 😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Change mode to 640?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

runc uses 0664

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think runc is using 0666: https://github.com/opencontainers/runc/blob/master/spec.go#L110

But I don't know why, I think 0640 could be enough.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

that's weird

$ docker-runc spec
$ ls -l config.json
-rw-rw-r-- 1 X X 597 Apr 11 10:33 config.json

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, let's do better than runc here, 0640 will be enough.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Usage: "generate a configuration for a rootless container",
},
},
Action: func(context *cli.Context) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

please add an unit test for this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Doing

cli/spec.go Outdated
cli.BoolFlag{
Name: "rootless",
Usage: "generate a configuration for a rootless container",
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure if we can support "rootless" container in kata in future, as I know this is a runc feature that allows you to run a container without root privilege.

This flag needs to be removed if it's not supported yet.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

cli/spec.go Outdated
rootless := context.Bool("rootless")
if rootless {
specconv.ToRootless(spec)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This part needs to be removed if rootless container isn't supported yet

@WeiZhang555
Copy link
Copy Markdown
Member

WeiZhang555 commented Apr 11, 2018

I'm wondering if these vendor files added by dep tool? Please update the vendor with dep tool, one reference link is:
#141

And thanks for adding spec command, this is useful especially for following runc command line.

@bergwolf
Copy link
Copy Markdown
Member

bergwolf commented Apr 11, 2018

Could you add a test case the makes sure we can run a kata container using the default spec? There is an example in runv for creating a busybox bundle that might help you.

@caoruidong
Copy link
Copy Markdown
Member Author

@bergwolf Sure. Thanks. I'm working on this.
@WeiZhang555 Yes. I will update with dep together with unit test.

@caoruidong caoruidong force-pushed the add-spec branch 2 times, most recently from 2dad24c to e6e88d1 Compare April 12, 2018 05:34
@caoruidong
Copy link
Copy Markdown
Member Author

caoruidong commented Apr 12, 2018

@WeiZhang555 Vendor updated.
@bergwolf After testing, the default spec can work with busybox. Do you mean that add a test case in spec_test.go to explicitly call kata-runtime run with default spec and busybox bundle ?
@ALL Is runc's example spec too long or inappropriate for kata-runtime? for example https://github.com/opencontainers/runc/blob/3cbb2fa3c4e8f307817317c455268c6e58703e0b/libcontainer/specconv/example.go#L66
Hostname: "runc",
Do we need to write our own spec example?

@bergwolf
Copy link
Copy Markdown
Member

@caoruidong I don't think we can do it in spec_test.go. I was thinking some place in https://github.com/kata-containers/tests. It does not block this PR though.

@caoruidong
Copy link
Copy Markdown
Member Author

@bergwolf So I think test_data/Makefile should be moved to https://github.com/kata-containers/tests.

@bergwolf
Copy link
Copy Markdown
Member

@caoruidong Feel free to use it when adding new tests. I just pointed to the runv tests for your reference.

@sboeuf
Copy link
Copy Markdown

sboeuf commented Apr 12, 2018

@devimc PTAL.

Copy link
Copy Markdown

@devimc devimc left a comment

Choose a reason for hiding this comment

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

lgtm

@caoruidong
Copy link
Copy Markdown
Member Author

@jodh-intel @WeiZhang555 PTAL

@devimc
Copy link
Copy Markdown

devimc commented Apr 13, 2018

@caoruidong rebase please

@WeiZhang555
Copy link
Copy Markdown
Member

WeiZhang555 commented Apr 13, 2018

LGTM after rebase.
Nice patch!

Approved with PullApprove

@caoruidong
Copy link
Copy Markdown
Member Author

Rebased!

@caoruidong
Copy link
Copy Markdown
Member Author

Can this be merged?

Copy link
Copy Markdown

@jodh-intel jodh-intel left a comment

Choose a reason for hiding this comment

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

lgtm. I'd better update kata-containers/documentation#48 to remove this limitation... ;)

jodh-intel pushed a commit to jodh-intel/documentation that referenced this pull request Apr 17, 2018
Update the limitations document to remove the `spec` command limitation
(implemented on kata-containers/runtime#196).

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
@jodh-intel
Copy link
Copy Markdown

Done on kata-containers/documentation@2f2956e.

@jodh-intel
Copy link
Copy Markdown

Tests fine in stand-alone mode fwiw (using the strategy below for kata-runtime):

@grahamwhaley
Copy link
Copy Markdown
Contributor

The only thing stopping the merge is the red codecov reports - if we are happy with that @jodh-intel , then let's merge...

cli/spec.go Outdated
// Copyright (c) 2014,2015,2016,2017 Docker, Inc.
// Copyright (c) 2018 Huawei Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I thought the standard for this project (the whole of kata) was the SPDX style copyright like:
https://github.com/kata-containers/runtime/blob/master/cli/fatal.go#L3
but, I note we have some non-SPDX copyright in the code base already, such as:
https://github.com/kata-containers/runtime/blob/master/cli/config.go#L3

@egernst @sboeuf @jodh-intel , thoughts?
And, maybe we can add a static check to catch any future deviations (whichever way we go) to the CI - maybe.

Other than that, this copyright looks correct to me afaict - the original code coming from https://github.com/opencontainers/runc/blob/master/spec.go I believe. That original file does not have an explicit copyright (it relies on the project wide LICENSE file I believe), so I presume we looked at the git logs to get the date range in the above - which I believe is fine and correct.

Maybe we can add a URL reference to that original file just below the copyright to make the historical origins clear?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

btw, if we do all agree on SPDX (which we did I think at project inception, but we probably did not document well enough, and have not always caught transgressions), then I'm happy to Issue/PR to update/fix them all etc.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good spot @grahamwhaley! Yep, I agree - we should ensure all our files have the SPDX header where possible.

I've raised kata-containers/tests#240 to add a CI check to enforce this for new / modified files, but would be great to have the existing codebase "SPDX-ified" 😄

@caoruidong
Copy link
Copy Markdown
Member Author

caoruidong commented Apr 17, 2018

@grahamwhaley It's green last time... I'll update again.
@jodh-intel SPDX-ing together.

Add spec command that generates a basic config.json for kata.

fixes kata-containers#188

Signed-off-by: Ruidong Cao <caoruidong@huawei.com>
Signed-off-by: Ruidong <caoruidong@huawei.com>
@jodh-intel
Copy link
Copy Markdown

yep - let's do this! ;)

@jodh-intel jodh-intel merged commit a4b7e20 into kata-containers:master Apr 17, 2018
jodh-intel pushed a commit to jodh-intel/documentation that referenced this pull request Apr 18, 2018
Update the limitations document to remove the `spec` command limitation
(implemented on kata-containers/runtime#196).

Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
@caoruidong caoruidong deleted the add-spec branch April 24, 2018 14:54
zklei pushed a commit to zklei/runtime that referenced this pull request Jun 13, 2019
agent: Rollback properly when container creation fails
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the spec command

7 participants