-
Notifications
You must be signed in to change notification settings - Fork 62
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
feat: add linode UUID as a metadata to each node #162
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5405a76
fix(build): correct image os/arch on ARM Mac
shanduur-akamai dd89c13
feat: add client builder method
shanduur-akamai 605ec91
feat: add node controller
shanduur-akamai 053f6d6
feat: integrate node controller with rest of code
shanduur-akamai 3797e68
feat: node update should trigger metadata update
shanduur-akamai 21b185a
fix: prevent backslash escape
shanduur-akamai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package linode | ||
|
||
const ( | ||
// annLinodeDefaultProtocol is the annotation used to specify the default protocol | ||
// for Linode load balancers. Options are tcp, http and https. Defaults to tcp. | ||
annLinodeDefaultProtocol = "service.beta.kubernetes.io/linode-loadbalancer-default-protocol" | ||
annLinodePortConfigPrefix = "service.beta.kubernetes.io/linode-loadbalancer-port-" | ||
annLinodeDefaultProxyProtocol = "service.beta.kubernetes.io/linode-loadbalancer-default-proxy-protocol" | ||
|
||
annLinodeCheckPath = "service.beta.kubernetes.io/linode-loadbalancer-check-path" | ||
annLinodeCheckBody = "service.beta.kubernetes.io/linode-loadbalancer-check-body" | ||
annLinodeHealthCheckType = "service.beta.kubernetes.io/linode-loadbalancer-check-type" | ||
|
||
annLinodeHealthCheckInterval = "service.beta.kubernetes.io/linode-loadbalancer-check-interval" | ||
annLinodeHealthCheckTimeout = "service.beta.kubernetes.io/linode-loadbalancer-check-timeout" | ||
annLinodeHealthCheckAttempts = "service.beta.kubernetes.io/linode-loadbalancer-check-attempts" | ||
annLinodeHealthCheckPassive = "service.beta.kubernetes.io/linode-loadbalancer-check-passive" | ||
|
||
// annLinodeThrottle is the annotation specifying the value of the Client Connection | ||
// Throttle, which limits the number of subsequent new connections per second from the | ||
// same client IP. Options are a number between 1-20, or 0 to disable. Defaults to 20. | ||
annLinodeThrottle = "service.beta.kubernetes.io/linode-loadbalancer-throttle" | ||
|
||
annLinodeLoadBalancerPreserve = "service.beta.kubernetes.io/linode-loadbalancer-preserve" | ||
annLinodeNodeBalancerID = "service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-id" | ||
|
||
annLinodeHostnameOnlyIngress = "service.beta.kubernetes.io/linode-loadbalancer-hostname-only-ingress" | ||
annLinodeLoadBalancerTags = "service.beta.kubernetes.io/linode-loadbalancer-tags" | ||
annLinodeCloudFirewallID = "service.beta.kubernetes.io/linode-loadbalancer-firewall-id" | ||
|
||
annLinodeNodePrivateIP = "node.k8s.linode.com/private-ip" | ||
annLinodeHostUUID = "node.k8s.linode.com/host-uuid" | ||
) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package linode | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/appscode/go/wait" | ||
"github.com/linode/linodego" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
v1informers "k8s.io/client-go/informers/core/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/cache" | ||
"k8s.io/client-go/util/workqueue" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
type nodeController struct { | ||
client Client | ||
instances *instances | ||
kubeclient kubernetes.Interface | ||
informer v1informers.NodeInformer | ||
|
||
queue workqueue.DelayingInterface | ||
} | ||
|
||
func newNodeController(kubeclient kubernetes.Interface, client Client, informer v1informers.NodeInformer) *nodeController { | ||
return &nodeController{ | ||
client: client, | ||
instances: newInstances(client), | ||
kubeclient: kubeclient, | ||
informer: informer, | ||
queue: workqueue.NewDelayingQueue(), | ||
} | ||
} | ||
|
||
func (s *nodeController) Run(stopCh <-chan struct{}) { | ||
s.informer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ | ||
AddFunc: func(obj interface{}) { | ||
node, ok := obj.(*v1.Node) | ||
if !ok { | ||
return | ||
} | ||
|
||
klog.Infof("NodeController will handle newly created node (%s) metadata", node.Name) | ||
s.queue.Add(node) | ||
}, | ||
UpdateFunc: func(_, new interface{}) { | ||
node, ok := new.(*v1.Node) | ||
if !ok { | ||
return | ||
} | ||
|
||
klog.Infof("NodeController will handle updated node (%s) metadata", node.Name) | ||
s.queue.Add(node) | ||
}, | ||
}) | ||
|
||
go wait.Until(s.worker, time.Second, stopCh) | ||
s.informer.Informer().Run(stopCh) | ||
} | ||
|
||
// worker runs a worker thread that dequeues new or modified nodes and processes | ||
// metadata (host UUID) on each of them. | ||
func (s *nodeController) worker() { | ||
for s.processNext() { | ||
} | ||
} | ||
|
||
func (s *nodeController) processNext() bool { | ||
key, quit := s.queue.Get() | ||
if quit { | ||
return false | ||
} | ||
defer s.queue.Done(key) | ||
|
||
node, ok := key.(*v1.Node) | ||
if !ok { | ||
klog.Errorf("expected dequeued key to be of type *v1.Node but got %T", node) | ||
return true | ||
} | ||
|
||
err := s.handleNodeAdded(context.TODO(), node) | ||
switch deleteErr := err.(type) { | ||
case nil: | ||
break | ||
|
||
case *linodego.Error: | ||
if deleteErr.Code >= http.StatusInternalServerError || deleteErr.Code == http.StatusTooManyRequests { | ||
klog.Errorf("failed to add metadata for node (%s); retrying in 1 minute: %s", node.Name, err) | ||
s.queue.AddAfter(node, retryInterval) | ||
} | ||
|
||
default: | ||
klog.Errorf("failed to add metadata for node (%s); will not retry: %s", node.Name, err) | ||
} | ||
return true | ||
} | ||
|
||
func (s *nodeController) handleNodeAdded(ctx context.Context, node *v1.Node) error { | ||
klog.Infof("NodeController handling node (%s) addition", node.Name) | ||
|
||
linode, err := s.instances.lookupLinode(ctx, node) | ||
if err != nil { | ||
klog.Infof("instance lookup error: %s", err.Error()) | ||
return err | ||
} | ||
|
||
uuid, ok := node.Labels[annLinodeHostUUID] | ||
if ok && uuid == linode.HostUUID { | ||
return nil | ||
} | ||
|
||
node.Labels[annLinodeHostUUID] = linode.HostUUID | ||
|
||
_, err = s.kubeclient.CoreV1().Nodes().Update(ctx, node, metav1.UpdateOptions{}) | ||
if err != nil { | ||
klog.Infof("node update error: %s", err.Error()) | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.
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.
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.
is this still required after the linodego update?
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.
This is the same logic as in the linode-cosi-driver and linode-blockstorage-csi-driver, added there just so we have similar code paths in all 3 components.
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.
maybe a dumb question, but why dont we make a
linodeClient.ParseURL
which does this logic and sets the base url and version for you. this would move all this logic to the linodego and we could reuse it right?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.
@lgarber-akamai @zliang-akamai for visibility on my dumb questions
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.
Hi @luthermonson, I think you are right. Let us discuss it and get back to you next week.
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.
Sorry for the late follow-up! I think this is a good idea and I've created a ticket internally to get this implemented ^