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

Add client operations to support registering the Kubernetes agent as a worker #858

Merged
merged 9 commits into from
Jun 28, 2024

Conversation

kevjt
Copy link
Contributor

@kevjt kevjt commented Jun 25, 2024

Background

We would like to support running the Kubernetes Agent as a worker. To do this, Tentacle must have a way to call the worker registration API of Octopus Server. It communicates with Server via Octopus.Client Operations, which act as an abstraction over the API library.

Associated PRs

[sc-82021]

Result

  • Introduces an IRegisterKubernetesWorkerOperation
  • Deprecates the existing IRegisterKubernetesClusterOperation and rebrands it as IRegisterKubernetesDeploymentTargetOperation as we want to be clear in the distinction between the two (the functionality is still the same)

@kevjt kevjt marked this pull request as ready for review June 26, 2024 07:11
Copy link
Contributor

@scme0 scme0 left a comment

Choose a reason for hiding this comment

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

LGTM, nice work and thanks for adding the tests 👍

Just one comment to reuse your nice FindByNameIdOrSlugs extension method for Tenants as well if possible but I think I can pre-approve.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tenants are also retrieved by name, id, or slug, Can you update that method (GetTenants) to use the new extension method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out that only the non-async GetTenants currently supports slugs, and it is the async version that get actually gets used in Tentacle..

Nevertheless, I will adjust both to use the new extension method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that's probably my fault. Sorry and thanks! 🙏

(It sucks supporting both sync and async 👎 )


internal static class AsyncRepositoryExtensions
{
public static async Task<List<TResource>> FindByNameIdOrSlugs<TResource, TRepository>(this TRepository repository,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

@rain-on rain-on left a comment

Choose a reason for hiding this comment

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

already approved, but a few thoughts.

if (missing.Any())
throw new InvalidRegistrationArgumentsException(CouldNotFindByMultipleMessage("environment", missing.ToArray()));
var environmentsByNameIdOrSlug =
repository.Environments.FindByNameIdOrSlugs<EnvironmentResource, IEnvironmentRepository>(
Copy link
Contributor

Choose a reason for hiding this comment

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

seems odd that the FindByIdOrName would take a lambda for failures - that's the callers problem, not here's.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately this is because the caller needs to provide a custom error message that contains the type of resource it couldn't find (I think this is because it needs to be in the error logs in Tentacle.. and Client.Operations is largely concerned about Tentacle). In any case, the actual error message generator comes from a protected static method defined in RegisterMachineOperationBase, presumably specific to machine operations. Using a lambda to preserve existing error logging was the best solution I could come up with. I didn't want the generic extension method to start knowing about machine operation error messages.


if (missing.Any())
throw new InvalidRegistrationArgumentsException(CouldNotFindByMultipleMessage("environment", missing.ToArray()));
var environmentsByNameIdOrSlug =
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the variable is literally just "existingEnvs" - I don't care how you found them, I can see that in the function you called.
in fact - just "envs" would be perfectly fine :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea either way is fine really 🤷 It also doesn't hurt to be explicit, especially because the chunk of code above it is also adding environments that are found by name to the resulting env list.

@@ -12,6 +10,12 @@ public interface IRegisterWorkerOperation : IRegisterMachineOperationBase
/// <summary>
/// Gets or sets the worker pools that this machine should be added to.
/// </summary>
[Obsolete($"Use the {nameof(WorkerPools)} property as it supports worker pool names, slugs and Ids.")]
Copy link
Contributor

Choose a reason for hiding this comment

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

assuming this obsolete doesn't appear anywhere other than for coders?
Do we need to create a deprecation for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The people using this library will get compiler warnings about its deprecation. I think this is enough because the only way this can get used is through code.

}

async Task<List<WorkerPoolResource>> GetWorkerPools(IOctopusSpaceAsyncRepository repository)

Copy link
Contributor

Choose a reason for hiding this comment

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

remove whitespace -but probably done by pretty printer anyway.

@kevjt kevjt merged commit ba09b89 into master Jun 28, 2024
17 checks passed
@kevjt kevjt deleted the kevjt/kubernetes-agent-as-a-worker branch June 28, 2024 01:57
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.

3 participants