Skip to content

api: Deprecate outdated networking fields & structs#45945

Open
akerouanton wants to merge 5 commits intomoby:masterfrom
akerouanton:deprecate-outdated-api-fields
Open

api: Deprecate outdated networking fields & structs#45945
akerouanton wants to merge 5 commits intomoby:masterfrom
akerouanton:deprecate-outdated-api-fields

Conversation

@akerouanton
Copy link
Member

- What I did

  • Fixed the deprecation warning on DefaultNetworkSettings ;
  • Marked NetworkSettingsBase as deprecated ;
  • Fixed a few undescriptive comments ;

- How to verify it

CI is green

- A picture of a cute animal (not mandatory but encouraged)

Copy link
Contributor

@corhere corhere left a comment

Choose a reason for hiding this comment

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

How do you propose to remove types and struct fields without breaking the build of API clients? Pinning the version is not an acceptable answer because transitive dependencies may force an upgrade of the moby/moby dependency whether the consumer wants to or not.

@akerouanton akerouanton force-pushed the deprecate-outdated-api-fields branch 3 times, most recently from ffa1036 to efcbbdd Compare September 12, 2023 17:44
// NetworkSettingsBase holds basic information about networks
// NetworkSettingsBase holds the networking state of a specific container when inspecting it.
//
// Deprecated: this struct mostly contains deprecated fields and will be removed in v26.0.
Copy link
Member

Choose a reason for hiding this comment

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

Don't think we can remove the fields if we still support the older API versions.

Copy link
Member

Choose a reason for hiding this comment

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

OH, I guess that's the approach with the duplicated fields 🤔

Copy link
Member Author

@akerouanton akerouanton Dec 21, 2023

Choose a reason for hiding this comment

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

How to completely get rid of these fields is still an unanswered question for me right now. One option could be through some clever use of struct tags and a custom JSON encoder, maybe.

But at least, this change clearly separates what's deprecated and what is not, making maintainers' life easier I believe.

Comment on lines 334 to 336
SandboxID string // SandboxID uniquely represents a container's network stack
SandboxKey string // SandboxKey is the full path of the netns handle
Ports nat.PortMap // Ports is a collection of PortBinding indexed by Port
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicating these fields is a breaking change; the insidious kind of breaking change that doesn't break compilation.

myNetworkSettings.SandboxID != myNetworkSettings.NetworkSettingsBase.SandboxID

I'm afraid that NetworkSettingsBase can't be deprecated or removed until we migrate to Go modules and release a new major version (read: with a /vN module path). We can still deprecate the fields inside NetworkSettingsBase at least, and drop the NetworkSettingsBase type without any ceremony in a new module version.

Copy link
Member Author

Choose a reason for hiding this comment

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

For now, we'll continue to write both fields so I don't think that's gonna be a problem. In a release or two, we should think about removing the whole NetworkSettingsBase struct, or at least the fields that were copied to NetworkSettings (ie. Bridge, SandboxID, SandboxKey). This should give enough time for our Go users to migrate to the new fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Mh right. So, is it okay if I just remove the fields I added to NetworkSettings and keep the deprecation warning on NetworkSettingsBase while mentioning that non-deprecated fields will be moved to NetworkSettings in v26?

Copy link
Contributor

Choose a reason for hiding this comment

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

That'd work, so long as linters don't complain about references to fields like myNetworkSettings.SandboxID which would be well-formed in both v25 and v26. The deprecation warning on the struct itself might have to go.

@akerouanton akerouanton force-pushed the deprecate-outdated-api-fields branch 2 times, most recently from c437ed1 to 9adb056 Compare December 20, 2023 23:53
@akerouanton
Copy link
Member Author

akerouanton commented Dec 21, 2023

We discussed this PR few weeks ago during a maintainers' call and we agreed that every major release is a major release of the Go API, even if we don't have a proper Go module, and thus we shouldn't feel obliged to not break our Go API.

As explained in the commit messages, these fields have been deprecated a long time ago and are of no practical use as they're always empty. As such, this PR marks those fields / structs as deprecated.

When they will be removed, and how to handle older API versions that still them, is an unanswered question but that could be sorted out at a later time.

For now the main focus is to make it easier for maintainers to understand those fields aren't used. In the future, removing these fields from API reponses will make docker inspect output slightly easier to consume by end-users.

@thaJeztah
Copy link
Member

thaJeztah commented Jan 3, 2024

As there's still concerns about some parts of this PR (the Go changes which wouldn't fail but could silently cause issues), I'll move some of the more trivial / non-concentioous parts to separate PRs.

First two;

@thaJeztah
Copy link
Member

@akerouanton can you rebase this one, so that the things already merged are removed from this PR?

This struct is only used to report the networking state of the default
bridge when inspecting a container.

It was deprecated in v1.09 (API v1.21) but has never been removed since
then. Unfortunately, the deprecation warning was wrongly formatted,
thus automation tools and IDEs are not flagging it as deprecated.

This commit fixes the deprecation comment.

Signed-off-by: Albin Kerouanton <[email protected]>
This struct holds the overall networking state of a container, and still
have a bunch of relic of the past (ie. < Docker v1.09).

All the following fields are never written and are only used to create
the equivalent fields in the api `NetworkSettingsBase` (which was
properly deprecated in ce57494):

- `HairpinMode`
- `LinkLocalIPv6Address`
- `LinkLocalIPv6PrefixLen`
- `SecondaryIPAddresses`
- `SecondaryIPv6Addresses`

As such, all those fields are now marked as deprecated and their values
aren't copied into `NetworkSettingsBase` anymore.

Signed-off-by: Albin Kerouanton <[email protected]>
Signed-off-by: Albin Kerouanton <[email protected]>
Signed-off-by: Albin Kerouanton <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants