Upgrades volume support for use with deploy-and-run container
This commit is contained in:
parent
b5e5570145
commit
ac07327d77
|
@ -112,17 +112,21 @@
|
||||||
|
|
||||||
public class VolumeMount
|
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;
|
VolumeName = volumeName;
|
||||||
MountPath = mountPath;
|
MountPath = mountPath;
|
||||||
SubPath = subPath;
|
SubPath = subPath;
|
||||||
ResourceQuantity = resourceQuantity;
|
ResourceQuantity = resourceQuantity;
|
||||||
|
Secret = secret;
|
||||||
|
HostPath = hostPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string VolumeName { get; }
|
public string VolumeName { get; }
|
||||||
public string MountPath { get; }
|
public string MountPath { get; }
|
||||||
public string? SubPath { get; }
|
public string? SubPath { get; }
|
||||||
public string? ResourceQuantity { get; }
|
public string? ResourceQuantity { get; }
|
||||||
|
public string? Secret { get; }
|
||||||
|
public string? HostPath { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,9 +97,10 @@ namespace KubernetesWorkflow
|
||||||
podAnnotations.Add(name, value);
|
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)
|
protected void AddVolume(string mountPath, ByteSize volumeSize)
|
||||||
|
|
|
@ -458,32 +458,45 @@ namespace KubernetesWorkflow
|
||||||
|
|
||||||
private V1Volume CreateVolume(VolumeMount v)
|
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
|
client.Run(c => c.CreateNamespacedPersistentVolumeClaim(new V1PersistentVolumeClaim
|
||||||
{
|
{
|
||||||
ApiVersion = "v1",
|
ApiVersion = "v1",
|
||||||
Metadata = new V1ObjectMeta
|
Metadata = new V1ObjectMeta
|
||||||
{
|
{
|
||||||
Name = v.VolumeName
|
Name = v.VolumeName,
|
||||||
},
|
},
|
||||||
Spec = new V1PersistentVolumeClaimSpec
|
Spec = new V1PersistentVolumeClaimSpec
|
||||||
{
|
{
|
||||||
|
|
||||||
AccessModes = new List<string>
|
AccessModes = new List<string>
|
||||||
{
|
{
|
||||||
"ReadWriteOnce"
|
"ReadWriteOnce"
|
||||||
},
|
},
|
||||||
Resources = new V1ResourceRequirements
|
Resources = CreateVolumeResourceRequirements(v),
|
||||||
{
|
},
|
||||||
Requests = resourcesRequests
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, K8sNamespace));
|
}, 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
|
return new V1Volume
|
||||||
{
|
{
|
||||||
Name = v.VolumeName,
|
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)
|
private List<V1EnvVar> CreateEnv(ContainerRecipe recipe)
|
||||||
{
|
{
|
||||||
return recipe.EnvVars.Select(CreateEnvVar).ToList();
|
return recipe.EnvVars.Select(CreateEnvVar).ToList();
|
||||||
|
|
|
@ -21,7 +21,11 @@ namespace DeployAndRunPlugin
|
||||||
AddEnvVar("DNR_FILTER", setup.Filter);
|
AddEnvVar("DNR_FILTER", setup.Filter);
|
||||||
AddEnvVar("DNR_DURATION", setup.Duration.TotalSeconds.ToString());
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,8 @@ namespace DeployAndRunPlugin
|
||||||
startupConfig.NameOverride = "dnr-" + config.Name;
|
startupConfig.NameOverride = "dnr-" + config.Name;
|
||||||
startupConfig.Add(config);
|
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();
|
return containers.Containers.Single();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class Program
|
||||||
}
|
}
|
||||||
var specs = JsonConvert.DeserializeObject<ClusterTestSetup>(File.ReadAllText(SpecsFile))!;
|
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 entryPoint = new EntryPoint(new ConsoleLog(), kConfig, "datafolder");
|
||||||
var ci = entryPoint.CreateInterface();
|
var ci = entryPoint.CreateInterface();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue