Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty out the aliases on recreation #1699

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg/container/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,25 @@
return nil
}

func (client dockerClient) GetNetworkConfig(c t.Container) *network.NetworkingConfig {
config := &network.NetworkingConfig{
EndpointsConfig: c.ContainerInfo().NetworkSettings.Networks,
}

for _, ep := range config.EndpointsConfig {
// This keeps accumulating across upgrades with no apparent added value
// so throwing the information away to prevent overflows.
ep.Aliases = nil
}
return config
}

func (client dockerClient) StartContainer(c t.Container) (t.ContainerID, error) {
bg := context.Background()
config := c.GetCreateConfig()
hostConfig := c.GetCreateHostConfig()
networkConfig := &network.NetworkingConfig{EndpointsConfig: c.ContainerInfo().NetworkSettings.Networks}
networkConfig := client.GetNetworkConfig(c)

Check warning on line 229 in pkg/container/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/client.go#L228-L229

Added lines #L228 - L229 were not covered by tests
// simpleNetworkConfig is a networkConfig with only 1 network.
// see: https://github.com/docker/docker/issues/29265
simpleNetworkConfig := func() *network.NetworkingConfig {
Expand All @@ -228,6 +242,7 @@
name := c.Name()

log.Infof("Creating %s", name)

Check warning on line 245 in pkg/container/client.go

View check run for this annotation

Codecov / codecov/patch

pkg/container/client.go#L245

Added line #L245 was not covered by tests
createdContainer, err := client.api.ContainerCreate(bg, config, hostConfig, simpleNetworkConfig, nil, name)
if err != nil {
return "", err
Expand Down
19 changes: 19 additions & 0 deletions pkg/container/client_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package container

import (
"github.com/docker/docker/api/types/network"
"time"

"github.com/containrrr/watchtower/internal/util"
Expand Down Expand Up @@ -284,6 +285,24 @@ var _ = Describe("the client", func() {
})
})
})
Describe(`GetNetworkConfig`, func() {
When(`providing a container with network aliases`, func() {
It(`should purge the aliases`, func() {
aliases := []string{"One", "Two"}
client := dockerClient{
api: docker,
ClientOptions: ClientOptions{PullImages: false, IncludeRestarting: false},
}
container := MockContainer(WithImageName("docker.io/prefix/imagename:latest"))
endpoints := map[string]*network.EndpointSettings{
`test`: {Aliases: aliases},
}
container.containerInfo.NetworkSettings = &types.NetworkSettings{Networks: endpoints}
Expect(container.ContainerInfo().NetworkSettings.Networks[`test`].Aliases).To(Equal(aliases))
Expect(client.GetNetworkConfig(container).EndpointsConfig[`test`].Aliases).To(BeEmpty())
})
})
})
})

// Capture logrus output in buffer
Expand Down
Loading