@@ -148,6 +148,42 @@ func (pc *podController) Drift(cluster cluster.Cluster, fromNode, toNode string,
148148 return true
149149}
150150
151+ func (pc * podController ) Update (cluster cluster.Cluster ) error {
152+ log .Infof ("%s updating" , pc )
153+ start := time .Now ()
154+ defer func () {
155+ pc .spec .Filters = []string {} // clear the filter
156+ pc .pod .UpdatedAt = time .Now ()
157+ log .Infof ("%s updated, state=%+v, duration=%s" , pc , pc .pod .ImRuntime , time .Now ().Sub (start ))
158+ }()
159+ var err error
160+ for i , cSpec := range pc .spec .Containers {
161+ e := pc .updateContainer (cluster , i )
162+ if e != nil {
163+ log .Warnf ("%s Cannot update container, error=%q, spec=%+v" , pc , err , cSpec )
164+ if err == nil {
165+ err = e
166+ }
167+ }
168+ id := pc .pod .Containers [i ].Id
169+ pc .startContainer (cluster , id )
170+ pc .refreshContainer (cluster , i )
171+ if i == 0 && pc .pod .Containers [0 ].NodeName != "" {
172+ pc .spec .PrevState .NodeName = pc .pod .Containers [i ].NodeName
173+ }
174+ pc .spec .PrevState .IPs [i ] = pc .pod .Containers [i ].ContainerIp
175+ }
176+ if pc .pod .State == RunStatePending {
177+ if err == nil {
178+ pc .pod .State = RunStateSuccess
179+ } else {
180+ pc .pod .State = RunStateError
181+ }
182+ pc .pod .TargetState = ExpectStateRun
183+ }
184+ return err
185+ }
186+
151187func (pc * podController ) Remove (cluster cluster.Cluster ) {
152188 log .Infof ("%s removing" , pc )
153189 start := time .Now ()
@@ -338,6 +374,7 @@ func (pc *podController) refreshContainer(kluster cluster.Cluster, index int) {
338374 if network == "" {
339375 network = pc .spec .Namespace
340376 }
377+ log .Infof ("pc.spec.PrevState.IPs:%v" , pc .spec .PrevState .IPs )
341378 prevIP , nowIP := pc .spec .PrevState .IPs [index ], info .NetworkSettings .Networks [network ].IPAddress
342379 // NOTE: if the container's ip is not equal to prev ip, try to correct it; if failed, accpet new ip
343380 if prevIP != "" && prevIP != nowIP {
@@ -406,6 +443,19 @@ func (pc *podController) createContainer(cluster cluster.Cluster, filters []stri
406443 return cluster .CreateContainer (cc , hc , nc , name )
407444}
408445
446+ func (pc * podController ) updateContainer (cluster cluster.Cluster , index int ) error {
447+ podSpec := pc .spec
448+ spec := podSpec .Containers [index ]
449+ id := pc .pod .Containers [index ].Id
450+ config := & CUpdateConfig {
451+ Memory : spec .MemoryLimit ,
452+ MemorySwap : spec .MemoryLimit , // Memory == MemorySwap means disable swap
453+ CPUPeriod : CPUQuota ,
454+ CPUQuota : int64 (spec .CpuLimit * resource .Cpu * CPUMaxPctg ) * CPUQuota / int64 (CPUMaxLevel * 100 ),
455+ }
456+ return cluster .UpdateContainer (id , config )
457+ }
458+
409459func (pc * podController ) createContainerConfig (filters []string , index int ) adoc.ContainerConfig {
410460 podSpec := pc .spec
411461 spec := podSpec .Containers [index ]
@@ -527,7 +577,7 @@ func (pc *podController) createHostConfig(index int) adoc.HostConfig {
527577 Resources : adoc.Resources {
528578 Memory : spec .MemoryLimit ,
529579 MemorySwap : spec .MemoryLimit , // Memory == MemorySwap means disable swap
530- MemorySwappiness : & swappiness ,
580+ MemorySwappiness : & swappiness ,
531581 CPUPeriod : CPUQuota ,
532582 CPUQuota : int64 (spec .CpuLimit * resource .Cpu * CPUMaxPctg ) * CPUQuota / int64 (CPUMaxLevel * 100 ),
533583 BlkioDeviceReadBps : BlkioDeviceReadBps ,
0 commit comments