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.
General:
Pull Request Guidelines:
BUGFIX: This code change involves modifying the logic for handling metadata updates for Linode instances in a Kubernetes cluster. Previous behaviour spammed, did redundant work on Create and Update, and every time it was triggered, it pulled the node from the API. This prevents hitting the API too often.
instances.go:
timeout
variable is changed to be initialised with a default value of 15.LINODE_INSTANCE_CACHE_TTL
is set, the timeout is updated accordingly, but now it checks if the parsed value is greater than 0 before updating thetimeout
. This ensures that only positive values are considered valid for the timeout.node_controller.go:
nodeController
structure is extended to include async.RWMutex
for safe concurrent access to shared data.metadataLastUpdate
andttl
, are added to keep track of the last metadata update time and the time-to-live for metadata, respectively.timeout
variable is introduced, which defaults to 300 seconds (5 minutes), and it can be overridden by theLINODE_METADATA_TTL
environment variable.LastMetadataUpdate
andSetLastMetadataUpdate
, are added to get and set the last metadata update time for a given node name in a thread safe manner.Changes in
handleNodeAdded
:SetLastMetadataUpdate
method is called after a successful update to store the current time as the last update time for that node.Changes in
Run
:UpdateFunc
in the informer is removed. This function was handling updated nodes' metadata, but it's redundant.In summary, the changes provide better control over the caching mechanism for Linode instance metadata. The introduction of a TTL for metadata and the ability to configure it through environment variables allow for more flexibility and optimisation in handling updates. Additionally, the use of a mutex ensures thread-safe access to shared data in a concurrent environment.