Skip to content

Commit e62537c

Browse files
feat: add resource limits for ansible (#5274)
* feat: add resource limits for ansible Signed-off-by: Camila Macedo <[email protected]> * nit suggestion abut changelog info
1 parent 69ba8b0 commit e62537c

File tree

6 files changed

+80
-7
lines changed

6 files changed

+80
-7
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# entries is a list of entries to include in
2+
# release notes and/or the migration guide
3+
entries:
4+
- description: >
5+
For Ansible-based operators, add default resource limits for the manager.
6+
7+
# kind is one of:
8+
# - addition
9+
# - change
10+
# - deprecation
11+
# - removal
12+
# - bugfix
13+
kind: "addition"
14+
15+
# Is this a breaking change?
16+
breaking: false
17+
18+
# NOTE: ONLY USE `pull_request_override` WHEN ADDING THIS
19+
# FILE FOR A PREVIOUSLY MERGED PULL_REQUEST!
20+
#
21+
# The generator auto-detects the PR number from the commit
22+
# message in which this file was originally added.
23+
#
24+
# What is the pull request number (without the "#")?
25+
# pull_request_override: 0
26+
27+
28+
# Migration can be defined to automatically add a section to
29+
# the migration guide. This is required for breaking changes.
30+
migration:
31+
header: Header text for the migration section
32+
body: >
33+
Add into the config/manager/manager.yaml` the following limits scaffold by default:
34+
35+
```yaml
36+
...
37+
# TODO(user): Configure the resources accordingly based on the project requirements.
38+
# More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
39+
resources:
40+
limits:
41+
cpu: 500m
42+
memory: 768Mi
43+
requests:
44+
cpu: 10m
45+
memory: 256Mi
46+
...
47+
```
48+
49+
**IMPORTANT:** Having resource limits is a best-practice and these values are reasonable
50+
defaults, but Operator authors should optimize these values based on their project's
51+
requirements.

hack/generate/samples/internal/ansible/testdata/tasks/reconciliationtest_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
register: reconciliation_test
1919
- name: Retreive the number of iterations on the ConfigMap
2020
debug: var=cm.data.iterations
21-
retries: 10
21+
retries: 20
2222
delay: 2
2323
until: "cm.data.iterations|int == 5"
2424
vars:

hack/generate/samples/internal/ansible/testdata/tasks/secretstest_test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace: '{{ namespace }}'
2222
register: result
2323
until: result.resources
24-
retries: 10
24+
retries: 20
2525

2626
- name: Assert that the configmap has the proper content
2727
assert:
@@ -49,7 +49,7 @@
4949
namespace: '{{ namespace }}'
5050
register: result
5151
until: result.resources.0.data.new is defined
52-
retries: 10
52+
retries: 20
5353

5454
- name: Assert that the configmap has the proper content
5555
assert:

internal/plugins/ansible/v1/init.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ func addInitCustomizations(projectName string) error {
172172
return err
173173
}
174174

175-
// remove the resources limits
176-
// todo: remove it when we solve the issue operator-framework/operator-sdk#3573
175+
// update default resource request and limits with bigger values
177176
const resourcesLimitsFragment = ` resources:
178177
limits:
179178
cpu: 500m
@@ -182,7 +181,17 @@ func addInitCustomizations(projectName string) error {
182181
cpu: 10m
183182
memory: 64Mi
184183
`
185-
err = util.ReplaceInFile(managerFile, resourcesLimitsFragment, "")
184+
185+
const resourcesLimitsAnsibleFragment = ` resources:
186+
limits:
187+
cpu: 500m
188+
memory: 768Mi
189+
requests:
190+
cpu: 10m
191+
memory: 256Mi
192+
`
193+
194+
err = util.ReplaceInFile(managerFile, resourcesLimitsFragment, resourcesLimitsAnsibleFragment)
186195
if err != nil {
187196
return err
188197
}

testdata/ansible/memcached-operator/bundle/manifests/memcached-operator.clusterserviceversion.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,13 @@ spec:
141141
port: 6789
142142
initialDelaySeconds: 5
143143
periodSeconds: 10
144-
resources: {}
144+
resources:
145+
limits:
146+
cpu: 500m
147+
memory: 768Mi
148+
requests:
149+
cpu: 10m
150+
memory: 256Mi
145151
securityContext:
146152
allowPrivilegeEscalation: false
147153
securityContext:

testdata/ansible/memcached-operator/config/manager/manager.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,12 @@ spec:
5151
periodSeconds: 10
5252
# TODO(user): Configure the resources accordingly based on the project requirements.
5353
# More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
54+
resources:
55+
limits:
56+
cpu: 500m
57+
memory: 768Mi
58+
requests:
59+
cpu: 10m
60+
memory: 256Mi
5461
serviceAccountName: controller-manager
5562
terminationGracePeriodSeconds: 10

0 commit comments

Comments
 (0)