From e2d0ecec11ed923e8c0f168c66452a9592ed60fc Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 12:17:58 +1000 Subject: [PATCH 01/11] Add serviceName to NFS StatefulSet --- .changeset/dry-feet-add.md | 5 +++++ .../templates/nfs-statefulset.yaml | 3 +++ .../__snapshot__/nfs-statefulset_test.yaml.snap | 1 + .../tests/nfs-statefulset_test.yaml | 17 ++++++++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .changeset/dry-feet-add.md diff --git a/.changeset/dry-feet-add.md b/.changeset/dry-feet-add.md new file mode 100644 index 00000000..1910ff48 --- /dev/null +++ b/.changeset/dry-feet-add.md @@ -0,0 +1,5 @@ +--- +"kubernetes-agent": patch +--- + +Correctly set serviceName on NFS StatefulSet diff --git a/charts/kubernetes-agent/templates/nfs-statefulset.yaml b/charts/kubernetes-agent/templates/nfs-statefulset.yaml index 8912391b..757c1351 100644 --- a/charts/kubernetes-agent/templates/nfs-statefulset.yaml +++ b/charts/kubernetes-agent/templates/nfs-statefulset.yaml @@ -10,6 +10,9 @@ spec: selector: matchLabels: app.kubernetes.io/name: {{ include "nfs.name" .}} + {{- if .Release.IsInstall }} + serviceName: {{ include "nfs.name" .}} + {{- end }} template: metadata: {{- with .Values.persistence.nfs.metadata.annotations }} diff --git a/charts/kubernetes-agent/tests/__snapshot__/nfs-statefulset_test.yaml.snap b/charts/kubernetes-agent/tests/__snapshot__/nfs-statefulset_test.yaml.snap index 6349f10f..1b2fff00 100644 --- a/charts/kubernetes-agent/tests/__snapshot__/nfs-statefulset_test.yaml.snap +++ b/charts/kubernetes-agent/tests/__snapshot__/nfs-statefulset_test.yaml.snap @@ -11,6 +11,7 @@ should match snapshot: selector: matchLabels: app.kubernetes.io/name: octopus-agent-nfs + serviceName: octopus-agent-nfs template: metadata: labels: diff --git a/charts/kubernetes-agent/tests/nfs-statefulset_test.yaml b/charts/kubernetes-agent/tests/nfs-statefulset_test.yaml index 0d60e2dd..9481bc13 100644 --- a/charts/kubernetes-agent/tests/nfs-statefulset_test.yaml +++ b/charts/kubernetes-agent/tests/nfs-statefulset_test.yaml @@ -21,4 +21,19 @@ tests: asserts: - equal: path: spec.template.spec.volumes[?(@.name == 'octopus-volume')].emptyDir.sizeLimit - value: 100Gi \ No newline at end of file + value: 100Gi + +- it: does not set serviceName if Release.IsInstall is false + release: + upgrade: true + asserts: + - notExists: + path: spec.serviceName + +- it: sets serviceName if Release.IsInstall is true + release: + upgrade: false + asserts: + - equal: + path: spec.serviceName + value: octopus-agent-nfs \ No newline at end of file From 1cec36bf56c97fc1ca5094f910885a4cca43a34b Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 12:50:18 +1000 Subject: [PATCH 02/11] Run test with Helm 3.2.3 --- .../Setup/Tooling/HelmDownloader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs index f29f8c8d..b3e21d8c 100644 --- a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs @@ -6,7 +6,7 @@ namespace KubernetesAgent.Integration.Setup.Tooling; public class HelmDownloader : ToolDownloader { - const string LatestVersion = "v3.14.3"; + const string LatestVersion = "v3.2.3"; public HelmDownloader( ILogger logger) : base("helm", logger) { From c160e5b76bc5db109058423034fd7e2c56ac142e Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 13:07:49 +1000 Subject: [PATCH 03/11] Run test with Helm 3.8.0 --- .../Setup/Tooling/HelmDownloader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs index b3e21d8c..d5c14c26 100644 --- a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs @@ -6,7 +6,7 @@ namespace KubernetesAgent.Integration.Setup.Tooling; public class HelmDownloader : ToolDownloader { - const string LatestVersion = "v3.2.3"; + const string LatestVersion = "v3.8.0"; public HelmDownloader( ILogger logger) : base("helm", logger) { From e23a795debb5f42ebd6e079db588db8a0caf65bf Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 13:26:18 +1000 Subject: [PATCH 04/11] Disable validation for initial install --- .../Setup/KubernetesAgentInstaller.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs index c3ad1dac..e1949263 100644 --- a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs @@ -121,6 +121,7 @@ string BuildAgentInstallArguments(string valuesFilePath, bool hasRegistrySecret) $"-f \"{valuesFilePath}\"", hasRegistrySecret ? $"--set imagePullSecrets[0].name=\"{RegistrySecretName}\"" : null, $"--version \"{chartVersion}\"", + "--disable-openapi-validation", NamespaceFlag, KubeConfigFlag, AgentName, From 98c5083bb266b05e3141a6c5bf4a9d9f608c3a74 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 14:24:38 +1000 Subject: [PATCH 05/11] Add new install test for the helm chart --- .../HelmChartBuilder.cs | 2 +- .../RunsAgentInstall.cs | 73 +++++++++++++++++++ .../Common/FileSystemInfoExtensionMethods.cs | 8 ++ .../Setup/KubernetesAgentInstaller.cs | 7 +- 4 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 tests/kubernetes-agent/KubernetesAgent.IntegrationTests/RunsAgentInstall.cs diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/HelmChartBuilder.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/HelmChartBuilder.cs index 0e53dfdf..383ac3bf 100644 --- a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/HelmChartBuilder.cs +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/HelmChartBuilder.cs @@ -32,7 +32,7 @@ static string[] GetHelmChartPackageArguments(string version) ]; } - static DirectoryInfo GetChartsDirectory() + public static DirectoryInfo GetChartsDirectory() { var chartsDirectory = Path.Combine(AppContext.BaseDirectory); var currentDirectory = new DirectoryInfo(chartsDirectory); diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/RunsAgentInstall.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/RunsAgentInstall.cs new file mode 100644 index 00000000..7b69fd22 --- /dev/null +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/RunsAgentInstall.cs @@ -0,0 +1,73 @@ +using Halibut; +using KubernetesAgent.Integration.Setup; +using KubernetesAgent.Integration.Setup.Common; +using Octopus.Tentacle.Client; +using Octopus.Tentacle.Client.Scripts.Models; +using Octopus.Tentacle.Client.Scripts.Models.Builders; +using Xunit.Abstractions; + +namespace KubernetesAgent.Integration; + +public class HelmInstallTests(ITestOutputHelper output) : IAsyncLifetime +{ + readonly ITestOutputHelper output = output; + ILogger logger = null!; + readonly TemporaryDirectory workingDirectory = new(Directory.CreateTempSubdirectory()); + KubernetesClusterInstaller clusterInstaller = null!; + KubernetesAgentInstaller agentInstaller = null!; + TentacleClient client = null!; + string kindExePath = null!; + string helmExePath = null!; + string kubeCtlPath = null!; + + public async Task InitializeAsync() + { + logger = new LoggerConfiguration() + .MinimumLevel.Verbose() + .WriteTo.TestOutput(output) + .CreateLogger(); + + var requiredToolDownloader = new RequiredToolDownloader(workingDirectory, logger); + (kindExePath, helmExePath, kubeCtlPath) = await requiredToolDownloader.DownloadRequiredTools(CancellationToken.None); + clusterInstaller = new KubernetesClusterInstaller(workingDirectory, kindExePath, helmExePath, kubeCtlPath, logger); + await clusterInstaller.Install(); + } + + public async Task DisposeAsync() + { + clusterInstaller.Dispose(); + workingDirectory.Dispose(); + await Task.CompletedTask; + } + + [Fact] + public async Task CanInstallAgentAndRunCommand() + { + var chartDirectory = HelmChartBuilder.GetChartsDirectory(); + + agentInstaller = new KubernetesAgentInstaller(workingDirectory , helmExePath, kubeCtlPath, clusterInstaller.KubeConfigPath, logger, chartDirectory.FullName); + client = await agentInstaller.InstallAgent(); + + var testLogger = new TestLogger(logger); + + var runHelloWorldCommand = new ExecuteKubernetesScriptCommandBuilder(Guid.NewGuid().ToString()) + .WithScriptBody("echo \"hello world\"") + .Build(); + var result = await client.ExecuteScript(runHelloWorldCommand, OnScriptStatusResponseReceived, OnScriptCompleted, testLogger, CancellationToken.None); + if (result.ExitCode != 0) + { + throw new Exception($"Script failed with exit code {result.ExitCode}"); + } + + logger.Information("Script executed successfully"); + return; + + async Task OnScriptCompleted(CancellationToken t) + { + await Task.CompletedTask; + logger.Information("Script completed"); + } + + void OnScriptStatusResponseReceived(ScriptExecutionStatus res) => logger.Information("{Output}", res.ToString()); + } +} \ No newline at end of file diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Common/FileSystemInfoExtensionMethods.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Common/FileSystemInfoExtensionMethods.cs index 4f52a3ad..d7902dd5 100644 --- a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Common/FileSystemInfoExtensionMethods.cs +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Common/FileSystemInfoExtensionMethods.cs @@ -1,9 +1,17 @@ +using System.Runtime.InteropServices; + namespace KubernetesAgent.Integration.Setup.Common; public static class FileSystemInfoExtensionMethods { public static void MakeExecutable(this FileSystemInfo fsObject) { + //if we are on windows, we don't need to do this + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return; + } + var result = ProcessRunner.Run("chmod", "-R", "+x", fsObject.FullName); if (result.ExitCode != 0) { diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs index e1949263..3a80131d 100644 --- a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs @@ -23,19 +23,21 @@ public class KubernetesAgentInstaller readonly string kubeCtlExePath; readonly TemporaryDirectory temporaryDirectory; readonly ILogger logger; + readonly string? chartDirectoryName; readonly string kubeConfigPath; protected HalibutRuntime ServerHalibutRuntime { get; private set; } = null!; protected TentacleClient TentacleClient { get; private set; } = null!; bool isAgentInstalled; - public KubernetesAgentInstaller(TemporaryDirectory temporaryDirectory, string helmExePath, string kubeCtlExePath, string kubeConfigPath, ILogger logger) + public KubernetesAgentInstaller(TemporaryDirectory temporaryDirectory, string helmExePath, string kubeCtlExePath, string kubeConfigPath, ILogger logger, string? chartDirectoryName = null) { this.temporaryDirectory = temporaryDirectory; this.helmExePath = helmExePath; this.kubeCtlExePath = kubeCtlExePath; this.kubeConfigPath = kubeConfigPath; this.logger = logger; + this.chartDirectoryName = chartDirectoryName; AgentName = Guid.NewGuid().ToString("N"); } @@ -125,7 +127,8 @@ string BuildAgentInstallArguments(string valuesFilePath, bool hasRegistrySecret) NamespaceFlag, KubeConfigFlag, AgentName, - ArtifactoryAgentOciRepository + //Use the local directory if it exists, otherwise pull from artifactory + chartDirectoryName ?? ArtifactoryAgentOciRepository }; return string.Join(" ", args.WhereNotNull()); From 814decc286b1ce41957568c9295ef2b62c91a94c Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 16:09:13 +1000 Subject: [PATCH 06/11] Rework how we decide to include serviceName --- .vscode/settings.json | 5 ++ charts/kubernetes-agent/package.json | 4 +- .../templates/nfs-statefulset.yaml | 17 ++++--- .../tests/nfs-statefulset_test.yaml | 46 +++++++++++++++---- 4 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..1b6140dc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "yaml.schemas": { + "https://raw.githubusercontent.com/helm-unittest/helm-unittest/v0.5.1/schema/helm-testsuite.json": "file:///**/*_test.yaml" + } +} \ No newline at end of file diff --git a/charts/kubernetes-agent/package.json b/charts/kubernetes-agent/package.json index 0ee73ec2..fbf99a99 100644 --- a/charts/kubernetes-agent/package.json +++ b/charts/kubernetes-agent/package.json @@ -5,8 +5,8 @@ "description": "The Octopus Kubernetes Agent", "author": "Octopus Deploy Ptd Ltd", "scripts": { - "test": "cross-env-shell docker run -ti --rm -v $INIT_CWD:/apps helmunittest/helm-unittest:latest .", - "update-test-snapshots": "cross-env-shell docker run -ti --rm -v $INIT_CWD:/apps helmunittest/helm-unittest:latest . -u", + "test": "cross-env-shell docker run -ti --rm -v $INIT_CWD:/apps helmunittest/helm-unittest:3.15.2-0.5.1 .", + "update-test-snapshots": "cross-env-shell docker run -ti --rm -v $INIT_CWD:/apps helmunittest/helm-unittest:3.15.2-0.5.1 . -u", "generate-agent-docs": "docker run --rm --volume \".:/helm-docs\" jnorwood/helm-docs:latest" }, "dependencies": { diff --git a/charts/kubernetes-agent/templates/nfs-statefulset.yaml b/charts/kubernetes-agent/templates/nfs-statefulset.yaml index 757c1351..aea723a2 100644 --- a/charts/kubernetes-agent/templates/nfs-statefulset.yaml +++ b/charts/kubernetes-agent/templates/nfs-statefulset.yaml @@ -2,17 +2,22 @@ apiVersion: apps/v1 kind: StatefulSet metadata: - name: {{ include "nfs.name" .}} + name: {{ include "nfs.name" . }} namespace: {{ .Release.Namespace | quote }} labels: - app.kubernetes.io/name: {{ include "nfs.name" .}} + app.kubernetes.io/name: {{ include "nfs.name" . }} spec: selector: matchLabels: - app.kubernetes.io/name: {{ include "nfs.name" .}} - {{- if .Release.IsInstall }} - serviceName: {{ include "nfs.name" .}} - {{- end }} + app.kubernetes.io/name: {{ include "nfs.name" . }} + {{- $ss := (lookup "apps/v1" "StatefulSet" .Release.Namespace (include "nfs.name" .)) }} + {{- if not $ss }} + {{/* If the stateful set doesn't exist */}} + serviceName: {{ include "nfs.name" . }} + {{- else if (index $ss "spec.serviceName" ) }} + {{/* Or it does exist and it already has a non-empty serviceName */}} + serviceName: {{ include "nfs.name" . }} + {{- end }} template: metadata: {{- with .Values.persistence.nfs.metadata.annotations }} diff --git a/charts/kubernetes-agent/tests/nfs-statefulset_test.yaml b/charts/kubernetes-agent/tests/nfs-statefulset_test.yaml index 9481bc13..a3507d58 100644 --- a/charts/kubernetes-agent/tests/nfs-statefulset_test.yaml +++ b/charts/kubernetes-agent/tests/nfs-statefulset_test.yaml @@ -1,6 +1,27 @@ suite: "persistence" templates: -- templates/nfs-statefulset.yaml + - templates/nfs-statefulset.yaml +kubernetesProvider: + scheme: + "apps/v1/StatefulSet": + gvr: + group: "apps" + version: "v1" + resource: "statefulsets" + namespaced: true + objects: + - kind: StatefulSet + apiVersion: "apps/v1" + metadata: + name: "empty-serviceName-nfs" + namespace: "NAMESPACE" + - kind: StatefulSet + apiVersion: "apps/v1" + metadata: + name: "populated-serviceName-nfs" + namespace: "NAMESPACE" + spec: + serviceName: "populated-serviceName-nfs" tests: - it: "is not created when storageClassName has a value" set: @@ -23,17 +44,26 @@ tests: path: spec.template.spec.volumes[?(@.name == 'octopus-volume')].emptyDir.sizeLimit value: 100Gi -- it: does not set serviceName if Release.IsInstall is false - release: - upgrade: true +- it: does not set serviceName if the StatefulSet exists and has an empty serviceName + set: + nameOverride: "empty-serviceName" asserts: + - equal: + path: metadata.name + value: "empty-serviceName-nfs" - notExists: path: spec.serviceName -- it: sets serviceName if Release.IsInstall is true - release: - upgrade: false +- it: sets serviceName if the StatefulSet doesn't exist + asserts: + - equal: + path: spec.serviceName + value: octopus-agent-nfs + +- it: sets serviceName if the StatefulSet exists and is set to same service name + set: + nameOverride: "populated-ServiceName" asserts: - equal: path: spec.serviceName - value: octopus-agent-nfs \ No newline at end of file + value: populated-ServiceName-nfs \ No newline at end of file From 3c47934968f09bbd404cd8b999fa1e595d41b7f5 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 16:15:17 +1000 Subject: [PATCH 07/11] Set helm version to 3.15.3 --- .../Setup/Tooling/HelmDownloader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs index d5c14c26..19b3047e 100644 --- a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/Tooling/HelmDownloader.cs @@ -6,7 +6,7 @@ namespace KubernetesAgent.Integration.Setup.Tooling; public class HelmDownloader : ToolDownloader { - const string LatestVersion = "v3.8.0"; + const string LatestVersion = "v3.15.3"; public HelmDownloader( ILogger logger) : base("helm", logger) { From c89bf748561689e6e99c22270ea674ee55516c54 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 16:16:54 +1000 Subject: [PATCH 08/11] Remove disable-openapi-validation --- .../Setup/KubernetesAgentInstaller.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs index 3a80131d..45d79d45 100644 --- a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesAgentInstaller.cs @@ -123,7 +123,6 @@ string BuildAgentInstallArguments(string valuesFilePath, bool hasRegistrySecret) $"-f \"{valuesFilePath}\"", hasRegistrySecret ? $"--set imagePullSecrets[0].name=\"{RegistrySecretName}\"" : null, $"--version \"{chartVersion}\"", - "--disable-openapi-validation", NamespaceFlag, KubeConfigFlag, AgentName, From ef4ad109834ccf321cdafae6cae56487033d81d0 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 16:21:19 +1000 Subject: [PATCH 09/11] Fix random indenting --- charts/kubernetes-agent/templates/tentacle-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/kubernetes-agent/templates/tentacle-deployment.yaml b/charts/kubernetes-agent/templates/tentacle-deployment.yaml index dfc7e394..d70f5005 100644 --- a/charts/kubernetes-agent/templates/tentacle-deployment.yaml +++ b/charts/kubernetes-agent/templates/tentacle-deployment.yaml @@ -18,7 +18,7 @@ spec: {{- end }} labels: {{- include "kubernetes-agent.labels" . | nindent 8 }} - {{- with .Values.agent.metadata.labels }} + {{- with .Values.agent.metadata.labels }} {{- toYaml . | nindent 8 }} {{- end }} spec: From 967264a277403bf0378eae1942a2542cd8e799b1 Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 16:32:56 +1000 Subject: [PATCH 10/11] Make k8s cluster name unique --- .../Setup/KubernetesClusterInstaller.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesClusterInstaller.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesClusterInstaller.cs index c982c970..e79ad238 100644 --- a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesClusterInstaller.cs +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesClusterInstaller.cs @@ -25,7 +25,7 @@ public KubernetesClusterInstaller(TemporaryDirectory tempDirectory, string kindE this.kubeCtlPath = kubeCtlPath; this.logger = logger; - clusterName = $"helm-octopus-agent-int-{DateTime.Now:yyyyMMddhhmmss}"; + clusterName = $"octo-test-{Guid.NewGuid():N}-{DateTime.Now:yyyyMMddhhmmss}"; kubeConfigName = $"{clusterName}.config"; } From 2f9fc574624f093dba0764fd4b3c05ab955242bb Mon Sep 17 00:00:00 2001 From: Alastair Pitts Date: Fri, 12 Jul 2024 16:38:51 +1000 Subject: [PATCH 11/11] More uniquey --- .../Setup/KubernetesClusterInstaller.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesClusterInstaller.cs b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesClusterInstaller.cs index e79ad238..3b716f10 100644 --- a/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesClusterInstaller.cs +++ b/tests/kubernetes-agent/KubernetesAgent.IntegrationTests/Setup/KubernetesClusterInstaller.cs @@ -6,6 +6,7 @@ namespace KubernetesAgent.Integration.Setup; public class KubernetesClusterInstaller : IDisposable { + static int clusterCount = 0; readonly string clusterName; readonly string kubeConfigName; @@ -25,7 +26,9 @@ public KubernetesClusterInstaller(TemporaryDirectory tempDirectory, string kindE this.kubeCtlPath = kubeCtlPath; this.logger = logger; - clusterName = $"octo-test-{Guid.NewGuid():N}-{DateTime.Now:yyyyMMddhhmmss}"; + //hack to get a unique time for multiple clusters + var count = Interlocked.Increment(ref clusterCount); + clusterName = $"octo-test-{DateTime.Now.AddSeconds(count):yyyyMMddhhmmss}"; kubeConfigName = $"{clusterName}.config"; }