Skip to content

Commit d6c26df

Browse files
committed
Drop --json/--no-json and create.json
[#143034769]
1 parent ba94581 commit d6c26df

15 files changed

Lines changed: 95 additions & 295 deletions

File tree

README.md

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ create:
144144
| create.with\_clean | Clean up unused layers before creating rootfs |
145145
| create.uid_mappings | UID mapping for image translation, e.g.: \<Namespace UID\>:\<Host UID\>:\<Size\> |
146146
| create.gid_mappings | GID mapping for image translation, e.g.: \<Namespace GID\>:\<Host GID\>:\<Size\> |
147-
| create.json | Format the output as JSON |
148-
| create.without_mount | Don't perform the rootfs mount and return the mount information in the json output. Only usable with --json. |
147+
| create.without_mount | Don't perform the rootfs mount. |
149148
| clean.ignore\_images | Images to ignore during cleanup |
150149
| clean.threshold\_bytes | Disk usage of the store directory at which cleanup should trigger |
151150
@@ -198,35 +197,22 @@ grootfs --store /mnt/btrfs create /my-rootfs.tar my-image-id
198197

199198
#### Output
200199

201-
The output of this command is the image path
202-
(`/mnt/btrfs/images/<uid>/my-image-id`) which has the following structure:
203-
204-
* The `<uid>` is the effective user id running the command.
200+
The output of this command is a json object which has the following structure:
205201

206202
```
207-
<Returned directory>
208-
|____ rootfs/
209-
|____ image.json
203+
{
204+
"rootfs": "...", # complete path to the image rootfs, which lives in <image-path>/rootfs
205+
"config": {...}, # contents of image config, also writen to <image-path>/image.json
206+
}
210207
```
211208

212-
* The `rootfs` folder is where the root filesystem lives.
213-
* The `image.json` file follows the [OCI image
209+
* The `<image-path>/rootfs` folder is where the root filesystem lives.
210+
* The `<image-path>/image.json` file follows the [OCI image
214211
description](https://github.com/opencontainers/image-spec/blob/master/serialization.md#image-json-description)
215212
schema.
216213

217-
##### JSON
218-
219-
When create is provided with a `--json` flag, it will print the output as json.
220-
The json will contain:
221-
222-
```
223-
{
224-
"rootfs": "...", # complete path to the image rootfs
225-
"config": {...}, # contents of image config, also writen to <image-path>/image.json
226-
}
227-
```
228214

229-
If `--without-mount` flag is provided (or `create.without_mount = true` in config),
215+
If the `--without-mount` flag is provided (or `create.without_mount = true` in config),
230216
the json output will also contain the `mount` key:
231217

232218
```
@@ -240,11 +226,10 @@ the json output will also contain the `mount` key:
240226
...
241227
```
242228

243-
Special notes about `--without-mount`/`create.without_mount`:
229+
The `--without-mount` option exists so that GrootFS can be run as non-root. The mount information is compatible
230+
with [OCI container spec](https://github.com/opencontainers/runtime-spec/blob/master/config.md#example-linux).
231+
244232

245-
* It can only be used in combination with the `--json` (or `create.json` in config) option
246-
* This option exists so that GrootFS can be run as non-root. The mount information
247-
is compatible with [OCI container spec](https://github.com/opencontainers/runtime-spec/blob/master/config.md#example-linux).
248233

249234
#### User/Group ID Mapping
250235

commands/config/builder.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type Create struct {
2727
ExcludeImageFromQuota bool `yaml:"exclude_image_from_quota"`
2828
WithClean bool `yaml:"with_clean"`
2929
WithoutMount bool `yaml:"without_mount"`
30-
Json bool `yaml:"json"`
3130
DiskLimitSizeBytes int64 `yaml:"disk_limit_size_bytes"`
3231
InsecureRegistries []string `yaml:"insecure_registries"`
3332
GIDMappings []string `yaml:"gid_mappings"`
@@ -228,18 +227,6 @@ func (b *Builder) WithMount(mount bool, noMount bool) *Builder {
228227
return b
229228
}
230229

231-
func (b *Builder) WithJson(json bool, noJson bool) *Builder {
232-
if json {
233-
b.config.Create.Json = true
234-
}
235-
236-
if noJson {
237-
b.config.Create.Json = false
238-
}
239-
240-
return b
241-
}
242-
243230
func load(configPath string) (Config, error) {
244231
configContent, err := ioutil.ReadFile(configPath)
245232
if err != nil {

commands/config/builder_test.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ var _ = Describe("Builder", func() {
3131
GIDMappings: []string{"config-gid-mapping"},
3232
InsecureRegistries: []string{"http://example.org"},
3333
DiskLimitSizeBytes: int64(1000),
34-
Json: false,
3534
}
3635

3736
cleanCfg = config.Clean{
@@ -602,47 +601,6 @@ var _ = Describe("Builder", func() {
602601
})
603602
})
604603

605-
Describe("WithJson", func() {
606-
Context("when no-json is set, and json is not set", func() {
607-
BeforeEach(func() {
608-
cfg.Create.Json = true
609-
})
610-
611-
It("overrides the config's entry", func() {
612-
builder = builder.WithJson(false, true)
613-
config, err := builder.Build()
614-
Expect(err).NotTo(HaveOccurred())
615-
Expect(config.Create.Json).To(BeFalse())
616-
})
617-
})
618-
619-
Context("when no-json is not set, and json is set", func() {
620-
BeforeEach(func() {
621-
cfg.Create.Json = false
622-
})
623-
624-
It("overrides the config's entry", func() {
625-
builder = builder.WithJson(true, false)
626-
config, err := builder.Build()
627-
Expect(err).NotTo(HaveOccurred())
628-
Expect(config.Create.Json).To(BeTrue())
629-
})
630-
})
631-
632-
Context("when no-json is not set, and json is not set", func() {
633-
BeforeEach(func() {
634-
cfg.Create.Json = true
635-
})
636-
637-
It("uses the config value", func() {
638-
builder = builder.WithJson(false, false)
639-
config, err := builder.Build()
640-
Expect(err).NotTo(HaveOccurred())
641-
Expect(config.Create.Json).To(BeTrue())
642-
})
643-
})
644-
})
645-
646604
Describe("WithMount", func() {
647605
Context("when without-mount is set, and with-mount is not set", func() {
648606
BeforeEach(func() {

commands/create.go

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,7 @@ var CreateCommand = cli.Command{
7171
},
7272
cli.BoolFlag{
7373
Name: "without-mount",
74-
Usage: "Do not mount the root filesystem. Must be used in conjunction with --json.",
75-
},
76-
cli.BoolFlag{
77-
Name: "json",
78-
Usage: "Print RootFS Path and container config as JSON",
79-
},
80-
cli.BoolFlag{
81-
Name: "no-json",
82-
Usage: "Do NOT print RootFS Path and container config as JSON",
74+
Usage: "Do not mount the root filesystem.",
8375
},
8476
cli.StringFlag{
8577
Name: "username",
@@ -110,7 +102,6 @@ var CreateCommand = cli.Command{
110102
WithExcludeImageFromQuota(ctx.Bool("exclude-image-from-quota"),
111103
ctx.IsSet("exclude-image-from-quota")).
112104
WithClean(ctx.IsSet("with-clean"), ctx.IsSet("without-clean")).
113-
WithJson(ctx.IsSet("json"), ctx.IsSet("no-json")).
114105
WithMount(ctx.IsSet("with-mount"), ctx.IsSet("without-mount"))
115106

116107
cfg, err := configBuilder.Build()
@@ -218,7 +209,6 @@ var CreateCommand = cli.Command{
218209

219210
createSpec := groot.CreateSpec{
220211
ID: id,
221-
Json: cfg.Create.Json,
222212
Mount: !cfg.Create.WithoutMount,
223213
BaseImage: baseImage,
224214
DiskLimit: cfg.Create.DiskLimitSizeBytes,
@@ -236,19 +226,12 @@ var CreateCommand = cli.Command{
236226
return newExitError(humanizedError, 1)
237227
}
238228

239-
var output string
240-
if cfg.Create.Json {
241-
jsonBytes, err := json.Marshal(image)
242-
if err != nil {
243-
logger.Error("formatting output", err)
244-
return newExitError(err.Error(), 1)
245-
}
246-
output = string(jsonBytes)
247-
} else {
248-
output = image.Path
229+
jsonBytes, err := json.Marshal(image)
230+
if err != nil {
231+
logger.Error("formatting output", err)
232+
return newExitError(err.Error(), 1)
249233
}
250-
251-
fmt.Println(output)
234+
fmt.Println(string(jsonBytes))
252235

253236
usage, err := sm.MeasureStore(logger)
254237
if err != nil {
@@ -344,13 +327,5 @@ func validateOptions(ctx *cli.Context, cfg config.Config) error {
344327
return errorspkg.New("with-clean and without-clean cannot be used together")
345328
}
346329

347-
if ctx.IsSet("json") && ctx.IsSet("no-json") {
348-
return errorspkg.New("json and no-json cannot be used together")
349-
}
350-
351-
if cfg.Create.WithoutMount && !cfg.Create.Json {
352-
return errorspkg.New("without-mount option must be used with the json option")
353-
}
354-
355330
return nil
356331
}

groot/creator.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ type CreateSpec struct {
1717
ID string
1818
BaseImage string
1919
DiskLimit int64
20-
Json bool
2120
Mount bool
2221
ExcludeBaseImageFromQuota bool
2322
CleanOnCreate bool

integration/create_local_test.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ var _ = Describe("Create with local images", func() {
4949
BaseImage: baseImagePath,
5050
ID: "random-id",
5151
Mount: mountByDefault(),
52-
Json: true,
5352
}
5453
})
5554

@@ -87,7 +86,6 @@ var _ = Describe("Create with local images", func() {
8786
ID: "another-random-id",
8887
BaseImage: baseImagePath,
8988
Mount: false,
90-
Json: true,
9189
})
9290
Expect(err).NotTo(HaveOccurred())
9391

@@ -127,7 +125,6 @@ var _ = Describe("Create with local images", func() {
127125
ID: "my-image-1",
128126
BaseImage: baseImagePath,
129127
Mount: true,
130-
Json: true,
131128
})
132129
Expect(err).NotTo(HaveOccurred())
133130

@@ -146,7 +143,6 @@ var _ = Describe("Create with local images", func() {
146143
ID: "my-image-2",
147144
BaseImage: baseImage2Path,
148145
Mount: true,
149-
Json: true,
150146
}
151147
_, err := Runner.Create(createSpec)
152148
Expect(err).NotTo(HaveOccurred())
@@ -234,7 +230,6 @@ var _ = Describe("Create with local images", func() {
234230
ID: "random-id-2",
235231
BaseImage: baseImagePath,
236232
Mount: mountByDefault(),
237-
Json: true,
238233
})
239234
Expect(err).NotTo(HaveOccurred())
240235
Expect(Runner.EnsureMounted(image)).To(Succeed())
@@ -259,7 +254,6 @@ var _ = Describe("Create with local images", func() {
259254
ID: "random-id-2",
260255
BaseImage: baseImagePath,
261256
Mount: mountByDefault(),
262-
Json: true,
263257
})
264258
Expect(Runner.EnsureMounted(image)).To(Succeed())
265259
Expect(err).NotTo(HaveOccurred())
@@ -274,7 +268,6 @@ var _ = Describe("Create with local images", func() {
274268
BaseImage: "/invalid/image",
275269
ID: "random-id",
276270
Mount: false,
277-
Json: true,
278271
})
279272
Expect(err).To(MatchError(ContainSubstring("stat /invalid/image: no such file or directory")))
280273
})

integration/create_overlayxfs_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ var _ = Describe("Create (overlay-xfs only)", func() {
4444
BaseImage: baseImagePath,
4545
ID: "random-id",
4646
Mount: mountByDefault(),
47-
Json: !mountByDefault(),
4847
DiskLimit: tenMegabytes,
4948
}
5049
})

0 commit comments

Comments
 (0)