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

controller: use slice instead of map to conserve consistent order #1052

Merged

Conversation

shajmakh
Copy link
Member

Using map to store the daemonset of the targeted MCPs turned out to be a not the best data structure especially when we would like to conserve a consistent order of the elements that aligns with the rest of the slices in the operator status.
The problem with map is that it cannot be guaranteed that the elements will be ordered in the same order they were placed. To fix that, define a new struct of an MCP and its respective created RTE daemonset and replace the map with a slice of this struct which ensures that same data will produce same output every time.

ref: https://groups.google.com/g/golang-nuts/c/YfDxpkI34hY/m/4pktJI2ytusJ

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 21, 2024
Copy link
Member

@ffromani ffromani left a comment

Choose a reason for hiding this comment

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

the general direction is fine, thanks for the fix!
some improvements and followups as inline comments.

Comment on lines 316 to 329
func syncNodeGroupsStatus(instance *nropv1.NUMAResourcesOperator, dsPerMCP []MCPDaemonSetPair) []nropv1.NodeGroupStatus {
ngStatuses := []nropv1.NodeGroupStatus{}
for _, mcp := range instance.Status.MachineConfigPools {
status := nropv1.NodeGroupStatus{
PoolName: mcp.Name,
Config: *mcp.Config,
DaemonSet: dsPerMCP[mcp.Name],
for _, info := range dsPerMCP {
if mcp.Name != info.MCPName {
continue
}

status := nropv1.NodeGroupStatus{
PoolName: mcp.Name,
Config: *mcp.Config,
DaemonSet: info.Daemonset,
}
ngStatuses = append(ngStatuses, status)
Copy link
Member

Choose a reason for hiding this comment

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

thanks for the fix. We can use another fix later: this function should create the NodeGroupStatus using dsPerMCP as master source (iterating over there) and not depend on other status fields like instance.Status.MachineConfigPools.

Copy link
Member Author

Choose a reason for hiding this comment

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

we need to be aligned with the status update on MCP, currently the config won't be updated there if MCP is not completely ready. I'll look into this anyhow, we can use an improvement here indeed

Copy link
Member

Choose a reason for hiding this comment

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

fine, material for another PR anyway.

controllers/numaresourcesoperator_controller.go Outdated Show resolved Hide resolved
controllers/numaresourcesoperator_controller.go Outdated Show resolved Hide resolved
@shajmakh shajmakh force-pushed the replace-map-in-slice branch from 4e62f4d to 83e0ba7 Compare October 21, 2024 09:48
Copy link
Member

@ffromani ffromani left a comment

Choose a reason for hiding this comment

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

/approve
/lgtm

controllers/numaresourcesoperator_controller.go Outdated Show resolved Hide resolved
controllers/numaresourcesoperator_controller.go Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 21, 2024
@shajmakh
Copy link
Member Author

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 21, 2024
@shajmakh shajmakh force-pushed the replace-map-in-slice branch from 83e0ba7 to 181a8f6 Compare October 21, 2024 12:10
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Oct 21, 2024
Using map to store the daemonset of the targeted MCPs turned out to be a
not the best data structure especially when we would like to conserve a
consistent order of the elements that aligns with the rest of the slices
in the operator status.
The problem with map is that it cannot be guaranteed that the elements
will be ordered in the same order they were placed. To fix that, define
a new struct of an MCP and its respective created RTE daemonset and
replace the map with a slice of this struct which ensures that same data
will produce same output every time.

ref: https://groups.google.com/g/golang-nuts/c/YfDxpkI34hY/m/4pktJI2ytusJ

Signed-off-by: Shereen Haj <[email protected]>
@shajmakh shajmakh force-pushed the replace-map-in-slice branch from 181a8f6 to 8c847f8 Compare October 21, 2024 12:11
@shajmakh
Copy link
Member Author

/unhold

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 21, 2024
@ffromani
Copy link
Member

/approve
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 21, 2024
Copy link
Contributor

openshift-ci bot commented Oct 21, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ffromani, shajmakh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit b01a129 into openshift-kni:main Oct 21, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants