Skip to content

Commit

Permalink
Fix incorrect TCP port used by default for k8s probes (#5085)
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Taillefer <mataille@microsoft.com>
  • Loading branch information
geeknoid and Martin Taillefer authored Apr 8, 2024
1 parent 88e1a9d commit 5fc05f8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ public static IServiceCollection AddKubernetesProbes(this IServiceCollection ser
return services
.AddTcpEndpointProbe(ProbeTags.Liveness, options =>
{
options.TcpPort = wrapperOptions.LivenessProbe.TcpPort;
wrapperOptions.LivenessProbe = options;

configure(wrapperOptions);

var originalPredicate = options.FilterChecks;
if (originalPredicate == null)
{
Expand All @@ -66,8 +69,11 @@ public static IServiceCollection AddKubernetesProbes(this IServiceCollection ser
})
.AddTcpEndpointProbe(ProbeTags.Startup, options =>
{
options.TcpPort = wrapperOptions.StartupProbe.TcpPort;
wrapperOptions.StartupProbe = options;

configure(wrapperOptions);

var originalPredicate = options.FilterChecks;
if (originalPredicate == null)
{
Expand All @@ -80,8 +86,11 @@ public static IServiceCollection AddKubernetesProbes(this IServiceCollection ser
})
.AddTcpEndpointProbe(ProbeTags.Readiness, (options) =>
{
options.TcpPort = wrapperOptions.ReadinessProbe.TcpPort;
wrapperOptions.ReadinessProbe = options;

configure(wrapperOptions);

var originalPredicate = options.FilterChecks;
if (originalPredicate == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ public void AddKubernetesProbes_RegistersAllProbes()
Assert.True(livenessConfig.FilterChecks!(livenessRegistration));
Assert.False(livenessConfig.FilterChecks(startupRegistration));
Assert.False(livenessConfig.FilterChecks(readinessRegistration));
Assert.Equal(2305, livenessConfig.TcpPort);

var startupConfig = config.Get(ProbeTags.Startup);
Assert.False(startupConfig.FilterChecks!(livenessRegistration));
Assert.True(startupConfig.FilterChecks(startupRegistration));
Assert.False(startupConfig.FilterChecks(readinessRegistration));
Assert.Equal(2306, startupConfig.TcpPort);

var readinessConfig = config.Get(ProbeTags.Readiness);
Assert.False(readinessConfig.FilterChecks!(livenessRegistration));
Assert.False(readinessConfig.FilterChecks(startupRegistration));
Assert.True(readinessConfig.FilterChecks(readinessRegistration));
Assert.Equal(2307, readinessConfig.TcpPort);
}

[Fact]
Expand Down

0 comments on commit 5fc05f8

Please sign in to comment.