Skip to content

Commit 7624eb3

Browse files
committed
Improved error message when no agent connection is specified.
1 parent f5218bf commit 7624eb3

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/Contrast.K8s.AgentOperator/Core/State/Appliers/AgentInjectorApplier.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ public override async ValueTask<AgentInjectorResource> CreateFrom(V1Beta1AgentIn
4848
);
4949
var selector = GetSelector(spec, @namespace);
5050

51-
var connectionName = spec.Connection?.Name ?? _clusterDefaults.GetDefaultAgentConnectionName(@namespace);
52-
var connectionReference = new AgentInjectorConnectionReference(@namespace, connectionName);
51+
var namespaceDefaultConnectionName = _clusterDefaults.GetDefaultAgentConnectionName(@namespace);
52+
var connectionName = spec.Connection?.Name ?? namespaceDefaultConnectionName;
53+
var isConnectionNamespaceDefault = connectionName == namespaceDefaultConnectionName;
54+
var connectionReference = new AgentInjectorConnectionReference(@namespace, connectionName, isConnectionNamespaceDefault);
5355

5456
var namespaceDefaultConfigurationName = _clusterDefaults.GetDefaultAgentConfigurationName(@namespace);
5557
var configurationName = spec.Configuration?.Name ?? namespaceDefaultConfigurationName;
56-
var isNamespaceDefault = namespaceDefaultConfigurationName == configurationName;
57-
var configurationReference = new AgentConfigurationReference(@namespace, configurationName, isNamespaceDefault);
58+
var isConfigurationNamespaceDefault = namespaceDefaultConfigurationName == configurationName;
59+
var configurationReference = new AgentConfigurationReference(@namespace, configurationName, isConfigurationNamespaceDefault);
5860

5961
var pullSecretName = spec.Image.PullSecretName != null ? new SecretReference(@namespace, spec.Image.PullSecretName, ".dockerconfigjson") : null;
6062
var pullPolicy = spec.Image.PullPolicy ?? "Always";

src/Contrast.K8s.AgentOperator/Core/State/Resources/Primitives/AgentInjectorConnectionReference.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
namespace Contrast.K8s.AgentOperator.Core.State.Resources.Primitives
55
{
6-
public record AgentInjectorConnectionReference(string Namespace, string Name);
6+
public record AgentInjectorConnectionReference(string Namespace, string Name, bool IsNamespaceDefault);
77
}

src/Contrast.K8s.AgentOperator/Core/State/StateContainerExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static async ValueTask<ReadyResult<AgentInjectorResource>> GetReadyAgentI
3535
&& await state.GetReadyAgentConnectionById(
3636
connectionRef.Name,
3737
connectionRef.Namespace,
38+
connectionRef.IsNamespaceDefault,
3839
context,
3940
cancellationToken
4041
) != null;
@@ -76,6 +77,7 @@ public static async ValueTask<ReadyResult<AgentInjectorResource>> GetReadyAgentI
7677
private static async ValueTask<AgentConnectionResource?> GetReadyAgentConnectionById(this IStateContainer state,
7778
string name,
7879
string @namespace,
80+
bool isNamespaceDefault,
7981
ReadyContext readyContext,
8082
CancellationToken cancellationToken = default)
8183
{
@@ -112,7 +114,9 @@ public static async ValueTask<ReadyResult<AgentInjectorResource>> GetReadyAgentI
112114
}
113115
else
114116
{
115-
readyContext.AddFailureReason($"AgentConnection '{@namespace}/{name}' could not be found.");
117+
readyContext.AddFailureReason(isNamespaceDefault
118+
? "AgentConnection was not specified, and no cluster default was found."
119+
: $"AgentConnection '{@namespace}/{name}' could not be found.");
116120
}
117121

118122
return null;

0 commit comments

Comments
 (0)