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

detect network config changes and recreate if needed #12267

Merged
merged 2 commits into from
Nov 15, 2024

Conversation

ndeloof
Copy link
Contributor

@ndeloof ndeloof commented Nov 5, 2024

What I did
use a config hash label on networks to detect need to be recreated.

attached services will be stopped so we can recreate network,
then convergence will recreate them as we check the network container is attached to has the expected ID

Related issue
fixes #9203

(not mandatory) A picture of a cute animal, if possible in relation to what you did

@ndeloof ndeloof marked this pull request as draft November 6, 2024 11:48
@ndeloof ndeloof marked this pull request as ready for review November 6, 2024 12:23
bytes, err := json.Marshal(o)
if err != nil {
return "", err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to ignore api.VersionLabel and api.ConfigHashLabel similarly to volumes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, this is why I introduced CustomLabel in compose-go (same mechanism used for services)
https://github.com/docker/compose/pull/12267/files#diff-1f4d596600c620b3df55dbfbc63e50a6f43b356865fae411c553d0937fbb6d91R122

@ndeloof ndeloof requested review from a team and glours and removed request for a team November 8, 2024 11:16
@terev
Copy link
Contributor

terev commented Nov 12, 2024

Bless you for this change! Was just working on a workaround for our internal compose wrapper but it was proving difficult to be sure it works sanely.

One question, is there a reason we can't do the network recreation more gracefully? Like detach all containers connected to the diverged network then remove the network only. Is this because the disconnected containers won't be reattached in the current reconciliation strategy?

@ndeloof
Copy link
Contributor Author

ndeloof commented Nov 12, 2024

@terev I also considered this approach, but this indeed require more changes on the convergence side to re-attach + this involves the container will manage network being disconnected/reconnected (IP address will change) and in many cases this is not well supported. Recreating is "safer" from this point of view.

What's your use-case for changing network definition and requirement for app to keep running ?

@terev
Copy link
Contributor

terev commented Nov 12, 2024

@ndeloof Ok understood, that makes sense. It's not a super hard requirement, as my use case only applies to local development where I'd like to gracefully update the default binding address.

I was just weighing network detachment against the possibility of accidentally removing container logs and data. But even if container data is lost it probably should have been kept in a volume in the first place.

@ndeloof
Copy link
Contributor Author

ndeloof commented Nov 13, 2024

Right. This makes me wonder we should preserve anonymous volumes on recreation, to avoid such a data loss.

@terev
Copy link
Contributor

terev commented Nov 13, 2024

That would be neat if possible, though that sounds like it'd be a totally new mechanism given that anonymous volumes are currently disassociated with a service if its container is recreated. I do think that'd be a neat feature that would make the Dockerfile volume instruction much more useful.

@ndeloof
Copy link
Contributor Author

ndeloof commented Nov 13, 2024

@terev when a service recreated, anonymous volumes are preserve already. We can reuse this mechanism

@terev
Copy link
Contributor

terev commented Nov 13, 2024

Oh! Right sorry I'm mistaken, that's perfect.

}
}
if !found {
// config is up-t-date but container is not connected to network - maybe recreated ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw this makes a lot of sense to me. Would even say it makes sense to recreate if it is connected to undesired networks.

return true, nil
}

if c.networks != nil {
Copy link
Contributor

@terev terev Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we recreate if networks is nil but expected/actual has networks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

networks is nil only if caller didn't created convergence with actual network state - this is the case running compose run command, need to investigate why we don't manage networks in this command, will do in a follow-up PR.

@ndeloof ndeloof force-pushed the network_diverged branch 2 times, most recently from 1730ede to 23e5f2a Compare November 14, 2024 17:02
Copy link
Contributor

@glours glours left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me

ndeloof and others added 2 commits November 15, 2024 15:00
Co-authored-by: Guillaume Lours <[email protected]>
Signed-off-by: Nicolas De loof <[email protected]>
@ndeloof ndeloof merged commit d4fa63f into docker:main Nov 15, 2024
28 checks passed
@ndeloof ndeloof deleted the network_diverged branch November 15, 2024 14:37
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Dec 5, 2024
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [docker/compose](https://github.com/docker/compose) | minor | `v2.30.3` -> `v2.31.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>docker/compose (docker/compose)</summary>

### [`v2.31.0`](https://github.com/docker/compose/releases/tag/v2.31.0)

[Compare Source](docker/compose@v2.30.3...v2.31.0)

#### What's Changed

##### ✨ Improvements

-   Delegate build to buildx bake by [@&#8203;ndeloof](https://github.com/ndeloof) [(12300)](docker/compose#12300)
-   Add commit command by [@&#8203;jarqvi](https://github.com/jarqvi) [(12268)](docker/compose#12268)

##### 🐛 Fixes

-   Fix(config): Print service names with --no-interpolate by [@&#8203;idsulik](https://github.com/idsulik) [(12282)](docker/compose#12282)
-   Remove obsolete containers first on scale down by [@&#8203;ndeloof](https://github.com/ndeloof) [(12272)](docker/compose#12272)
-   Fix compose images that return a different image with the same ID by [@&#8203;koooge](https://github.com/koooge) [(12278)](docker/compose#12278)
-   Emit events for building images by [@&#8203;felixfontein](https://github.com/felixfontein) [(11498)](docker/compose#11498)
-   Fix support for --remove-orphans on `docker compose run` by [@&#8203;ndeloof](https://github.com/ndeloof) [(12288)](docker/compose#12288)
-   Push empty descriptor layer when using OCI version 1.1 for Compose artifact by [@&#8203;glours](https://github.com/glours) [(12289)](docker/compose#12289)
-   Detect network config changes and recreate if needed by [@&#8203;ndeloof](https://github.com/ndeloof) [(12267)](docker/compose#12267)
-   Update wait-timeout flag usage to include the unit by [@&#8203;terev](https://github.com/terev) [(12316)](docker/compose#12316)
-   Use service.stop to stop dependent containers by [@&#8203;ndeloof](https://github.com/ndeloof) [(12322)](docker/compose#12322)
-   Only check attached networks on running containers by [@&#8203;ndeloof](https://github.com/ndeloof) [(12327)](docker/compose#12327)
-   Only stop dependent containers ... if there's some by [@&#8203;ndeloof](https://github.com/ndeloof) [(12328)](docker/compose#12328)

##### 🔧  Internal

-   Pass stale bot inactivity limit from 6 to 3 months by [@&#8203;glours](https://github.com/glours) [(12284)](docker/compose#12284)
-   Ci: enable testifylint linter by [@&#8203;mmorel-35](https://github.com/mmorel-35) [(11761)](docker/compose#11761)
-   Remove ddev e2e tests by [@&#8203;glours](https://github.com/glours) [(12291)](docker/compose#12291)
-   Gha: test against docker engine v27.4.0 by [@&#8203;thaJeztah](https://github.com/thaJeztah) [(12299)](docker/compose#12299)
-   Run build tests against bake by [@&#8203;ndeloof](https://github.com/ndeloof) [(12325)](docker/compose#12325)

##### ⚙️ Dependencies

-   Build(deps): bump golang.org/x/sync from `0.8.0` to `0.9.0` by [@&#8203;dependabot](https://github.com/dependabot) [(12277)](docker/compose#12277)
-   Build(deps): bump golang.org/x/sys from `0.26.0` to `0.27.0` by [@&#8203;dependabot](https://github.com/dependabot) [(12276)](docker/compose#12276)
-   Build(deps): bump github.com/moby/buildkit `v0.17.1`, github.com/docker/buildx `v0.18.0` by [@&#8203;thaJeztah](https://github.com/thaJeztah) [(12298)](docker/compose#12298)
-   Build(deps): bump docker/docker `v27.4.0-rc.2`, docker/cli `v27.4.0-rc.2` by [@&#8203;thaJeztah](https://github.com/thaJeztah) [(12306)](docker/compose#12306)
-   Build(deps): bump github.com/stretchr/testify from `1.9.0` to `1.10.0` by [@&#8203;dependabot](https://github.com/dependabot) [(12319)](docker/compose#12319)
-   Build(deps): bump github.com/compose-spec/compose-go/v2 from `2.4.5-0.20241111154218-9d02caaf8465` to `2.4.5` by [@&#8203;dependabot](https://github.com/dependabot) [(12324)](docker/compose#12324)
-   Build(deps): bump github.com/moby/buildkit from `0.17.1` to `0.17.2` by [@&#8203;dependabot](https://github.com/dependabot) [(12320)](docker/compose#12320)
-   Bump google.golang.org/grpc to v1.68.0 and containerd to `v1.7.24` by [@&#8203;glours](https://github.com/glours) [(12329)](docker/compose#12329)

#### New Contributors

-   [@&#8203;terev](https://github.com/terev) made their first contribution in docker/compose#12316

**Full Changelog**: docker/compose@v2.30.3...v2.31.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40NDAuNyIsInVwZGF0ZWRJblZlciI6IjM3LjQ0MC43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker compose does not adapt on bridge driver changes
4 participants