api/types/network: split EndpointSettings config and operational data#46059
Draft
thaJeztah wants to merge 2 commits intomoby:masterfrom
Draft
api/types/network: split EndpointSettings config and operational data#46059thaJeztah wants to merge 2 commits intomoby:masterfrom
thaJeztah wants to merge 2 commits intomoby:masterfrom
Conversation
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]>
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]>
234cf7b to
424a262
Compare
akerouanton
reviewed
Jul 24, 2023
|
|
||
| // Operational data | ||
| NetworkID string | ||
| EndpointOperationalData |
Member
There was a problem hiding this comment.
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.
Member
Author
There was a problem hiding this comment.
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 🤷♂️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
cleanOperationalDatafunction, but it does so for each field individually.This handling is slightly brittle, as the
cleanOperationalDatamust beupdated 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
EndpointOperationalDatastruct 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
EndpointOperationalDatato 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)