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

Update labels controller to utilize syncer for updates #10045

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

MichalFupso
Copy link
Contributor

Description

Update labels controller to utilize syncer updates to sync labels between k8s and calico nodes

Related issues/PRs

Todos

  • Tests
  • Documentation
  • Release note

Release Note

TBD

Reminder for the reviewer

Make sure that this PR has the correct labels and milestone set.

Every PR needs one docs-* label.

  • docs-pr-required: This change requires a change to the documentation that has not been completed yet.
  • docs-completed: This change has all necessary documentation completed.
  • docs-not-required: This change has no user-facing impact and requires no docs.

Every PR needs one release-note-* label.

  • release-note-required: This PR has user-facing changes. Most PRs should have this label.
  • release-note-not-required: This PR has no user-facing changes.

Other optional labels:

  • cherry-pick-candidate: This PR should be cherry-picked to an earlier release. For bug fixes only.
  • needs-operator-pr: This PR is related to install and requires a corresponding change to the operator.

@MichalFupso MichalFupso added docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact labels Mar 24, 2025
@MichalFupso MichalFupso requested a review from a team as a code owner March 24, 2025 20:17
@marvin-tigera marvin-tigera added this to the Calico v3.31.0 milestone Mar 24, 2025
return cn, ok
func (c *nodeLabelController) syncAllNodesLabels() {
if c.syncStatus != bapi.InSync {
logrus.WithField("status", c.syncStatus).Debug("Not in sync, skipping node sync")
Copy link
Contributor

Choose a reason for hiding this comment

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

The message says 'skipping node sync,' but the code doesn’t seem to implement a mechanism to skip. Is there a return missing? Is the message incorrect, or did I misunderstand the code? hehe


node, err := c.nodeLister.Get(kn)
if err != nil {
logrus.WithError(err).WithField("node", kn).Error("Unable to get node")
Copy link
Contributor

@lucastigera lucastigera Apr 8, 2025

Choose a reason for hiding this comment

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

Question:
Is this actually a real 'Error'? I mean, does the system detect an error but still allow the code to continue?
Should it be a 'Warning' instead, or should a return be added to stop execution after logging the error?

Comment on lines +166 to 192
if err != nil {
logrus.WithError(err).Info("Unable to get corresponding k8s node name, skipping")
} else if kn != "" {
// Create a mapping from Kubernetes node -> Calico node.
logrus.Debugf("Mapping k8s node -> calico node. %s -> %s", kn, n.Name)

c.k8sNodeMapper[kn] = n.Name

node, err := c.nodeLister.Get(kn)
if err != nil {
logrus.WithError(err).WithField("node", kn).Error("Unable to get node")
}

if _, ok := c.calicoNodeCache[n.Name]; !ok {
// If this is new calicoNode trigger sync for corresponding k8s node.
// As we only sync labels k8s -> calico node, no need to sync when calico node already exists in our cache
c.calicoNodeCache[n.Name] = n

if node != nil && c.syncStatus == bapi.InSync {
// Only trigger the update if the k8s node exists
c.k8sNodeUpdate <- node
}
return
}

c.calicoNodeCache[n.Name] = n
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a suggestion to exit early, in order to avoid nested conditions.

Suggested change
if err != nil {
logrus.WithError(err).Info("Unable to get corresponding k8s node name, skipping")
} else if kn != "" {
// Create a mapping from Kubernetes node -> Calico node.
logrus.Debugf("Mapping k8s node -> calico node. %s -> %s", kn, n.Name)
c.k8sNodeMapper[kn] = n.Name
node, err := c.nodeLister.Get(kn)
if err != nil {
logrus.WithError(err).WithField("node", kn).Error("Unable to get node")
}
if _, ok := c.calicoNodeCache[n.Name]; !ok {
// If this is new calicoNode trigger sync for corresponding k8s node.
// As we only sync labels k8s -> calico node, no need to sync when calico node already exists in our cache
c.calicoNodeCache[n.Name] = n
if node != nil && c.syncStatus == bapi.InSync {
// Only trigger the update if the k8s node exists
c.k8sNodeUpdate <- node
}
return
}
c.calicoNodeCache[n.Name] = n
}
if err != nil {
logrus.WithError(err).Info("Unable to get corresponding k8s node name, skipping")
return
}
if kn == "" {
logrus.WithError(err).Info("Corresponding k8s node name is empty, skipping")
return
}
// Create a mapping from Kubernetes node -> Calico node.
logrus.Debugf("Mapping k8s node -> calico node. %s -> %s", kn, n.Name)
c.k8sNodeMapper[kn] = n.Name
node, err := c.nodeLister.Get(kn)
if err != nil {
logrus.WithError(err).WithField("node", kn).Error("Unable to get node")
}
_, existsCalicoNode := c.calicoNodeCache[n.Name];
c.calicoNodeCache[n.Name] = n
if !existsCalicoNode {
// If this is new calicoNode trigger sync for corresponding k8s node.
// As we only sync labels k8s -> calico node, no need to sync when calico node already exists in our cache
if node != nil && c.syncStatus == bapi.InSync {
// Only trigger the update if the k8s node exists
c.k8sNodeUpdate <- node
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required Docs not required for this change hold-merge release-note-not-required Change has no user-facing impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants