Skip to content
Draft
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
2 changes: 2 additions & 0 deletions source/Octopus.Tentacle/Kubernetes/KubernetesConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public static class KubernetesConfig
const string ServerCommsAddressVariableName = "ServerCommsAddress";
const string EnvVarPrefix = "OCTOPUS__K8STENTACLE";

public static string KubeContextVariableName = $"{EnvVarPrefix}__KUBECONTEXT";

public static string NamespaceVariableName => $"{EnvVarPrefix}__NAMESPACE";
public static string Namespace => GetRequiredEnvVar(NamespaceVariableName, "Unable to determine Kubernetes namespace.");
public static string PodServiceAccountName => GetRequiredEnvVar($"{EnvVarPrefix}__PODSERVICEACCOUNTNAME", "Unable to determine Kubernetes Pod service account name.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IKubernetesConfigMapService
Task<V1ConfigMap?> TryGet(string name, CancellationToken cancellationToken);

Task<V1ConfigMap> Patch(string name, IDictionary<string, string> data, CancellationToken cancellationToken);
Task<V1ConfigMap> Create(string name,IDictionary<string, byte[]> data, CancellationToken cancellationToken);
}

public class KubernetesConfigMapService : KubernetesService, IKubernetesConfigMapService
Expand Down Expand Up @@ -51,5 +52,8 @@ public async Task<V1ConfigMap> Patch(string name, IDictionary<string, string> da
return await RetryPolicy.ExecuteAsync(async () =>
await Client.CoreV1.PatchNamespacedConfigMapAsync(new V1Patch(configMapJson, V1Patch.PatchType.MergePatch), name, KubernetesConfig.Namespace, cancellationToken: cancellationToken));
}

public async Task<V1ConfigMap> Create(string name, IDictionary<string, byte[]> data, CancellationToken cancellationToken) =>
await RetryPolicy.ExecuteAsync(async () => await Client.CoreV1.CreateNamespacedConfigMapAsync(new V1ConfigMap(metadata: new V1ObjectMeta(){ Name = name }, binaryData: data), KubernetesConfig.Namespace, cancellationToken: cancellationToken));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public override void EnsureDiskHasEnoughFreeSpace(string directoryPath, long req

public (ulong freeSpaceBytes, ulong totalSpaceBytes)? GetStorageInformation()
{
if(Environment.GetEnvironmentVariable("OCTOPUS__SKIP_DISK_SPACE_CHECK") == "true") return null;

var bytesUsed = directoryInformationProvider.GetPathUsedBytes(HomeDir);
var bytesTotal = directoryInformationProvider.GetPathTotalBytes();
if (bytesUsed.HasValue && bytesTotal.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Octopus.Tentacle.Core.Diagnostics;
using Octopus.Tentacle.Core.Services.Scripts.Locking;
using Octopus.Tentacle.Kubernetes.Crypto;
using Octopus.Tentacle.Scripts;

namespace Octopus.Tentacle.Kubernetes
{
Expand All @@ -24,6 +25,7 @@ public KubernetesRawScriptPodCreator(
IKubernetesPodService podService,
IKubernetesPodMonitor podMonitor,
IKubernetesSecretService secretService,
IKubernetesConfigMapService configMapService,
IKubernetesPodTemplateService podTemplateService,
IKubernetesPodContainerResolver containerResolver,
IApplicationInstanceSelector appInstanceSelector,
Expand All @@ -33,7 +35,7 @@ public KubernetesRawScriptPodCreator(
KubernetesPhysicalFileSystem kubernetesPhysicalFileSystem,
IScriptPodLogEncryptionKeyProvider scriptPodLogEncryptionKeyProvider,
ScriptIsolationMutex scriptIsolationMutex)
: base(podService, podMonitor, secretService, podTemplateService, containerResolver, appInstanceSelector, log, scriptLogProvider, homeConfiguration, kubernetesPhysicalFileSystem, scriptPodLogEncryptionKeyProvider, scriptIsolationMutex)
: base(podService, podMonitor, secretService, configMapService, podTemplateService, containerResolver, appInstanceSelector, log, scriptLogProvider, homeConfiguration, kubernetesPhysicalFileSystem, scriptPodLogEncryptionKeyProvider, scriptIsolationMutex)
{
this.containerResolver = containerResolver;
}
Expand All @@ -50,16 +52,16 @@ protected override async Task<IList<V1Container>> CreateInitContainers(StartKube
container.Image = command.PodImageConfiguration?.Image ?? await containerResolver.GetContainerImageForCluster();
container.ImagePullPolicy = KubernetesConfig.ScriptPodPullPolicy;
container.Command = new List<string> { "sh", "-c", GetInitExecutionScript("/nfs-mount", homeDir, workspacePath) };
container.VolumeMounts = Merge(container.VolumeMounts, new[] { new V1VolumeMount("/nfs-mount", "init-nfs-volume"), new V1VolumeMount(homeDir, "tentacle-home") });
//container.VolumeMounts = Merge(container.VolumeMounts, new[] { new V1VolumeMount("/nfs-mount", "init-nfs-volume"), new V1VolumeMount(homeDir, "tentacle-home") });

return new List<V1Container> { container };
}

protected override async Task<IList<V1Container>> CreateScriptContainers(StartKubernetesScriptCommandV1 command, string podName, string scriptName, string homeDir, string workspacePath, string[]? scriptArguments, InMemoryTentacleScriptLog tentacleScriptLog, ScriptPodTemplate? template)
protected override async Task<IList<V1Container>> CreateScriptContainers(StartKubernetesScriptCommandV1 command, string podName, string scriptName, string homeDir, string workspacePath, string[]? scriptArguments, InMemoryTentacleScriptLog tentacleScriptLog, ScriptPodTemplate? template, IScriptWorkspace workspace)
{
return new List<V1Container>
{
await CreateScriptContainer(command, podName, scriptName, homeDir, workspacePath, scriptArguments, tentacleScriptLog, template?.ScriptContainerSpec)
await CreateScriptContainer(command, podName, scriptName, homeDir, workspacePath, scriptArguments, tentacleScriptLog, template?.ScriptContainerSpec, workspace)
};
}

Expand All @@ -69,15 +71,21 @@ protected override IList<V1Volume> CreateVolumes(StartKubernetesScriptCommandV1
{
new()
{
Name = "tentacle-home",
Name = "workspace",
EmptyDir = new V1EmptyDirVolumeSource()
},
new()
new V1Volume
{
Name = "init-nfs-volume",
PersistentVolumeClaim = new V1PersistentVolumeClaimVolumeSource
{
ClaimName = KubernetesConfig.PodVolumeClaimName
Name = "calamari",
EmptyDir = new V1EmptyDirVolumeSource()
},

new () {
Name = "bootstrap-runner",
Image =
new() {
Reference = "octopusdeploy/kubernetes-agent-tentacle:8.3.3359",
PullPolicy = "IfNotPresent"
}
},
CreateAgentUpgradeSecretVolume(),
Expand Down
Loading