-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
275 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
source/Octopus.Tentacle.Kubernetes.Tests.Integration/KubernetesClientCompatibilityTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,158 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Halibut; | ||
using Octopus.Tentacle.Client; | ||
using Octopus.Tentacle.Client.Scripts.Models; | ||
using Octopus.Tentacle.Client.Scripts.Models.Builders; | ||
using Octopus.Tentacle.CommonTestUtils; | ||
using Octopus.Tentacle.CommonTestUtils.Diagnostics; | ||
using Octopus.Tentacle.Contracts; | ||
using Octopus.Tentacle.Contracts.ClientServices; | ||
using Octopus.Tentacle.Kubernetes.Tests.Integration.Setup; | ||
using Octopus.Tentacle.Kubernetes.Tests.Integration.Util; | ||
using Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators; | ||
using Octopus.Tentacle.Tests.Integration.Common.Builders.Decorators.Proxies; | ||
using Octopus.Tentacle.Tests.Integration.Common.Logging; | ||
|
||
namespace Octopus.Tentacle.Kubernetes.Tests.Integration; | ||
|
||
[TestFixture] | ||
public class KubernetesClientCompatibilityTests | ||
{ | ||
static readonly object[] TestClusterVersions = | ||
[ | ||
new object[] {new ClusterVersion(1, 31)}, | ||
new object[] {new ClusterVersion(1, 30)}, | ||
new object[] {new ClusterVersion(1, 29)}, | ||
new object[] {new ClusterVersion(1, 28)}, | ||
]; | ||
|
||
string kindExePath; | ||
string helmExePath; | ||
string kubeCtlPath; | ||
KubernetesClusterInstaller clusterInstaller = null!; | ||
KubernetesAgentInstaller? kubernetesAgentInstaller; | ||
HalibutRuntime serverHalibutRuntime = null!; | ||
string? agentThumbprint; | ||
TraceLogFileLogger? traceLogFileLogger; | ||
CancellationToken cancellationToken; | ||
CancellationTokenSource? cancellationTokenSource; | ||
ILogger? logger; | ||
TentacleClient tentacleClient = null!; | ||
IRecordedMethodUsages recordedMethodUsages = null!; | ||
|
||
[OneTimeSetUp] | ||
public async Task OneTimeSetup() | ||
{ | ||
var toolDownloader = new RequiredToolDownloader(KubernetesTestsGlobalContext.Instance.TemporaryDirectory, KubernetesTestsGlobalContext.Instance.Logger); | ||
(kindExePath, helmExePath, kubeCtlPath) = await toolDownloader.DownloadRequiredTools(CancellationToken.None); | ||
} | ||
|
||
[TearDown] | ||
public async Task TearDown() | ||
{ | ||
if (traceLogFileLogger is not null) await traceLogFileLogger.DisposeAsync(); | ||
|
||
if (cancellationTokenSource is not null) | ||
{ | ||
await cancellationTokenSource.CancelAsync(); | ||
cancellationTokenSource.Dispose(); | ||
} | ||
|
||
clusterInstaller.Dispose(); | ||
KubernetesTestsGlobalContext.Instance.Dispose(); | ||
} | ||
|
||
[Test] | ||
[TestCaseSource(nameof(TestClusterVersions))] | ||
public async Task RunSimpleScript(ClusterVersion clusterVersion) | ||
{ | ||
await SetUp(clusterVersion); | ||
|
||
// Arrange | ||
var logs = new List<ProcessOutput>(); | ||
var scriptCompleted = false; | ||
|
||
var builder = new ExecuteKubernetesScriptCommandBuilder(LoggingUtils.CurrentTestHash()) | ||
.WithScriptBody(script => script | ||
.Print("Hello World") | ||
.PrintNTimesWithDelay("Yep", 30, TimeSpan.FromMilliseconds(100))); | ||
|
||
var command = builder.Build(); | ||
|
||
// Act | ||
var result = await tentacleClient.ExecuteScript(command, StatusReceived, ScriptCompleted, new InMemoryLog(), cancellationToken); | ||
|
||
// Assert | ||
logs.Should().Contain(po => po.Text.StartsWith("[POD EVENT]")); // Verify that we are receiving some pod events | ||
logs.Should().Contain(po => po.Source == ProcessOutputSource.StdOut && po.Text == "Hello World"); | ||
scriptCompleted.Should().BeTrue(); | ||
result.ExitCode.Should().Be(0); | ||
result.State.Should().Be(ProcessState.Complete); | ||
|
||
recordedMethodUsages.For(nameof(IAsyncClientKubernetesScriptServiceV1.StartScriptAsync)).Started.Should().Be(1); | ||
recordedMethodUsages.For(nameof(IAsyncClientKubernetesScriptServiceV1.GetStatusAsync)).Started.Should().BeGreaterThan(1); | ||
recordedMethodUsages.For(nameof(IAsyncClientKubernetesScriptServiceV1.CompleteScriptAsync)).Started.Should().Be(1); | ||
recordedMethodUsages.For(nameof(IAsyncClientKubernetesScriptServiceV1.CancelScriptAsync)).Started.Should().Be(0); | ||
|
||
return; | ||
|
||
void StatusReceived(ScriptExecutionStatus status) | ||
{ | ||
logs.AddRange(status.Logs); | ||
} | ||
|
||
Task ScriptCompleted(CancellationToken ct) | ||
{ | ||
scriptCompleted = true; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
async Task SetUp(ClusterVersion clusterVersion) | ||
{ | ||
await SetupCluster(clusterVersion); | ||
|
||
kubernetesAgentInstaller = new KubernetesAgentInstaller( | ||
KubernetesTestsGlobalContext.Instance.TemporaryDirectory, | ||
KubernetesTestsGlobalContext.Instance.HelmExePath, | ||
KubernetesTestsGlobalContext.Instance.KubeCtlExePath, | ||
KubernetesTestsGlobalContext.Instance.KubeConfigPath, | ||
KubernetesTestsGlobalContext.Instance.Logger); | ||
|
||
//create a new server halibut runtime | ||
serverHalibutRuntime = SetupHelpers.BuildServerHalibutRuntime(); | ||
var listeningPort = serverHalibutRuntime.Listen(); | ||
|
||
agentThumbprint = await kubernetesAgentInstaller.InstallAgent(listeningPort, KubernetesTestsGlobalContext.Instance.TentacleImageAndTag, new Dictionary<string, string>()); | ||
|
||
//trust the generated cert thumbprint | ||
serverHalibutRuntime.Trust(agentThumbprint); | ||
|
||
traceLogFileLogger = new TraceLogFileLogger(LoggingUtils.CurrentTestHash()); | ||
logger = new SerilogLoggerBuilder() | ||
.SetTraceLogFileLogger(traceLogFileLogger) | ||
.Build() | ||
.ForContext(GetType()); | ||
|
||
cancellationTokenSource = new CancellationTokenSource(); | ||
cancellationTokenSource.CancelAfter(TimeSpan.FromMinutes(5)); | ||
cancellationToken = cancellationTokenSource.Token; | ||
|
||
tentacleClient = SetupHelpers.BuildTentacleClient(kubernetesAgentInstaller.SubscriptionId, agentThumbprint, serverHalibutRuntime, builder => | ||
{ | ||
builder.RecordMethodUsages<IAsyncClientKubernetesScriptServiceV1>(out var recordedUsages); | ||
recordedMethodUsages = recordedUsages; | ||
}); | ||
} | ||
|
||
async Task SetupCluster(ClusterVersion clusterVersion) | ||
{ | ||
clusterInstaller = new KubernetesClusterInstaller(KubernetesTestsGlobalContext.Instance.TemporaryDirectory, kindExePath, helmExePath, kubeCtlPath, KubernetesTestsGlobalContext.Instance.Logger); | ||
await clusterInstaller.Install(clusterVersion); | ||
|
||
KubernetesTestsGlobalContext.Instance.TentacleImageAndTag = SetupHelpers.GetTentacleImageAndTag(kindExePath, clusterInstaller); | ||
KubernetesTestsGlobalContext.Instance.SetToolExePaths(helmExePath, kubeCtlPath); | ||
KubernetesTestsGlobalContext.Instance.KubeConfigPath = clusterInstaller.KubeConfigPath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...opus.Tentacle.Kubernetes.Tests.Integration/Setup/KindConfiguration/kind-config-v1-28.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.28.15@sha256:a7c05c7ae043a0b8c818f5a06188bc2c4098f6cb59ca7d1856df00375d839251 | ||
- role: worker | ||
image: kindest/node:v1.28.15@sha256:a7c05c7ae043a0b8c818f5a06188bc2c4098f6cb59ca7d1856df00375d839251 |
8 changes: 8 additions & 0 deletions
8
...opus.Tentacle.Kubernetes.Tests.Integration/Setup/KindConfiguration/kind-config-v1-29.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.29.12@sha256:62c0672ba99a4afd7396512848d6fc382906b8f33349ae68fb1dbfe549f70dec | ||
- role: worker | ||
image: kindest/node:v1.29.12@sha256:62c0672ba99a4afd7396512848d6fc382906b8f33349ae68fb1dbfe549f70dec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.