Skip to content

Commit

Permalink
🚧 Make workflows resources configurable (#8)
Browse files Browse the repository at this point in the history
- volume size, memory request/limit, cpu request/limit
- Close kintoproj/kinto-core#17
  • Loading branch information
bakayolo authored Mar 2, 2021
1 parent 16627a4 commit 26aa240
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 26 deletions.
5 changes: 4 additions & 1 deletion kinto-build/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ ARGO_WORKFLOW_CLI_IMAGE=kintohub/kinto-workflow-cli:latest
# Argo workflow use an `emptyDir` ephemeral storage. Be careful setting up this limit since it's gonna use the node volume.
ARGO_WORKFLOW_VOLUME_SIZE=1Gi

# Resources limit for the main step
# Resources for the main step
ARGO_WORKFLOW_MEMORY_LIMIT=2Gi # must be > 2Gi
ARGO_WORKFLOW_CPU_LIMIT=1 # must be > 500m
ARGO_WORKFLOW_MEMORY_REQUEST=
ARGO_WORKFLOW_CPU_REQUEST=

25 changes: 15 additions & 10 deletions kinto-build/internal/build/argo/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ func submitWorkflow(
exitHandlerNeeded bool,
templates []v1alpha1.Template) (string, *utilsGoServer.Error) {

volumeSize := resource.MustParse(config.ArgoWorkflowVolumeSize)

workflowObject := &v1alpha1.Workflow{
ObjectMeta: v1.ObjectMeta{
GenerateName: name,
Expand Down Expand Up @@ -108,14 +106,6 @@ func submitWorkflow(
},
},
},
{
Name: workflowVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
SizeLimit: &volumeSize,
},
},
},
},
ServiceAccountName: config.ArgoWorkflowServiceAccount,
NodeSelector: nil,
Expand All @@ -127,6 +117,21 @@ func submitWorkflow(
},
}

if config.ArgoWorkflowVolumeSize != "" {
volumeSize := resource.MustParse(config.ArgoWorkflowVolumeSize)

workflowObject.Spec.Volumes = append(
workflowObject.Spec.Volumes,
corev1.Volume{
Name: workflowVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
SizeLimit: &volumeSize,
},
},
})
}

if exitHandlerNeeded {
workflowObject.Spec.OnExit = workflowOnExit
}
Expand Down
43 changes: 31 additions & 12 deletions kinto-build/internal/build/argo/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,41 @@ func genMainWorkflowTemplate() v1alpha1.Template {
MountPath: "/kaniko/.docker",
},
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("500m"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
corev1.ResourceEphemeralStorage: resource.MustParse(config.ArgoWorkflowVolumeSize),
},
Limits: corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse(config.ArgoWorkflowCPULimit),
corev1.ResourceMemory: resource.MustParse(config.ArgoWorkflowMemoryLimit),
corev1.ResourceEphemeralStorage: resource.MustParse(config.ArgoWorkflowVolumeSize),
},
},
Resources: genWorkflowResource(),
},
}
}

func genWorkflowResource() corev1.ResourceRequirements {
resources := corev1.ResourceRequirements{
Requests: corev1.ResourceList{},
Limits: corev1.ResourceList{},
}

if config.ArgoWorkflowVolumeSize != "" {
resources.Requests[corev1.ResourceEphemeralStorage] = resource.MustParse(config.ArgoWorkflowVolumeSize)
resources.Limits[corev1.ResourceEphemeralStorage] = resource.MustParse(config.ArgoWorkflowVolumeSize)
}

if config.ArgoWorkflowMemoryRequest != "" {
resources.Requests[corev1.ResourceMemory] = resource.MustParse(config.ArgoWorkflowMemoryRequest)
}

if config.ArgoWorkflowCPURequest != "" {
resources.Requests[corev1.ResourceCPU] = resource.MustParse(config.ArgoWorkflowCPURequest)
}

if config.ArgoWorkflowMemoryLimit != "" {
resources.Limits[corev1.ResourceMemory] = resource.MustParse(config.ArgoWorkflowMemoryLimit)
}

if config.ArgoWorkflowCPULimit != "" {
resources.Limits[corev1.ResourceCPU] = resource.MustParse(config.ArgoWorkflowCPULimit)
}

return resources
}

func genBuildAndDeployWorkflow(
envId, blockName, releaseId, kintoCoreHost string,
buildConfig *types.BuildConfig,
Expand Down
10 changes: 7 additions & 3 deletions kinto-build/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var (
ArgoWorkflowVolumeSize string
ArgoWorkflowMemoryLimit string
ArgoWorkflowCPULimit string
ArgoWorkflowMemoryRequest string
ArgoWorkflowCPURequest string
)

func LoadConfig() {
Expand Down Expand Up @@ -67,7 +69,9 @@ func LoadConfig() {
ArgoWorkflowImagePullPolicy = config.GetString("ARGO_WORKFLOW_IMAGE_PULL_POLICY", "IfNotPresent")
ArgoWorkflowMainImage = config.GetStringOrDie("ARGO_WORKFLOW_MAIN_IMAGE")
ArgoWorkflowCliImage = config.GetStringOrDie("ARGO_WORKFLOW_CLI_IMAGE")
ArgoWorkflowVolumeSize = config.GetString("ARGO_WORKFLOW_VOLUME_SIZE", "1Gi")
ArgoWorkflowMemoryLimit = config.GetString("ARGO_WORKFLOW_MEMORY_LIMIT", "2Gi")
ArgoWorkflowCPULimit = config.GetString("ARGO_WORKFLOW_CPU_LIMIT", "1")
ArgoWorkflowVolumeSize = config.GetString("ARGO_WORKFLOW_VOLUME_SIZE", "")
ArgoWorkflowMemoryLimit = config.GetString("ARGO_WORKFLOW_MEMORY_LIMIT", "")
ArgoWorkflowCPULimit = config.GetString("ARGO_WORKFLOW_CPU_LIMIT", "")
ArgoWorkflowMemoryRequest = config.GetString("ARGO_WORKFLOW_MEMORY_REQUEST", "")
ArgoWorkflowCPURequest = config.GetString("ARGO_WORKFLOW_CPU_REQUEST", "")
}

0 comments on commit 26aa240

Please sign in to comment.