Skip to content

Comments

api/types/network: split EndpointSettings config and operational data#46059

Draft
thaJeztah wants to merge 2 commits intomoby:masterfrom
thaJeztah:refactor_cleanOperationalData
Draft

api/types/network: split EndpointSettings config and operational data#46059
thaJeztah wants to merge 2 commits intomoby:masterfrom
thaJeztah:refactor_cleanOperationalData

Conversation

@thaJeztah
Copy link
Member

daemon: Daemon.releaseNetwork move nil-check to cleanOperationalData

network.EndpointSettings is a wrapper around types.EndpointSettings,
and the fields being cleared are all in that struct, so if it's nil,
there's nothing to do.

Making the nil-check a responsibility of the caller didn't make sense,
so let's move it inside that function.

api/types/network: split EndpointSettings config and operational data

EndpointSettings holds both "Config" data (definition) and runtime ("operational")
data. Fields for the latter one are set/reset at runtime. Resetting is handled
by the cleanOperationalData function, but it does so for each field individually.

This handling is slightly brittle, as the cleanOperationalData must be
updated when adding new "operational" data, which can easily be overlooked.

This patch updates the EndpointSettings type to split the "config" and
"operational" data into separate structs. The new EndpointOperationalData
struct is embedded in the existing type, so the net-result should be the
same for most cases (except for constructing struct-literals).

Resetting the operational data now allows for the EndpointOperationalData
to be set to an empty struct (resetting its values to their defaults / empty).

- Description for the changelog

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

network.EndpointSettings is a wrapper around types.EndpointSettings,
and the fields being cleared are all in that struct, so if it's nil,
there's nothing to do.

Making the nil-check a responsibility of the caller didn't make sense,
so let's move it inside that function.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah added area/api API status/2-code-review area/networking Networking kind/refactor PR's that refactor, or clean-up code labels Jul 24, 2023
EndpointSettings holds both "Config" data (definition) and runtime ("operational")
data. Fields for the latter one are set/reset at runtime. Resetting is handled
by the `cleanOperationalData` function, but it does so for each field individually.

This handling is slightly brittle, as the `cleanOperationalData` must be
updated when adding new "operational" data, which can easily be overlooked.

This patch updates the EndpointSettings type to split the "config" and
"operational" data into separate structs. The new `EndpointOperationalData`
struct is embedded in the existing type, so the net-result should be the
same for most cases (except for constructing struct-literals).

Resetting the operational data now allows for the `EndpointOperationalData`
to be set to an empty struct (resetting its values to their defaults / empty).

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the refactor_cleanOperationalData branch from 234cf7b to 424a262 Compare July 24, 2023 10:52

// Operational data
NetworkID string
EndpointOperationalData
Copy link
Member

Choose a reason for hiding this comment

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

The real issue here is to mix both user-provided settings and state. The state should be derived from the settings, and not the other way around.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, must 100% admit that I got lost on these types, and also confused whether NetworkID was a config or operational field. It was not reset in cleanOperationalData so assumed it was "config", but it was listed under the "operational data" comment, so 🤷‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api API area/networking Networking kind/refactor PR's that refactor, or clean-up code status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants