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

Commit

Permalink
virtcontainers: Remove ConfigJSONKey annotation
Browse files Browse the repository at this point in the history
Currently we already saved "BundlePath" in sandbox and config's config, with
`BundlePath`, we can easily get config of json format from "BundlePath"/config.json,
So ConfigJSONKey is a duplicate and unnecessary field and we can remove it for
saving more space from persist data.

Fixes: #215

Signed-off-by: Zhang Wei <[email protected]>
  • Loading branch information
WeiZhang555 committed Apr 17, 2018
1 parent ad5669f commit fbdcb79
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 101 deletions.
2 changes: 1 addition & 1 deletion cli/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func createSandbox(ociSpec oci.CompatOCISpec, runtimeConfig oci.RuntimeConfig,
return vc.Process{}, err
}

sandboxConfig, err := oci.SandboxConfig(ociSpec, runtimeConfig, bundlePath, containerID, console, disableOutput)
sandboxConfig, err := oci.SandboxConfig(runtimeConfig, bundlePath, containerID, console, disableOutput)
if err != nil {
return vc.Process{}, err
}
Expand Down
37 changes: 12 additions & 25 deletions cli/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ func TestDeleteSandbox(t *testing.T) {
}

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
return []vc.SandboxStatus{
Expand All @@ -182,7 +180,7 @@ func TestDeleteSandbox(t *testing.T) {
ID: sandbox.ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
},
State: vc.State{
State: "ready",
Expand All @@ -197,7 +195,7 @@ func TestDeleteSandbox(t *testing.T) {
testingImpl.ListSandboxFunc = nil
}()

err = delete(sandbox.ID(), false)
err := delete(sandbox.ID(), false)
assert.Error(err)
assert.True(vcmock.IsMockError(err))

Expand Down Expand Up @@ -233,9 +231,6 @@ func TestDeleteInvalidContainerType(t *testing.T) {
}

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
return []vc.SandboxStatus{
{
Expand All @@ -245,7 +240,7 @@ func TestDeleteInvalidContainerType(t *testing.T) {
ID: sandbox.ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: "InvalidType",
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
},
State: vc.State{
State: "created",
Expand All @@ -261,7 +256,7 @@ func TestDeleteInvalidContainerType(t *testing.T) {
}()

// Delete an invalid container type
err = delete(sandbox.ID(), false)
err := delete(sandbox.ID(), false)
assert.Error(err)
assert.False(vcmock.IsMockError(err))
}
Expand All @@ -274,8 +269,6 @@ func TestDeleteSandboxRunning(t *testing.T) {
}

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
return []vc.SandboxStatus{
Expand All @@ -286,7 +279,7 @@ func TestDeleteSandboxRunning(t *testing.T) {
ID: sandbox.ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
},
State: vc.State{
State: "running",
Expand All @@ -302,7 +295,7 @@ func TestDeleteSandboxRunning(t *testing.T) {
}()

// Delete on a running sandbox should fail
err = delete(sandbox.ID(), false)
err := delete(sandbox.ID(), false)
assert.Error(err)
assert.False(vcmock.IsMockError(err))

Expand Down Expand Up @@ -346,8 +339,6 @@ func TestDeleteRunningContainer(t *testing.T) {
}

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
return []vc.SandboxStatus{
Expand All @@ -358,7 +349,7 @@ func TestDeleteRunningContainer(t *testing.T) {
ID: sandbox.MockContainers[0].ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
},
State: vc.State{
State: "running",
Expand All @@ -374,7 +365,7 @@ func TestDeleteRunningContainer(t *testing.T) {
}()

// Delete on a running container should fail.
err = delete(sandbox.MockContainers[0].ID(), false)
err := delete(sandbox.MockContainers[0].ID(), false)
assert.Error(err)
assert.False(vcmock.IsMockError(err))

Expand Down Expand Up @@ -419,8 +410,6 @@ func TestDeleteContainer(t *testing.T) {
}

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
return []vc.SandboxStatus{
Expand All @@ -431,7 +420,7 @@ func TestDeleteContainer(t *testing.T) {
ID: sandbox.MockContainers[0].ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
},
State: vc.State{
State: "ready",
Expand All @@ -446,7 +435,7 @@ func TestDeleteContainer(t *testing.T) {
testingImpl.ListSandboxFunc = nil
}()

err = delete(sandbox.MockContainers[0].ID(), false)
err := delete(sandbox.MockContainers[0].ID(), false)
assert.Error(err)
assert.True(vcmock.IsMockError(err))

Expand Down Expand Up @@ -511,8 +500,6 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
}

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
return []vc.SandboxStatus{
Expand All @@ -523,7 +510,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
ID: sandbox.ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
},
State: vc.State{
State: "ready",
Expand Down Expand Up @@ -556,7 +543,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
fn, ok := deleteCLICommand.Action.(func(context *cli.Context) error)
assert.True(ok)

err = fn(ctx)
err := fn(ctx)
assert.Error(err)
assert.False(vcmock.IsMockError(err))

Expand Down
32 changes: 8 additions & 24 deletions cli/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ func TestExecuteErrors(t *testing.T) {

// Container state undefined
configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

annotations = map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
}

containerState := vc.State{}
Expand Down Expand Up @@ -149,12 +147,10 @@ func TestExecuteErrorReadingProcessJson(t *testing.T) {
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

annotations := map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
}

state := vc.State{
Expand Down Expand Up @@ -193,12 +189,10 @@ func TestExecuteErrorOpeningConsole(t *testing.T) {
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

annotations := map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
}

state := vc.State{
Expand Down Expand Up @@ -255,12 +249,10 @@ func TestExecuteWithFlags(t *testing.T) {
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

annotations := map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
}

state := vc.State{
Expand Down Expand Up @@ -339,12 +331,10 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

annotations := map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
}

state := vc.State{
Expand Down Expand Up @@ -413,12 +403,10 @@ func TestExecuteWithInvalidProcessJson(t *testing.T) {
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

annotations := map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
}

state := vc.State{
Expand Down Expand Up @@ -460,12 +448,10 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

annotations := map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
}

state := vc.State{
Expand Down Expand Up @@ -552,12 +538,10 @@ func TestExecuteWithInvalidEnvironment(t *testing.T) {
ctx := cli.NewContext(cli.NewApp(), flagSet, nil)

configPath := testConfigSetup(t)
configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

annotations := map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: configJSON,
vcAnnotations.BundlePathKey: filepath.Dir(configPath),
}

state := vc.State{
Expand Down
18 changes: 7 additions & 11 deletions cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ type runContainerData struct {
pidFilePath string
consolePath string
bundlePath string
configJSON string
sandbox *vcmock.Sandbox
runtimeConfig oci.RuntimeConfig
process *os.Process
Expand Down Expand Up @@ -193,7 +192,7 @@ func testRunContainerSetup(t *testing.T) runContainerData {
assert.NoError(err)

// config json path
configPath := filepath.Join(bundlePath, specConfig)
filepath.Join(bundlePath, specConfig)

// sandbox id and container id must be the same otherwise delete will not works
sandbox := &vcmock.Sandbox{
Expand All @@ -212,14 +211,10 @@ func testRunContainerSetup(t *testing.T) runContainerData {
runtimeConfig, err := newTestRuntimeConfig(tmpdir, consolePath, true)
assert.NoError(err)

configJSON, err := readOCIConfigJSON(configPath)
assert.NoError(err)

return runContainerData{
pidFilePath: pidFilePath,
consolePath: consolePath,
bundlePath: bundlePath,
configJSON: configJSON,
sandbox: sandbox,
runtimeConfig: runtimeConfig,
process: cmd.Process,
Expand Down Expand Up @@ -261,7 +256,7 @@ func TestRunContainerSuccessful(t *testing.T) {
ID: d.sandbox.ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: d.configJSON,
vcAnnotations.BundlePathKey: d.bundlePath,
},
},
},
Expand Down Expand Up @@ -337,7 +332,7 @@ func TestRunContainerDetachSuccessful(t *testing.T) {
ID: d.sandbox.ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: d.configJSON,
vcAnnotations.BundlePathKey: d.bundlePath,
},
},
},
Expand Down Expand Up @@ -410,7 +405,7 @@ func TestRunContainerDeleteFail(t *testing.T) {
ID: d.sandbox.ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: d.configJSON,
vcAnnotations.BundlePathKey: d.bundlePath,
},
},
},
Expand Down Expand Up @@ -486,7 +481,7 @@ func TestRunContainerWaitFail(t *testing.T) {
ID: d.sandbox.ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: d.configJSON,
vcAnnotations.BundlePathKey: d.bundlePath,
},
},
},
Expand Down Expand Up @@ -570,7 +565,7 @@ func TestRunContainerStartFail(t *testing.T) {
ID: d.sandbox.ID(),
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
vcAnnotations.ConfigJSONKey: d.configJSON,
vcAnnotations.BundlePathKey: d.bundlePath,
},
},
},
Expand Down Expand Up @@ -625,6 +620,7 @@ func TestRunContainerStartFailNoContainers(t *testing.T) {
ID: testContainerID,
Annotations: map[string]string{
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
vcAnnotations.BundlePathKey: d.bundlePath,
},
},
},
Expand Down
Loading

0 comments on commit fbdcb79

Please sign in to comment.