Upgrades volume support for use with deploy-and-run container

This commit is contained in:
benbierens 2023-10-31 14:20:50 +01:00
parent b5e5570145
commit ac07327d77
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
6 changed files with 62 additions and 18 deletions

View File

@ -112,17 +112,21 @@
public class VolumeMount
{
public VolumeMount(string volumeName, string mountPath, string? subPath = null, string? resourceQuantity = null)
public VolumeMount(string volumeName, string mountPath, string? subPath = null, string? resourceQuantity = null, string? secret = null, string? hostPath = null)
{
VolumeName = volumeName;
MountPath = mountPath;
SubPath = subPath;
ResourceQuantity = resourceQuantity;
Secret = secret;
HostPath = hostPath;
}
public string VolumeName { get; }
public string MountPath { get; }
public string? SubPath { get; }
public string? ResourceQuantity { get; }
public string? Secret { get; }
public string? HostPath { get; }
}
}

View File

@ -97,9 +97,10 @@ namespace KubernetesWorkflow
podAnnotations.Add(name, value);
}
protected void AddVolume(string name, string mountPath, string subPath)
protected void AddVolume(string name, string mountPath, string? subPath = null, string? secret = null, string? hostPath = null)
{
volumeMounts.Add(new VolumeMount(name, mountPath, subPath));
var size = 10.MB().ToSuffixNotation();
volumeMounts.Add(new VolumeMount(name, mountPath, subPath, size, secret, hostPath));
}
protected void AddVolume(string mountPath, ByteSize volumeSize)

View File

@ -458,32 +458,45 @@ namespace KubernetesWorkflow
private V1Volume CreateVolume(VolumeMount v)
{
var resourcesRequests = new Dictionary<string, ResourceQuantity>();
if (v.ResourceQuantity != null)
{
resourcesRequests.Add("storage", new ResourceQuantity(v.ResourceQuantity));
}
client.Run(c => c.CreateNamespacedPersistentVolumeClaim(new V1PersistentVolumeClaim
{
ApiVersion = "v1",
Metadata = new V1ObjectMeta
{
Name = v.VolumeName
Name = v.VolumeName,
},
Spec = new V1PersistentVolumeClaimSpec
{
AccessModes = new List<string>
{
"ReadWriteOnce"
},
Resources = new V1ResourceRequirements
{
Requests = resourcesRequests
}
}
Resources = CreateVolumeResourceRequirements(v),
},
}, K8sNamespace));
if (!string.IsNullOrEmpty(v.HostPath))
{
return new V1Volume
{
Name = v.VolumeName,
HostPath = new V1HostPathVolumeSource
{
Path = v.HostPath
}
};
}
if (!string.IsNullOrEmpty(v.Secret))
{
return new V1Volume
{
Name = v.VolumeName,
Secret = CreateVolumeSecret(v)
};
}
return new V1Volume
{
Name = v.VolumeName,
@ -494,6 +507,27 @@ namespace KubernetesWorkflow
};
}
private V1SecretVolumeSource CreateVolumeSecret(VolumeMount v)
{
if (string.IsNullOrWhiteSpace(v.Secret)) return null!;
return new V1SecretVolumeSource
{
SecretName = v.Secret
};
}
private V1ResourceRequirements CreateVolumeResourceRequirements(VolumeMount v)
{
if (v.ResourceQuantity == null) return null!;
return new V1ResourceRequirements
{
Requests = new Dictionary<string, ResourceQuantity>()
{
{"storage", new ResourceQuantity(v.ResourceQuantity) }
}
};
}
private List<V1EnvVar> CreateEnv(ContainerRecipe recipe)
{
return recipe.EnvVars.Select(CreateEnvVar).ToList();

View File

@ -21,7 +21,11 @@ namespace DeployAndRunPlugin
AddEnvVar("DNR_FILTER", setup.Filter);
AddEnvVar("DNR_DURATION", setup.Duration.TotalSeconds.ToString());
AddVolume(name: "kubeconfig", mountPath: "/opt/kubeconfig.yaml", subPath: "kubeconfig.yaml");
AddEnvVar("KUBECONFIG", "/opt/kubeconfig.yaml");
AddEnvVar("LOGPATH", "/var/log/codex-continuous-tests");
AddVolume(name: "kubeconfig", mountPath: "/opt/kubeconfig.yaml", subPath: "kubeconfig.yaml", secret: "codex-dist-tests-app-kubeconfig");
AddVolume(name: "logs", mountPath: "/var/log/codex-continuous-tests", hostPath: "/var/log/codex-continuous-tests");
}
}

View File

@ -28,7 +28,8 @@ namespace DeployAndRunPlugin
startupConfig.NameOverride = "dnr-" + config.Name;
startupConfig.Add(config);
var containers = workflow.Start(1, new DeployAndRunContainerRecipe(), startupConfig);
var location = workflow.GetAvailableLocations().Get("fixed-s-4vcpu-16gb-amd-yz8rd");
var containers = workflow.Start(1, location, new DeployAndRunContainerRecipe(), startupConfig);
return containers.Containers.Single();
}
}

View File

@ -27,7 +27,7 @@ public class Program
}
var specs = JsonConvert.DeserializeObject<ClusterTestSetup>(File.ReadAllText(SpecsFile))!;
var kConfig = new KubernetesWorkflow.Configuration(config.KubeConfigFile, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10), "codex-continuous-test-runners");
var kConfig = new KubernetesWorkflow.Configuration(config.KubeConfigFile, TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(10), kubernetesNamespace: "default");
var entryPoint = new EntryPoint(new ConsoleLog(), kConfig, "datafolder");
var ci = entryPoint.CreateInterface();