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

labels, ipcache: Introduce convenience NewFrom() #23218

Merged
merged 1 commit into from Jan 24, 2023

Conversation

christarazi
Copy link
Member

This new function is a convenience and safe wrapper for creating a copy
of a Labels object from another.

This is especially useful going forward with the IPcache rework
(#21142), where many call sites
are being converted from using raw identities over to labels. Being able
to create copies of labels without accidentally copying the reference to
the backing slice is crucial to avoid very subtle and hard to find bugs.

For example:

// Node 1 comes online.
node1Labels := labels.LabelRemoteNote
// Detect that node1 also has the kube-apiserver deployed on it, so add
// its label.
node1Labels.MergeLabels(labels.LabelKubeAPIServer)
...

// Node 2 comes onlne.
node2Labels := labels.LabelRemoteNote
// Now node2Labels contains the kube-apiserver label as well because
// node1Labels was set to the reference of labels.LabelRemoteNote.

Signed-off-by: Chris Tarazi chris@isovalent.com

@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jan 20, 2023
@github-actions github-actions bot added the kind/community-contribution This was a contribution made by a community member. label Jan 20, 2023
@christarazi christarazi added area/daemon Impacts operation of the Cilium daemon. area/misc Impacts miscellaneous areas of the code not otherwise owned by another area. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. release-note/misc This PR makes changes that have no direct user impact. and removed kind/community-contribution This was a contribution made by a community member. labels Jan 20, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jan 20, 2023
@christarazi christarazi marked this pull request as ready for review January 20, 2023 17:54
@christarazi christarazi requested review from a team as code owners January 20, 2023 17:54
@christarazi
Copy link
Member Author

cc @joestringer @gandro, this is related to 46d09ac.

@christarazi
Copy link
Member Author

christarazi commented Jan 20, 2023

/test

Job 'Cilium-PR-K8s-1.25-kernel-4.19' failed:

Click to show.

Test Name

K8sDatapathConfig Host firewall With VXLAN

Failure Output

FAIL: Failed to reach 192.168.56.12:80 from testclient-5klt8

If it is a flake and a GitHub issue doesn't already exist to track it, comment /mlh new-flake Cilium-PR-K8s-1.25-kernel-4.19 so I can create one.

This new function is a convenience and safe wrapper for creating a copy
of a Labels object from another.

This is especially useful going forward with the IPcache rework
(cilium#21142), where many call sites
are being converted from using raw identities over to labels. Being able
to create copies of labels without accidentally copying the reference to
the backing slice is crucial to avoid very subtle and hard to find bugs.

For example:

```
// Node 1 comes online.
node1Labels := labels.LabelRemoteNote
// Detect that node1 also has the kube-apiserver deployed on it, so add
// its label.
node1Labels.MergeLabels(labels.LabelKubeAPIServer)
...

// Node 2 comes onlne.
node2Labels := labels.LabelRemoteNote
// Now node2Labels contains the kube-apiserver label as well because
// node1Labels was set to the reference of labels.LabelRemoteNote.
```

Signed-off-by: Chris Tarazi <chris@isovalent.com>
@christarazi
Copy link
Member Author

/test

Copy link
Member

@gandro gandro left a comment

Choose a reason for hiding this comment

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

Nice find! Thanks

Copy link
Member

@aditighag aditighag left a comment

Choose a reason for hiding this comment

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

Thanks for the context in the commit description.

@christarazi
Copy link
Member Author

Runtime test hit: #22373

@christarazi
Copy link
Member Author

/test-runtime

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jan 23, 2023
@ldelossa ldelossa merged commit e0ebb93 into cilium:master Jan 24, 2023
@christarazi christarazi deleted the pr/christarazi/labels-newfrom branch January 24, 2023 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/daemon Impacts operation of the Cilium daemon. area/misc Impacts miscellaneous areas of the code not otherwise owned by another area. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants