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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement agent reuse, toggled by a cluster profile config option #355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brandonvin
Copy link
Contributor

@brandonvin brandonvin commented May 20, 2023

Description

This implements agent reuse following the approach outlined in these comments: #53 (comment) #53 (comment). Resolves #53

Cluster profile has an option to enable agent reuse, defaulting to false:

Gocd cluster profile option edit

Gocd cluster profile option

The naming, and presentation of this option, are open to feedback! 馃檪

Changes

When pods are created, they are annotated with a hash of the elastic config. This ensures that when elastic config is changed, agents created from the old config will not be reused, and will eventually expire after the timeout.

When agent reuse is enabled, the main behavior changes are:

  • Job completion request -> instead of terminating the agent, mark the agent as idle so it may be considered for reuse
  • Should assign work request -> assign work only if the agent is available for work and the elastic config hash matches the agent
  • Create agent request -> only create an agent if none are available for reuse

Other supporting changes:

  • KubernetesInstance is an immutable data class constructed by a builder, and no longer contains a Kubernetes client.
  • Improving field names (e.g. properties) for clarity between cluster profile properties and elastic profile properties.
  • Refreshing instances moved inside the ServerPingRequestExecutor instead of "inline" in the KubernetesPlugin request handling block.
  • Added a request handler for REQUEST_PLUGIN_SETTINGS that returns an empty map - just to silence some warnings about this request not being implemented.
  • Some classes are refactored to allow testing with less mocking.
  • Removed an unnecessary semaphore.

This ended up being a pretty large set of changes. Happy to explain in more detail if needed!

Testing

Many unit tests updated and added, and run with ./gradlew test. I've also tested this running GoCD on my machine with a Kubernetes cluster in kind.

@brandonvin brandonvin marked this pull request as ready for review May 20, 2023 19:57
@chadlwilson
Copy link
Member

Thanks for this. Appreciate all the work here. Unfortunately I have limited capacity to review, try out and give useful insight so might take me some time 馃檹

@woopstar
Copy link

Nice work +1 on this

@chadlwilson chadlwilson force-pushed the add-option-to-enable-agent-reuse branch from 179c5a7 to a7e1761 Compare January 6, 2024 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Elastic Agent Reuse
3 participants