Skip to content

Commit bf5b6ad

Browse files
henrybarretogustavosbarreto
authored andcommitted
fix(agent): remove agent updater container instead of stopping it
This commit resolves an issue where the updater container was stopping itself, preventing its removal after the update process. The previous implementation of the `CompleteUpdate` method would stop the updater container, resulting in it remaining in a stopped state rather than being properly removed. This behavior led to wasted system resources, as accumulated stopped containers could complicate the environment. By directly removing the updater container, we enhance resource management and streamline the update process.
1 parent 10550b3 commit bf5b6ad

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pkg/agent/pkg/selfupdater/updater_docker.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func (d *dockerUpdater) CompleteUpdate() error {
8181
return err
8282
}
8383

84+
if err := d.removeContainer(parent); err != nil {
85+
return err
86+
}
87+
8488
_, pv := parent.splitImageVersion()
8589
v, _ := semver.NewVersion(pv)
8690
v0_4_0, _ := semver.NewVersion("v0.4.0")
@@ -135,7 +139,7 @@ func (d *dockerUpdater) CompleteUpdate() error {
135139
return err
136140
}
137141

138-
if err := d.stopContainer(container); err != nil {
142+
if err := d.removeContainer(container); err != nil {
139143
return err
140144
}
141145

@@ -179,10 +183,14 @@ func (d *dockerUpdater) stopContainer(container *dockerContainer) error {
179183
return err
180184
}
181185

182-
opts := containertypes.RemoveOptions{Force: true, RemoveVolumes: true}
183-
err := d.api.ContainerRemove(ctx, container.info.ID, opts)
186+
return nil
187+
}
184188

185-
return err
189+
func (d *dockerUpdater) removeContainer(container *dockerContainer) error {
190+
ctx := context.Background()
191+
192+
opts := containertypes.RemoveOptions{Force: true, RemoveVolumes: true}
193+
return d.api.ContainerRemove(ctx, container.info.ID, opts)
186194
}
187195

188196
func (d *dockerUpdater) updateContainer(container *dockerContainer, image, name string, parent bool) (*dockerContainer, error) { //nolint:unparam

0 commit comments

Comments
 (0)