Uh oh!
There was an error while loading. Please reload this page.
Move generate code into a separate library - #131
Conversation
haiyanmeng
commented
Jul 9, 2016
@mrunalp , PTAL. |
haiyanmeng
commented
Jul 9, 2016
| "strings" | ||
| "github.com/Sirupsen/logrus" | ||
| "github.com/opencontainers/ocitools/libgen" |
There was a problem hiding this comment.
There was a reasonable amount of “what should we call this?” discussion in #128, which resolved around seccomp-gen. If we're aiming for separate generate/validate/(test?) commands, we probably want something like:
ocitools
|-- cmd
| `-- ocitools
| |-- main.go
| |-- generate.go
| |-- validate.go
| …
|-- generate
| |-- generate.go
| |-- utils.go, etc.
| `-- seccomp (#128)
| |-- consts.go
| …
|-- validate
| |-- validate.go
| `-- utils.go
…
Shifting the import paths around while we settle into whatever layout we choose isn't a big deal as long as we don't cut releases. But I expect that the libraries will start picking up external consumers shortly after they're born, and we'll make life easier on those downstream folks if we don't churn the layout too much ;).
There was a problem hiding this comment.
@wking , this new package structure looks very different from the current package structure.
ocitools
|-- cmd
| `-- runtimetest
| |-- main.go
| |-- rlimit_linux.go
| |-- mount
| |-- mountinfo_freebsd.go
| |-- mountinfo.go
| |-- mountinfo_linux.go
| |-- mountinfo_solaris.go
| |-- mountinfo_unsupported.go
| |-- mountinfo_windows.go
|-- main.go
|-- generate.go
|-- validate.go
There was a problem hiding this comment.
On Mon, Jul 11, 2016 at 07:09:30AM -0700, hmeng-19 wrote:
@@ -9,9 +9,8 @@ import (
"strconv"
"strings"
- "github.com/Sirupsen/logrus"
- "github.com/opencontainers/ocitools/libgen"
@wking , this new package structure looks very different from the
current package structure…
Yeah, but if we're going to restructure things, I think we want to
take a big step to get to where we (think we) want to be, instead of
taking a bunch of short steps. The big step may not be perfect, but
it's got a better chance at being right than a small step after which
we already plan on making further changes.
There was a problem hiding this comment.
@wking proposed layout scheme looks reasonable to me.
There was a problem hiding this comment.
@wking , @mrunalp . Sounds good. I will modify the code structure as @wking suggested.
@wking , in your proposal, there are two generate.go - one is under cmd/ocitools, another is under generate. What is their difference? The same problem happens to validate.go.
I think all the files under generate and validate should be libraries, right?
There was a problem hiding this comment.
On Mon, Jul 11, 2016 at 11:36:11AM -0700, hmeng-19 wrote:
@wking , in your proposal, there are two
generate.go- one is
undercmd/ocitools, another is undergenerate. What is their
difference? The same problem happens tovalidate.go.
The cmd/ocitools stuff is just thin bindings between the library code
(under generate/, validate/, etc.) and urfave/cli.
I think all the files under
generateandvalidateshould be
libraries, right?
Yup.
wking
commented
Jul 9, 2016
On Fri, Jul 08, 2016 at 08:02:51PM -0700, hmeng-19 wrote:
This is also going to create some tedious conflicts with #54 (now |
| } | ||
| // AddIDMappings add the mappings of uid and gid into spec. | ||
| func AddIDMappings(spec *rspec.Spec, uidMaps, gidMaps []string) error { |
There was a problem hiding this comment.
This should probably be a single:
func ParseIDMappings(spec *rspec.Spec, idType string, maps []string) error {…}
which the command implementation can call with something like (untested, and I don't do much Go ;):
idTypes := ["uid", "gid"]
for idType := range idTypes {
maps := context.StringSlice(idType + "mappings")
if err := libgen.AddIDMappings(spec, idType, maps) err != nil {
return err
}
}
The approach your copy/pasting was acceptable for an internal helper, but it seems like we should aim for something DRYer for a library method. On the other hand, I'm fine cleaning this stuff up in follow-up PRs, as long as we don't wait long enough for API-breaking to become a concern.
mrunalp
commented
Jul 11, 2016
haiyanmeng
commented
Jul 11, 2016
haiyanmeng
commented
Jul 11, 2016
@mrunalp , @wking , the CI checks failed because this PR tries to introduce a new package |
haiyanmeng
commented
Jul 11, 2016
@mrunalp , @wking , the new changes I made include: The new changes focus on the package structure, does not really polish the function API. |
On Mon, Jul 11, 2016 at 02:37:44PM -0700, hmeng-19 wrote:
Actually, I think that's failing because you haven't added |
haiyanmeng
commented
Jul 11, 2016
@wking , you are right. My |
wking
commented
Jul 11, 2016
On Mon, Jul 11, 2016 at 02:55:12PM -0700, hmeng-19 wrote:
Ah, the ‘ocitools’ entry in .gitignore should probably be ‘/ocitools’ I'm not sure what the ‘oci’ entry in .gitignore is for. It's from |
haiyanmeng
commented
Jul 11, 2016
@wking , I think the problem is the pattern Please refer to here https://git-scm.com/docs/gitignore . |
haiyanmeng
commented
Jul 11, 2016
wking
commented
Jul 11, 2016
Through fed976f look fine to me if we want to shuffle things around But I don't see a need to split “restructure and reconsider the API” |
grantseltzer
commented
Jul 12, 2016
wking
commented
Jul 12, 2016
On Tue, Jul 12, 2016 at 07:13:44AM -0700, Grant Seltzer Richman wrote:
Whatever's easier, but you can rebase your existing #128 branch once |
| Flags: generateFlags, | ||
| Before: before, | ||
| Action: func(context *cli.Context) error { | ||
| spec := generate.GetDefaultTemplate() |
There was a problem hiding this comment.
Again, a rename suggestion for GetDefaultTemplate to New
mrunalp
commented
Jul 13, 2016
commit history needs to be cleaned up or they should be squashed. |
haiyanmeng
commented
Jul 13, 2016
While this is a step in the right direction, I think API like the following will be easier to use: typegeneratorstruct {
spec*rspec.Spec
}
// Start from default templatespecgen:=generator.New()
// Make modificationsspecgen.SetRootPath("/path/to/rootfs")
specgen.AddCapabilities(...)
specgen.AddTmpfsMount(...)
specgen.SetSelinuxLabel(...)
......// Write to disk
specgen.Save("/path/to/file")
// Get back the spec objectspec:=specgen.GetSpec()
// Load a template.jsonspecgen:= generator.NewFromTemplate("/path/to/file")
specgen.AddMount(src, dest, options..)
specgen.Save("/some/other/path")
// Load existing spec object and modify it to generate a new specspecgen:=generator.NewFromSpec(someSpecObject)
specgen.SetNoNewPriviliges(true)
specgen.Save("/yet/another/path") |
wking
commented
Jul 13, 2016
On Wed, Jul 13, 2016 at 02:53:54PM -0700, Mrunal Patel wrote:
I'd load this from an io.Reader for more flexibility. Wrapping that |
mrunalp
commented
Jul 15, 2016
Please push your updates so the latest version could be reviewed. Sent from my iPhone
|
haiyanmeng
commented
Jul 15, 2016
| } | ||
| // ClearLinuxUIDMapping clears g.spec.Linux.UIDMappings. | ||
| func (g Generator) ClearLinuxUIDMapping() { |
haiyanmeng
commented
Jul 16, 2016
liangchenye
commented
Jul 18, 2016
0e6dfc0 LGTM |
| func checkCap(c string) error { | ||
| isValid := false | ||
| cp := fmt.Sprintf("CAP_%s", c) |
There was a problem hiding this comment.
This isn't required. The list you are checking against doesn't have CAP_
There was a problem hiding this comment.
The list I am checking against is capability.List(), which includes CAP_CHOWN, CAP_DAC_OVERRIDE, and so on.
There was a problem hiding this comment.
Ignore my comment. I got your point.
mrunalp
commented
Jul 18, 2016
--seccomp-default doesn't get populated |
mrunalp
commented
Jul 18, 2016
Also trying to add a capability or dropping it fails |
2a0235e to
9e31200Comparehaiyanmeng
commented
Jul 18, 2016
@mrunalp , fixed the problems you pointed out and also tested all the other options, PTAL. |
mrunalp
commented
Jul 18, 2016
Can you re-order or squash the commits? |
haiyanmeng
commented
Jul 18, 2016
@mrunalp , no problem. Are you done checking the latest changes? |
Signed-off-by: Haiyan Meng <hmeng@redhat.com>
mrunalp
commented
Jul 18, 2016
@hmeng-19 Yeah, the changes look good and am ready to merge. |
haiyanmeng
commented
Jul 18, 2016
@mrunalp , I sqashed the commits. |
mrunalp
commented
Jul 18, 2016
LGTM |
Move generate code into a separate library,
libgen.To avoid using
cli.Contextinsidelibgen, themodifyfunction responds to get the command options, and transfer them into the functions insidelibgen.The PR tries to fix#130 .