Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix container params #12

Merged
merged 2 commits into from
Oct 14, 2021
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
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 15 additions & 10 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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+: {
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 2 additions & 3 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -127,7 +127,6 @@ maxscale:
db3_port: 3305
monitor_user: mymonitoruser
service_user: myserviceuser
containers:
resources:
requests:
cpu: 1000m
Expand Down
8 changes: 8 additions & 0 deletions tests/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions tests/no_container_limits.yml
Original file line number Diff line number Diff line change
@@ -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