Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.argoproj.workflow.models.IoArgoprojWorkflowV1alpha1Template
import io.argoproj.workflow.models.IoArgoprojWorkflowV1alpha1Workflow
import io.argoproj.workflow.models.IoArgoprojWorkflowV1alpha1WorkflowSpec
import io.kubernetes.client.custom.Quantity
import io.kubernetes.client.openapi.models.V1ConfigMapVolumeSource
import io.kubernetes.client.openapi.models.V1Container
import io.kubernetes.client.openapi.models.V1EnvFromSource
import io.kubernetes.client.openapi.models.V1EnvVar
Expand All @@ -38,11 +39,15 @@ import io.kubernetes.client.openapi.models.V1VolumeResourceRequirements
private const val CSM_DAG_ENTRYPOINT = "entrypoint"
private const val CSM_DEFAULT_WORKFLOW_NAME = "default-workflow-"
internal const val VOLUME_SECRET_NAME = "secrets"
internal const val VOLUME_CLAIM_COAL = "coal-config"
internal const val VOLUME_CLAIM = "datadir"
internal const val VOLUME_CLAIM_DATASETS_SUBPATH = "datasetsdir"
internal const val VOLUME_CLAIM_PARAMETERS_SUBPATH = "parametersdir"
internal const val VOLUME_CLAIM_OUTPUT_SUBPATH = "outputdir"
internal const val VOLUME_CLAIM_TEMP_SUBPATH = "tempdir"
internal const val VOLUME_COAL_PATH = "/mnt/coal"
internal const val VOLUME_COAL_FILE_NAME = "coal-config.toml"

private const val VOLUME_DATASETS_PATH = "/mnt/scenariorun-data"
private const val VOLUME_PARAMETERS_PATH = "/mnt/scenariorun-parameters"
private const val VOLUME_OUTPUT_PATH = "/pkg/share/Simulation/Output"
Expand All @@ -51,6 +56,7 @@ private const val VOLUME_TEMP_PATH = "/usr/tmp"
internal const val CSM_ARGO_WORKFLOWS_TIMEOUT = 28800
internal const val ALWAYS_PULL_POLICY = "Always"

@Suppress("LongMethod")
internal fun buildTemplate(
organizationId: String,
workspaceId: String?,
Expand All @@ -67,6 +73,13 @@ internal fun buildTemplate(
}
}

val configMapMount =
listOf(
V1VolumeMount()
.name(VOLUME_CLAIM_COAL)
.mountPath(VOLUME_COAL_PATH + "/" + VOLUME_COAL_FILE_NAME)
.subPath(VOLUME_COAL_FILE_NAME)
)
val secretVolumeMount =
csmPlatformProperties.argo.workflows.secrets.map { secret ->
V1VolumeMount().name(secret.name).mountPath(VOLUME_SECRETS_PATH + "/" + secret.name)
Expand All @@ -90,14 +103,11 @@ internal fun buildTemplate(
.mountPath(VOLUME_TEMP_PATH)
.subPath(VOLUME_CLAIM_TEMP_SUBPATH),
)

val volumeMounts = normalVolumeMount + secretVolumeMount
val volumeMounts = normalVolumeMount + secretVolumeMount + configMapMount

val sizingInfo = runContainer.runSizing ?: BASIC_SIZING.toContainerResourceSizing()

val imagePullPolicy =
if (alwaysPull) ALWAYS_PULL_POLICY else csmPlatformProperties.argo.imagePullPolicy

val container =
buildContainer(
runContainer,
Expand All @@ -108,7 +118,6 @@ internal fun buildTemplate(
organizationId,
workspaceId,
)

if (runContainer.entrypoint != null) {
container.command(listOf(runContainer.entrypoint))
}
Expand All @@ -118,7 +127,6 @@ internal fun buildTemplate(
.name(runContainer.name.lowercase())
.metadata(IoArgoprojWorkflowV1alpha1Metadata().labels(runContainer.labels))
.container(container)

if (csmPlatformProperties.argo.workflows.ignoreNodeSelector == false) {
template = template.nodeSelector(runContainer.getNodeLabelSize())
}
Expand Down Expand Up @@ -163,6 +171,7 @@ private fun buildContainer(
)
}

@Suppress("LongMethod")
internal fun buildWorkflowSpec(
organizationId: String,
workspaceId: String?,
Expand Down Expand Up @@ -193,6 +202,18 @@ internal fun buildWorkflowSpec(
.entrypoint(CSM_DAG_ENTRYPOINT)
.templates(templates)
.volumeClaimTemplates(buildVolumeClaims(csmPlatformProperties))
.addVolumesItem(
V1Volume()
.name(VOLUME_CLAIM_COAL)
.configMap(
V1ConfigMapVolumeSource()
.optional(true)
.name("${organizationId}-${workspaceId}-coal-config")
.addItemsItem(
V1KeyToPath().key(VOLUME_COAL_FILE_NAME).path(VOLUME_COAL_FILE_NAME)
)
)
)

if (csmPlatformProperties.argo.workflows.secrets.isNotEmpty()) {
val argoSecrets = csmPlatformProperties.argo.workflows.secrets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ class WorkflowBuildersTests {
.name(VOLUME_CLAIM)
.mountPath("/usr/tmp")
.subPath(VOLUME_CLAIM_TEMP_SUBPATH),
V1VolumeMount()
.name(VOLUME_CLAIM_COAL)
.mountPath(VOLUME_COAL_PATH + "/" + VOLUME_COAL_FILE_NAME)
.subPath(VOLUME_COAL_FILE_NAME),
)
assertEquals(expected, template.container?.volumeMounts)
}
Expand Down