mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 16:27:50 +00:00
virtcontainers: change pass by value to pass by reference
container.config does not point to sandbox.config.Containers.ContainerConfig which caused the ContainerConfig not sync. Fixes: #2129 Signed-off-by: Wang Liang <wangliangzz@inspur.com>
This commit is contained in:
parent
c7b4c5eab9
commit
24d7aff60c
@ -717,7 +717,7 @@ func (c *Container) createBlockDevices() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newContainer creates a Container structure from a sandbox and a container configuration.
|
// newContainer creates a Container structure from a sandbox and a container configuration.
|
||||||
func newContainer(sandbox *Sandbox, contConfig ContainerConfig) (*Container, error) {
|
func newContainer(sandbox *Sandbox, contConfig *ContainerConfig) (*Container, error) {
|
||||||
span, _ := sandbox.trace("newContainer")
|
span, _ := sandbox.trace("newContainer")
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
|
|
||||||
@ -729,7 +729,7 @@ func newContainer(sandbox *Sandbox, contConfig ContainerConfig) (*Container, err
|
|||||||
id: contConfig.ID,
|
id: contConfig.ID,
|
||||||
sandboxID: sandbox.id,
|
sandboxID: sandbox.id,
|
||||||
rootFs: contConfig.RootFs,
|
rootFs: contConfig.RootFs,
|
||||||
config: &contConfig,
|
config: contConfig,
|
||||||
sandbox: sandbox,
|
sandbox: sandbox,
|
||||||
runPath: store.ContainerRuntimeRootPath(sandbox.id, contConfig.ID),
|
runPath: store.ContainerRuntimeRootPath(sandbox.id, contConfig.ID),
|
||||||
configPath: store.ContainerConfigurationRootPath(sandbox.id, contConfig.ID),
|
configPath: store.ContainerConfigurationRootPath(sandbox.id, contConfig.ID),
|
||||||
@ -812,7 +812,7 @@ func (c *Container) createMounts() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) createDevices(contConfig ContainerConfig) error {
|
func (c *Container) createDevices(contConfig *ContainerConfig) error {
|
||||||
// If sandbox supports "newstore", only newly created container can reach this function,
|
// If sandbox supports "newstore", only newly created container can reach this function,
|
||||||
// so we don't call restore when `supportNewStore` is true
|
// so we don't call restore when `supportNewStore` is true
|
||||||
if !c.sandbox.supportNewStore() {
|
if !c.sandbox.supportNewStore() {
|
||||||
|
@ -1099,7 +1099,7 @@ func (s *Sandbox) fetchContainers() error {
|
|||||||
contConfig.Spec = &spec
|
contConfig.Spec = &spec
|
||||||
s.config.Containers[i] = contConfig
|
s.config.Containers[i] = contConfig
|
||||||
|
|
||||||
c, err := newContainer(s, contConfig)
|
c, err := newContainer(s, &s.config.Containers[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1118,7 +1118,7 @@ func (s *Sandbox) fetchContainers() error {
|
|||||||
func (s *Sandbox) CreateContainer(contConfig ContainerConfig) (VCContainer, error) {
|
func (s *Sandbox) CreateContainer(contConfig ContainerConfig) (VCContainer, error) {
|
||||||
storeAlreadyExists := store.VCContainerStoreExists(s.ctx, s.id, contConfig.ID)
|
storeAlreadyExists := store.VCContainerStoreExists(s.ctx, s.id, contConfig.ID)
|
||||||
// Create the container.
|
// Create the container.
|
||||||
c, err := newContainer(s, contConfig)
|
c, err := newContainer(s, &contConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1417,7 +1417,7 @@ func (s *Sandbox) createContainers() error {
|
|||||||
|
|
||||||
for _, contConfig := range s.config.Containers {
|
for _, contConfig := range s.config.Containers {
|
||||||
|
|
||||||
c, err := newContainer(s, contConfig)
|
c, err := newContainer(s, &contConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -621,7 +621,7 @@ func TestSandboxGetContainer(t *testing.T) {
|
|||||||
|
|
||||||
contID := "999"
|
contID := "999"
|
||||||
contConfig := newTestContainerConfigNoop(contID)
|
contConfig := newTestContainerConfigNoop(contID)
|
||||||
nc, err := newContainer(p, contConfig)
|
nc, err := newContainer(p, &contConfig)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
err = p.addContainer(nc)
|
err = p.addContainer(nc)
|
||||||
@ -1043,7 +1043,7 @@ func TestDeleteStoreWhenNewContainerFail(t *testing.T) {
|
|||||||
DevType: "",
|
DevType: "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = newContainer(p, contConfig)
|
_, err = newContainer(p, &contConfig)
|
||||||
assert.NotNil(t, err, "New container with invalid device info should fail")
|
assert.NotNil(t, err, "New container with invalid device info should fail")
|
||||||
storePath := store.ContainerConfigurationRootPath(testSandboxID, contID)
|
storePath := store.ContainerConfigurationRootPath(testSandboxID, contID)
|
||||||
_, err = os.Stat(storePath)
|
_, err = os.Stat(storePath)
|
||||||
|
Loading…
Reference in New Issue
Block a user