From 9904bcebb598f3c39e61992a7da38fbbbb4bd493 Mon Sep 17 00:00:00 2001 From: Gavin Chappell Date: Mon, 6 Sep 2021 10:44:57 +0100 Subject: [PATCH] add optional resource limits to Machinaris Chart on `test` track (#137) * add optional resource limits to Machinaris Chart on `test` track * removed question mark * regex validation of values * Memory validation comes straight from `k3s-io/k3s` in `vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go` * CPU validation is home-grown and allows both the fractional representation as well as the "millicore" representation, but because the minimum precision is `1m`, fractions and millicores cannot be used together ([read more](https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu)) * any string containing a period MUST NOT end with an `m` as this must be a fractional representation * otherwise any string containing only digits MAY end with an `m` (to represent a number of millicores) or not (to represent one or more entire cores) --- test/machinaris/{1.0.5 => 1.0.6}/.helmignore | 0 test/machinaris/{1.0.5 => 1.0.6}/Chart.yaml | 2 +- test/machinaris/{1.0.5 => 1.0.6}/README.md | 0 .../machinaris/{1.0.5 => 1.0.6}/app-readme.md | 0 .../charts/common-2105.0.0.tgz | Bin .../{1.0.5 => 1.0.6}/ix_values.yaml | 0 .../{1.0.5 => 1.0.6}/questions.yaml | 21 ++++++++++++++++++ .../{1.0.5 => 1.0.6}/requirements.lock | 0 .../templates/deployment.yaml | 6 +++++ .../{1.0.5 => 1.0.6}/templates/service.yaml | 0 .../{1.0.5 => 1.0.6}/test_values.yaml | 0 11 files changed, 28 insertions(+), 1 deletion(-) rename test/machinaris/{1.0.5 => 1.0.6}/.helmignore (100%) rename test/machinaris/{1.0.5 => 1.0.6}/Chart.yaml (96%) rename test/machinaris/{1.0.5 => 1.0.6}/README.md (100%) rename test/machinaris/{1.0.5 => 1.0.6}/app-readme.md (100%) rename test/machinaris/{1.0.5 => 1.0.6}/charts/common-2105.0.0.tgz (100%) rename test/machinaris/{1.0.5 => 1.0.6}/ix_values.yaml (100%) rename test/machinaris/{1.0.5 => 1.0.6}/questions.yaml (88%) rename test/machinaris/{1.0.5 => 1.0.6}/requirements.lock (100%) rename test/machinaris/{1.0.5 => 1.0.6}/templates/deployment.yaml (91%) rename test/machinaris/{1.0.5 => 1.0.6}/templates/service.yaml (100%) rename test/machinaris/{1.0.5 => 1.0.6}/test_values.yaml (100%) diff --git a/test/machinaris/1.0.5/.helmignore b/test/machinaris/1.0.6/.helmignore similarity index 100% rename from test/machinaris/1.0.5/.helmignore rename to test/machinaris/1.0.6/.helmignore diff --git a/test/machinaris/1.0.5/Chart.yaml b/test/machinaris/1.0.6/Chart.yaml similarity index 96% rename from test/machinaris/1.0.5/Chart.yaml rename to test/machinaris/1.0.6/Chart.yaml index 16fb0e636c..871a3e824b 100644 --- a/test/machinaris/1.0.5/Chart.yaml +++ b/test/machinaris/1.0.6/Chart.yaml @@ -14,4 +14,4 @@ keywords: name: machinaris sources: - https://github.com/guydavis/machinaris -version: 1.0.5 +version: 1.0.6 diff --git a/test/machinaris/1.0.5/README.md b/test/machinaris/1.0.6/README.md similarity index 100% rename from test/machinaris/1.0.5/README.md rename to test/machinaris/1.0.6/README.md diff --git a/test/machinaris/1.0.5/app-readme.md b/test/machinaris/1.0.6/app-readme.md similarity index 100% rename from test/machinaris/1.0.5/app-readme.md rename to test/machinaris/1.0.6/app-readme.md diff --git a/test/machinaris/1.0.5/charts/common-2105.0.0.tgz b/test/machinaris/1.0.6/charts/common-2105.0.0.tgz similarity index 100% rename from test/machinaris/1.0.5/charts/common-2105.0.0.tgz rename to test/machinaris/1.0.6/charts/common-2105.0.0.tgz diff --git a/test/machinaris/1.0.5/ix_values.yaml b/test/machinaris/1.0.6/ix_values.yaml similarity index 100% rename from test/machinaris/1.0.5/ix_values.yaml rename to test/machinaris/1.0.6/ix_values.yaml diff --git a/test/machinaris/1.0.5/questions.yaml b/test/machinaris/1.0.6/questions.yaml similarity index 88% rename from test/machinaris/1.0.5/questions.yaml rename to test/machinaris/1.0.6/questions.yaml index f186d981ff..96b652d13a 100644 --- a/test/machinaris/1.0.5/questions.yaml +++ b/test/machinaris/1.0.6/questions.yaml @@ -7,6 +7,8 @@ groups: description: "Configure Storage for Machinaris" - name: "Machinaris Environment Variables" description: "Set the environment that will be visible to the container" + - name: "Resource Limits" + description: "Set CPU/memory limits for Kubernetes Pod" portals: web_portal: @@ -157,3 +159,22 @@ questions: label: "Value" schema: type: string + - variable: enableResourceLimits + label: "Enable Pod resource limits" + group: "Resource Limits" + schema: + type: boolean + - variable: cpuLimit + label: "CPU limit" + group: "Resource Limits" + schema: + type: string + show_if: [["enableResourceLimits", "=", true]] + valid_chars: "^\\d+(?:\\.\\d+(?!.*m$)|m?$)" + - variable: memLimit + label: "Memory limit" + group: "Resource Limits" + schema: + type: string + show_if: [["enableResourceLimits", "=", true]] + valid_chars: "^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$" diff --git a/test/machinaris/1.0.5/requirements.lock b/test/machinaris/1.0.6/requirements.lock similarity index 100% rename from test/machinaris/1.0.5/requirements.lock rename to test/machinaris/1.0.6/requirements.lock diff --git a/test/machinaris/1.0.5/templates/deployment.yaml b/test/machinaris/1.0.6/templates/deployment.yaml similarity index 91% rename from test/machinaris/1.0.5/templates/deployment.yaml rename to test/machinaris/1.0.6/templates/deployment.yaml index 2ae586e7d7..7fa3f48ce1 100644 --- a/test/machinaris/1.0.5/templates/deployment.yaml +++ b/test/machinaris/1.0.6/templates/deployment.yaml @@ -17,6 +17,12 @@ spec: hostNetwork: true containers: - name: {{ .Chart.Name }} + {{ if .Values.enableResourceLimits }} + resources: + limits: + cpu: {{ .Values.cpuLimit }} + memory: {{ .Values.memLimit }} + {{ end }} tty: true {{ include "common.containers.imageConfig" .Values.image | nindent 10 }} volumeMounts: {{ include "common.storage.configureAppVolumeMountsInContainer" .Values | nindent 12 }} diff --git a/test/machinaris/1.0.5/templates/service.yaml b/test/machinaris/1.0.6/templates/service.yaml similarity index 100% rename from test/machinaris/1.0.5/templates/service.yaml rename to test/machinaris/1.0.6/templates/service.yaml diff --git a/test/machinaris/1.0.5/test_values.yaml b/test/machinaris/1.0.6/test_values.yaml similarity index 100% rename from test/machinaris/1.0.5/test_values.yaml rename to test/machinaris/1.0.6/test_values.yaml