diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2f24fb2..18098f2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -38,3 +38,5 @@ jobs: path: ${{ env.COMPONENT_NAME }} - name: Compile component run: make test + - name: Compile component with no defined resource limits + run: make test-nolimits diff --git a/Makefile b/Makefile index 2768927..08933fe 100644 --- a/Makefile +++ b/Makefile @@ -51,9 +51,20 @@ docs-serve: ## Preview the documentation mkdir -p dependencies $(COMMODORE_CMD) -.PHONY: test -test: commodore_args += -f tests/$(instance).yml -test: .compile ## Compile the component +.PHONY: test-nolimits +test-nolimits: instance = no_container_limits +test-nolimits: runtest + +.PHONY: test-default +test-default: instance = defaults +test-default: runtest + +.PHONY: test test-default test-nolimits +test: test-default + +.PHONY: runtest +runtest: commodore_args += -f tests/$(instance).yml +runtest: .compile ## Compile the component .PHONY: clean clean: ## Clean the project diff --git a/class/defaults.yml b/class/defaults.yml index 7866d59..95f0a9b 100644 --- a/class/defaults.yml +++ b/class/defaults.yml @@ -16,14 +16,6 @@ parameters: monitor_user: maxscale service_pwd: ?{vaultkv:${customer:name}/${cluster:name}/${_instance}/service_pwd} monitor_pwd: ?{vaultkv:${customer:name}/${cluster:name}/${_instance}/monitor_pwd} - containers: - resources: - requests: - cpu: 1000m - memory: 128Mi - limits: - cpu: 2000m - memory: 512Mi images: maxscale: image: gchr.io/appuio/maxscale-docker diff --git a/component/main.jsonnet b/component/main.jsonnet index 2fa1fee..1763bf4 100644 --- a/component/main.jsonnet +++ b/component/main.jsonnet @@ -3,6 +3,20 @@ local kap = import 'lib/kapitan.libjsonnet'; local kube = import 'lib/kube.libjsonnet'; local inv = kap.inventory(); local params = inv.parameters.maxscale; +local res = if std.objectHas(params, 'resources') then params.resources else null; + +local default_resources = { + limits: { + cpu: '2000m', + memory: '512Mi', + }, + requests: { + cpu: '1000m', + memory: '128Mi', + }, +}; + +local resources = if res != null then std.mergePatch(default_resources, res) else null; local namespace = kube.Namespace(params.namespace) { metadata+: { @@ -80,16 +94,7 @@ local deployment = kube.Deployment('maxscale') { }, initialDelaySeconds: 15, }, - resources: { - requests: { - cpu: params.containers.resources.requests.cpu, - memory: params.containers.resources.requests.memory, - }, - limits: { - cpu: params.containers.resources.limits.cpu, - memory: params.containers.resources.limits.memory, - }, - }, + [if resources != null then 'resources']: resources, volumeMounts: [ { name: 'maxscale-cnf-volume', diff --git a/docs/modules/ROOT/pages/references/parameters.adoc b/docs/modules/ROOT/pages/references/parameters.adoc index 3436f5e..3305980 100644 --- a/docs/modules/ROOT/pages/references/parameters.adoc +++ b/docs/modules/ROOT/pages/references/parameters.adoc @@ -83,9 +83,9 @@ type:: string default:: `?{vaultkv:${customer:name}/${cluster:name}/maxscale/monitor_pwd}` -= Container Parameters += Container Resource Parameters -The parent key for the following parameters is `containers` and they affect the MaxScale containers: +By default there are no resource limits. As soon as you set *any* of these reource parameters, all the other ones are set to their defaults and you'll have to override them to change them. This prevents generating an invalid manifest. == `resources.requests.cpu` @@ -127,7 +127,6 @@ maxscale: db3_port: 3305 monitor_user: mymonitoruser service_user: myserviceuser -containers: resources: requests: cpu: 1000m diff --git a/tests/defaults.yml b/tests/defaults.yml index e3f744d..9f796c4 100644 --- a/tests/defaults.yml +++ b/tests/defaults.yml @@ -20,3 +20,11 @@ parameters: monitor_user: maxscale-testmonitor service_pwd: testservicepwd monitor_pwd: testmonitorpwd + containers: + resources: + limits: + memory: 512Mi + cpu: 1234m + requests: + memory: 1024Mi + cpu: 123m diff --git a/tests/no_container_limits.yml b/tests/no_container_limits.yml new file mode 100644 index 0000000..c34d8e0 --- /dev/null +++ b/tests/no_container_limits.yml @@ -0,0 +1,20 @@ +# Overwrite parameters here + +# parameters: {...} +--- +parameters: + _instance: maxscale-nolimits + maxscale: + namespace: maxscale-test + master_only_listen_address: 127.0.0.1 + read_write_listen_address: 127.0.0.1 + db1_address: db1.mygalera.test.example.org + db1_port: 3307 + db2_address: db2.mygalera.test.example.org + db2_port: 3307 + db3_address: db3.mygalera.test.example.org + db3_port: 3307 + service_user: maxscale-testservice + monitor_user: maxscale-testmonitor + service_pwd: testservicepwd + monitor_pwd: testmonitorpwd