Skip to content

feat: ECS Cluster Target Discovery #2013

Open
Jtango18 wants to merge 20 commits into
mainfrom
jt/spf-deprecation-replace-ecs-target-discovery
Open

feat: ECS Cluster Target Discovery #2013
Jtango18 wants to merge 20 commits into
mainfrom
jt/spf-deprecation-replace-ecs-target-discovery

Conversation

@Jtango18

@Jtango18 Jtango18 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

⚠️ Does this change require a corresponding Server Change?
⚠️ If so - please add a "Requires Server Change" label to this PR!

Implements Target Discovery for Conventional ECS Clusters as part of SPF Deprecation.

Centralises some AWS Credentials handling use by AKS for simplicity - more cleanup in a later PR

Server Change is staged here

@Jtango18 Jtango18 force-pushed the jt/spf-deprecation-replace-ecs-target-discovery branch 2 times, most recently from 5d67b08 to b8c1e1a Compare June 15, 2026 06:46
@Jtango18 Jtango18 force-pushed the jt/spf-deprecation-replace-ecs-target-discovery branch from 5482c90 to 0bdd0a1 Compare June 16, 2026 09:57
@Jtango18 Jtango18 marked this pull request as ready for review June 16, 2026 10:07
namespace Calamari.Aws.Integration.Ecs;

// TODO: Replace Static Helper with concrete class/interface to enable better testing
public static class EcsClientFactoryHelper

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is this class adding value - could people just go direct to the factory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They could, but I'm focused addition with this PR, avoiding modifying other functionality until a future PR.

var environment = AwsEnvironmentGeneration.Create(log, variables).GetAwaiter().GetResult();

using var ecsClient = EcsClientFactory.Create(environment);
using var ecsClient = EcsClientFactoryHelper.Create(environment);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can probably inject this as an autofac delegate factory (EcsClientFactory.Factory)

@Jtango18 Jtango18 Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I got chipped last time I did that :-(
Also, note from the above, that this will disappear in a future PR anyway - there's a lot of love for static in the AWS related code for some reason.

{
discoveredTargetCount++;
log.Info($"Discovered matching ECS cluster '{cluster.ClusterName}' in {region}.");
clusterDiscoveryWriter.WriteTargetCreationServiceMessage(region, cluster, authentication, scope, matchResult);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

standard question - IF we failed finding the 3rd cluster - should we have reported the first 2?
Eg: should this logic create a list of discovered clusters - then turn them into service msgs at the very end (Rather than after each discovery)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@zentron This is an intersting talking point. I've matched the existing behaviour, but it's worthy of further exploration moving forward (outside the confines of the SPF Deprecation Project)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fair question. I would naievely say that it should still report the first 2, even if they one of them failed, since they are presumably valid.
So long as it doesnt fail and then no longer detect cluster #4 if #3 fails, it seems reasonable to still detect the ones that did show up.

@rain-on rain-on left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread source/Calamari.Common/Features/Discovery/DefaultKeyNames.cs Outdated
public static readonly string Manifest = "Octopus.Steps.Manifest";
}

public const string TargetDiscoveryContext = "Octopus.TargetDiscovery.Context";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: is this the right place?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved in 08a1604

Comment thread source/Calamari.Tests/AWS/Behaviours/EcsClusterDiscoveryBehaviourTests.cs Outdated
await sut.Execute(deployment);

// Assert
fakeWriter.DidNotReceive()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: fake log to show no clusters found

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved in 2036202

@zentron zentron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Feel free to merge when ready 👍

{
discoveredTargetCount++;
log.Info($"Discovered matching ECS cluster '{cluster.ClusterName}' in {region}.");
clusterDiscoveryWriter.WriteTargetCreationServiceMessage(region, cluster, authentication, scope, matchResult);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fair question. I would naievely say that it should still report the first 2, even if they one of them failed, since they are presumably valid.
So long as it doesnt fail and then no longer detect cluster #4 if #3 fails, it seems reasonable to still detect the ones that did show up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants