Skip to content

Commit b2e7e10

Browse files
committed
refactor: delete update specific code
Signed-off-by: Michael Wan <zirenwan@gmail.com>
1 parent 10cb5da commit b2e7e10

2 files changed

Lines changed: 15 additions & 19 deletions

File tree

apis/plugins/ContainerPlugin.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ type ContainerPlugin interface {
1212
// used to sort the pre start array that pass to runc, network plugin hook always has priority value 0.
1313
PreStart(interface{}) ([]int, [][]string, error)
1414

15-
//NetworkGenericParams accepts the container id and env of this container and returns the priority of this endpoint
15+
// PreCreateEndpoint accepts the container id and env of this container and returns the priority of this endpoint
1616
// and if this endpoint should enable resolver and a map which will be used as generic params to create endpoints of
1717
// this container
1818
PreCreateEndpoint(string, []string) (priority int, disableResolver bool, genericParam map[string]interface{})
1919

2020
// PreUpdate defines plugin point where receives a container update request, in this plugin point user
2121
// could change the container update body passed-in by http request body
2222
PreUpdate(io.ReadCloser) (io.ReadCloser, error)
23+
24+
// PostUpdate called after update method successful,
25+
// the method accepts the rootfs path and envs of container
26+
PostUpdate(string, []string) error
2327
}

daemon/mgr/container.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -930,13 +930,13 @@ func (mgr *ContainerManager) Update(ctx context.Context, name string, config *ty
930930
}
931931

932932
restore := false
933-
configBack := *c.Config
934-
hostconfigBack := *c.HostConfig
933+
oldConfig := *c.Config
934+
oldHostconfig := *c.HostConfig
935935
defer func() {
936936
if restore {
937937
c.Lock()
938-
c.Config = &configBack
939-
c.HostConfig = &hostconfigBack
938+
c.Config = &oldConfig
939+
c.HostConfig = &oldHostconfig
940940
c.Unlock()
941941
}
942942
}()
@@ -974,20 +974,6 @@ func (mgr *ContainerManager) Update(ctx context.Context, name string, config *ty
974974
}
975975
}
976976
}
977-
978-
// TODO(ziren): we should use meta.Config.DiskQuota to record container diskquota
979-
// compatibility with alidocker, when set DiskQuota for container
980-
// add a DiskQuota label
981-
if config.DiskQuota != nil {
982-
if _, ok := c.Config.Labels["DiskQuota"]; ok {
983-
labels := []string{}
984-
for dir, quota := range c.Config.DiskQuota {
985-
labels = append(labels, fmt.Sprintf("%s=%s", dir, quota))
986-
}
987-
c.Config.Labels["DiskQuota"] = strings.Join(labels, ";")
988-
}
989-
}
990-
991977
c.Unlock()
992978

993979
// update Resources of a container.
@@ -1020,6 +1006,12 @@ func (mgr *ContainerManager) Update(ctx context.Context, name string, config *ty
10201006
}
10211007
c.Config.Env = newEnvSlice
10221008

1009+
if mgr.containerPlugin != nil {
1010+
if err = mgr.containerPlugin.PostUpdate(c.BaseFS, c.Config.Env); err != nil {
1011+
return err
1012+
}
1013+
}
1014+
10231015
// If container is not running, update container metadata struct is enough,
10241016
// resources will be updated when the container is started again,
10251017
// If container is running, we need to update configs to the real world.

0 commit comments

Comments
 (0)