Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="NLog" Version="5.0.4" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.1" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />
<PackageReference Include="TaskScheduler" Version="2.7.2" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net8.0-windows'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class KubernetesClientCompatibilityTests
{
static readonly object[] TestClusterVersions =
[
new object[] {new ClusterVersion(1, 34)},
new object[] {new ClusterVersion(1, 33)},
new object[] {new ClusterVersion(1, 32)},
new object[] {new ClusterVersion(1, 31)},
new object[] {new ClusterVersion(1, 30)},
];

KubernetesTestsGlobalContext? testContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<None Remove="Setup\teamcity-network-routing.yaml" />
<EmbeddedResource Include="Setup\KindConfiguration\kind-config-v1-30.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Setup\KindConfiguration\kind-config-v1-31.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
Expand All @@ -69,6 +66,9 @@
<EmbeddedResource Include="Setup\KindConfiguration\kind-config-v1-33.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Setup\KindConfiguration\kind-config-v1-34.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Setup\linux-network-routing.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ apiVersion: kind.x-k8s.io/v1alpha4

nodes:
- role: control-plane
image: kindest/node:v1.31.9@sha256:b94a3a6c06198d17f59cca8c6f486236fa05e2fb359cbd75dabbfc348a10b211
image: kindest/node:v1.31.12@sha256:0f5cc49c5e73c0c2bb6e2df56e7df189240d83cf94edfa30946482eb08ec57d2
- role: worker
image: kindest/node:v1.31.9@sha256:b94a3a6c06198d17f59cca8c6f486236fa05e2fb359cbd75dabbfc348a10b211
image: kindest/node:v1.31.12@sha256:0f5cc49c5e73c0c2bb6e2df56e7df189240d83cf94edfa30946482eb08ec57d2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ apiVersion: kind.x-k8s.io/v1alpha4

nodes:
- role: control-plane
image: kindest/node:v1.32.5@sha256:e3b2327e3a5ab8c76f5ece68936e4cafaa82edf58486b769727ab0b3b97a5b0d
image: kindest/node:v1.32.8@sha256:abd489f042d2b644e2d033f5c2d900bc707798d075e8186cb65e3f1367a9d5a1
- role: worker
image: kindest/node:v1.32.5@sha256:e3b2327e3a5ab8c76f5ece68936e4cafaa82edf58486b769727ab0b3b97a5b0d
image: kindest/node:v1.32.8@sha256:abd489f042d2b644e2d033f5c2d900bc707798d075e8186cb65e3f1367a9d5a1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ apiVersion: kind.x-k8s.io/v1alpha4

nodes:
- role: control-plane
image: kindest/node:v1.33.1@sha256:050072256b9a903bd914c0b2866828150cb229cea0efe5892e2b644d5dd3b34f
image: kindest/node:v1.33.4@sha256:25a6018e48dfcaee478f4a59af81157a437f15e6e140bf103f85a2e7cd0cbbf2
- role: worker
image: kindest/node:v1.33.1@sha256:050072256b9a903bd914c0b2866828150cb229cea0efe5892e2b644d5dd3b34f
image: kindest/node:v1.33.4@sha256:25a6018e48dfcaee478f4a59af81157a437f15e6e140bf103f85a2e7cd0cbbf2
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4

nodes:
- role: control-plane
image: kindest/node:v1.34.0@sha256:7416a61b42b1662ca6ca89f02028ac133a309a2a30ba309614e8ec94d976dc5a
- role: worker
image: kindest/node:v1.34.0@sha256:7416a61b42b1662ca6ca89f02028ac133a309a2a30ba309614e8ec94d976dc5a
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Octopus.Tentacle.Kubernetes.Tests.Integration.Setup.Tooling;

public class HelmDownloader : ToolDownloader
{
const string LatestVersion = "v3.18.6";
const string LatestVersion = "v3.19.2";
public HelmDownloader( ILogger logger)
: base("helm", logger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Octopus.Tentacle.Kubernetes.Tests.Integration.Setup.Tooling
{
public class KindDownloader : ToolDownloader
{
const string LatestKindVersion = "v0.29.0";
const string LatestKindVersion = "v0.30.0";

public KindDownloader(ILogger logger)
: base("kind", logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Octopus.Tentacle.Kubernetes.Tests.Integration.Setup.Tooling;

public class KubeCtlDownloader : ToolDownloader
{
public const string LatestKubeCtlVersion = "v1.33.5";
public const string LatestKubeCtlVersion = "v1.34.2";

public KubeCtlDownloader(ILogger logger)
: base("kubectl", logger)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task NoEntriesAreSentToMetricsWhenEventListIsEmpty()
var agentMetrics = Substitute.For<IKubernetesAgentMetrics>();
agentMetrics.GetLatestEventTimestamp(Arg.Any<CancellationToken>()).ReturnsForAnyArgs(testEpoch);
var eventService = Substitute.For<IKubernetesEventService>();
var sut = new KubernetesEventMonitor(agentMetrics, eventService, "arbitraryNamespace", new IEventMapper[]{new NfsPodRestarted(), new TentacleKilledEventMapper(), new NfsStaleEventMapper()}, log);
var sut = new KubernetesEventMonitor(agentMetrics, eventService, "arbitraryNamespace", new IEventMapper[] { new NfsPodRestarted(), new TentacleKilledEventMapper(), new NfsStaleEventMapper() }, log);

await sut.CacheNewEvents(tokenSource.Token);

Expand All @@ -72,20 +72,23 @@ public async Task NfsPodKillingEventsAreTrackedInMetrics()
var agentMetrics = new StubbedAgentMetrics(testEpoch);
var eventService = Substitute.For<IKubernetesEventService>();
eventService.FetchAllEventsAsync(Arg.Any<string>(), Arg.Any<CancellationToken>()).ReturnsForAnyArgs(
new Corev1EventList(new List<Corev1Event>
new Corev1EventList
{
new()
Items = new List<Corev1Event>
{
Reason = "Killing",
Metadata = new V1ObjectMeta()
new()
{
Name = "octopus-agent-nfs-123412-1234123",
},
FirstTimestamp = testEpoch.DateTime.AddMinutes(1),
LastTimestamp = testEpoch.DateTime.AddMinutes(1)
Reason = "Killing",
Metadata = new V1ObjectMeta()
{
Name = "octopus-agent-nfs-123412-1234123",
},
FirstTimestamp = testEpoch.DateTime.AddMinutes(1),
LastTimestamp = testEpoch.DateTime.AddMinutes(1)
}
}
}));
var sut = new KubernetesEventMonitor(agentMetrics, eventService, "arbitraryNamespace", new IEventMapper[]{new NfsPodRestarted(), new TentacleKilledEventMapper(), new NfsStaleEventMapper()}, log);
});
var sut = new KubernetesEventMonitor(agentMetrics, eventService, "arbitraryNamespace", new IEventMapper[] { new NfsPodRestarted(), new TentacleKilledEventMapper(), new NfsStaleEventMapper() }, log);

//Act
await sut.CacheNewEvents(tokenSource.Token);
Expand All @@ -105,21 +108,24 @@ public async Task NfsWatchDogEventsAreTrackedInMetrics()
var agentMetrics = new StubbedAgentMetrics(testEpoch);
var eventService = Substitute.For<IKubernetesEventService>();
eventService.FetchAllEventsAsync(Arg.Any<string>(), Arg.Any<CancellationToken>()).ReturnsForAnyArgs(
new Corev1EventList(new List<Corev1Event>
new Corev1EventList
{
new()
Items = new List<Corev1Event>
{
Reason = "NfsWatchdogTimeout",
Metadata = new V1ObjectMeta()
new()
{
Name = podName,
},
FirstTimestamp = testEpoch.DateTime.AddSeconds(1),
LastTimestamp = testEpoch.DateTime.AddSeconds(1)
Reason = "NfsWatchdogTimeout",
Metadata = new V1ObjectMeta()
{
Name = podName,
},
FirstTimestamp = testEpoch.DateTime.AddSeconds(1),
LastTimestamp = testEpoch.DateTime.AddSeconds(1)
}
}
}));
});

var sut = new KubernetesEventMonitor(agentMetrics, eventService, "arbitraryNamespace", new IEventMapper[]{new NfsPodRestarted(), new TentacleKilledEventMapper(), new NfsStaleEventMapper()}, log);
var sut = new KubernetesEventMonitor(agentMetrics, eventService, "arbitraryNamespace", new IEventMapper[] { new NfsPodRestarted(), new TentacleKilledEventMapper(), new NfsStaleEventMapper() }, log);

//Act
await sut.CacheNewEvents(tokenSource.Token);
Expand All @@ -139,24 +145,27 @@ public async Task EventsOlderThanOrEqualToMetricsTimestampCursorAreNotAddedToMet
var agentMetrics = new StubbedAgentMetrics(testEpoch);
var eventService = Substitute.For<IKubernetesEventService>();
eventService.FetchAllEventsAsync(Arg.Any<string>(), Arg.Any<CancellationToken>()).ReturnsForAnyArgs(
new Corev1EventList(new List<Corev1Event>
new Corev1EventList
{
new()
Items = new List<Corev1Event>
{
Reason = "NfsWatchdogTimeout",
Metadata = new V1ObjectMeta()
new()
{
Name = podName,
},
FirstTimestamp = testEpoch.DateTime,
LastTimestamp = testEpoch.DateTime
Reason = "NfsWatchdogTimeout",
Metadata = new V1ObjectMeta()
{
Name = podName,
},
FirstTimestamp = testEpoch.DateTime,
LastTimestamp = testEpoch.DateTime
}
}
}));
var sut = new KubernetesEventMonitor(agentMetrics, eventService, "arbitraryNamespace", new IEventMapper[]{new NfsPodRestarted(), new TentacleKilledEventMapper(), new NfsStaleEventMapper()}, log);
});

var sut = new KubernetesEventMonitor(agentMetrics, eventService, "arbitraryNamespace", new IEventMapper[] { new NfsPodRestarted(), new TentacleKilledEventMapper(), new NfsStaleEventMapper() }, log);
//Act
await sut.CacheNewEvents(tokenSource.Token);

//Assert
agentMetrics.Events.Should().BeEquivalentTo(new Dictionary<string, Dictionary<string, List<DateTimeOffset>>>());
}
Expand All @@ -169,25 +178,28 @@ public async Task NewestTimeStampInEventIsUsedToDetermineAgeAndAsMetricsValue()
var agentMetrics = new StubbedAgentMetrics(testEpoch);
var eventService = Substitute.For<IKubernetesEventService>();
eventService.FetchAllEventsAsync(Arg.Any<string>(), Arg.Any<CancellationToken>()).ReturnsForAnyArgs(
new Corev1EventList(new List<Corev1Event>
new Corev1EventList
{
new()
Items = new List<Corev1Event>
{
Reason = "NfsWatchdogTimeout",
Metadata = new V1ObjectMeta()
new()
{
Name = podName,
},
FirstTimestamp = testEpoch.DateTime.AddMinutes(-2),
LastTimestamp = testEpoch.DateTime.AddMinutes(-1),
EventTime = testEpoch.DateTime.AddMinutes(1)
Reason = "NfsWatchdogTimeout",
Metadata = new V1ObjectMeta()
{
Name = podName,
},
FirstTimestamp = testEpoch.DateTime.AddMinutes(-2),
LastTimestamp = testEpoch.DateTime.AddMinutes(-1),
EventTime = testEpoch.DateTime.AddMinutes(1)
}
}
}));
var sut = new KubernetesEventMonitor(agentMetrics, eventService, "arbitraryNamespace", new IEventMapper[]{new NfsPodRestarted(), new TentacleKilledEventMapper(), new NfsStaleEventMapper()}, log);
});

var sut = new KubernetesEventMonitor(agentMetrics, eventService, "arbitraryNamespace", new IEventMapper[] { new NfsPodRestarted(), new TentacleKilledEventMapper(), new NfsStaleEventMapper() }, log);
//Act
await sut.CacheNewEvents(tokenSource.Token);

//Assert
// The event.EventTime is newest event Time stamp, and is larger than the last metric date (TestEpoch) as such
// the event should factored into the metrics, and should report this latest time value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void SetUp()
{
podService = Substitute.For<IKubernetesPodService>();
log = new InMemoryLog();
clock = new FixedClock(new DateTimeOffset(2023,5,17,13,4,5, TimeSpan.Zero));
clock = new FixedClock(new DateTimeOffset(2023, 5, 17, 13, 4, 5, TimeSpan.Zero));
monitor = new KubernetesPodMonitor(podService, log, new TentacleScriptLogProvider(), clock);

scriptTicket = new ScriptTicket(Guid.NewGuid().ToString());
Expand Down Expand Up @@ -111,7 +111,7 @@ public async Task ExistingPodIsUpdatedWhenCompleted()
new()
{
Name = scriptTicket.ToKubernetesScriptPodName(),
State = new V1ContainerState(terminated: new V1ContainerStateTerminated(0, finishedAt: DateTime.UtcNow))
State = new V1ContainerState { Terminated = new V1ContainerStateTerminated { ExitCode = 0, FinishedAt = DateTime.UtcNow } }
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TrackedScriptPodFixture
public void SetUp()
{
scriptTicket = new ScriptTicket("ScriptTicketId");
clock = new FixedClock(new DateTimeOffset(2023,5,17,13,4,5, TimeSpan.Zero));
clock = new FixedClock(new DateTimeOffset(2023, 5, 17, 13, 4, 5, TimeSpan.Zero));
trackedPod = new TrackedScriptPod(scriptTicket, clock);
}

Expand All @@ -29,8 +29,8 @@ public void NullStatus_Pending()
{
//Just changing the tracked Pod to a different state
GetPodInRunningState();
trackedPod.Update(new V1Pod(){ Metadata = new V1ObjectMeta(), Status = null});

trackedPod.Update(new V1Pod() { Metadata = new V1ObjectMeta(), Status = null });
trackedPod.State.Phase.Should().Be(TrackedScriptPodPhase.Pending);
}

Expand All @@ -39,11 +39,11 @@ public void NullContainerStatus_Pending()
{
//Just changing the tracked Pod to a different state
GetPodInRunningState();
trackedPod.Update(new V1Pod(){ Metadata = new V1ObjectMeta(), Status = new V1PodStatus(){ Phase = "Foo", ContainerStatuses = null}});

trackedPod.Update(new V1Pod() { Metadata = new V1ObjectMeta(), Status = new V1PodStatus() { Phase = "Foo", ContainerStatuses = null } });
trackedPod.State.Phase.Should().Be(TrackedScriptPodPhase.Pending);
}

[Test]
public void ScriptContainerNotFound_Pending()
{
Expand All @@ -58,7 +58,7 @@ public void ScriptContainerNotFound_Pending()
public void CanTransitionFromPendingToRunning()
{
trackedPod.State.Phase.Should().Be(TrackedScriptPodPhase.Pending);

GetPodInRunningState();
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public void UpdateWithCompletedPodButNoFinishedAt(string podPhase, int exitCode,
trackedPod.State.ExitCode.Should().Be(exitCode);
trackedPod.State.FinishedAt.Should().Be(clock.GetUtcTime());
}

[TestCase(0, TrackedScriptPodPhase.Succeeded)]
[TestCase(123, TrackedScriptPodPhase.Failed)]
public void MarkAsCompleted(int exitCode, TrackedScriptPodPhase expectedPhase)
Expand Down Expand Up @@ -130,7 +130,7 @@ public void PodUpdateAfterMarkAsCompleted_UpdatesToNewValue()
trackedPod.State.ExitCode.Should().Be(podStatusExitCode);
trackedPod.State.FinishedAt.Should().Be(podStatusFinishedAt);
}

void GetPodInRunningState()
{
trackedPod.Update(CreateV1Pod(RunningContainerState()));
Expand All @@ -144,7 +144,6 @@ static V1ContainerState RunningContainerState()
{
return new V1ContainerState()
{

Running = new V1ContainerStateRunning()
};
}
Expand All @@ -153,7 +152,6 @@ static V1ContainerState TerminatedContainerState(DateTime? finishedAt, int exitC
{
return new V1ContainerState()
{

Terminated = new V1ContainerStateTerminated()
{
FinishedAt = finishedAt,
Expand Down Expand Up @@ -183,7 +181,7 @@ static V1Pod CreateV1Pod(V1ContainerStatus containerStatus)
}
};

return new V1Pod(status: podStatus, metadata: new V1ObjectMeta());
return new V1Pod { Status = podStatus, Metadata = new V1ObjectMeta() };
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public KubernetesEventMonitor(IKubernetesAgentMetrics agentMetrics, IKubernetesE
public async Task CacheNewEvents(CancellationToken cancellationToken)
{
log.Info($"Parsing kubernetes event list for namespace {kubernetesNamespace}.");
var allEvents = await eventService.FetchAllEventsAsync(kubernetesNamespace, cancellationToken) ?? new Corev1EventList(new List<Corev1Event>());
var allEvents = await eventService.FetchAllEventsAsync(kubernetesNamespace, cancellationToken) ?? new Corev1EventList();

var lastCachedEventTimeStamp = await agentMetrics.GetLatestEventTimestamp(cancellationToken);

Expand Down
Loading