-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
Conversation
# Conflicts: # kube-controllers/pkg/controllers/node/controller.go
return cn, ok | ||
func (c *nodeLabelController) syncAllNodesLabels() { | ||
if c.syncStatus != bapi.InSync { | ||
logrus.WithField("status", c.syncStatus).Debug("Not in sync, skipping node sync") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
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 | ||
} |
There was a problem hiding this comment.
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.
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 | |
} | |
} |
Description
Update labels controller to utilize syncer updates to sync labels between k8s and calico nodes
Related issues/PRs
Todos
Release Note
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.