Skip to content

Commit

Permalink
fix(db-wait): Allow to skip "extra" resources on some containers (#757)
Browse files Browse the repository at this point in the history
**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [x] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [ ] ⚖️ My code follows the style guidelines of this project
- [ ] 👀 I have performed a self-review of my own code
- [ ] #️⃣ I have commented my code, particularly in hard-to-understand
areas
- [ ] 📄 I have made corresponding changes to the documentation
- [ ] ⚠️ My changes generate no new warnings
- [ ] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [ ] ⬆️ I increased versions for any altered app according to semantic
versioning
- [ ] I made sure the title starts with `feat(chart-name):`,
`fix(chart-name):` or `chore(chart-name):`

**➕ App addition**

If this PR is an app addition please make sure you have done the
following.

- [ ] 🖼️ I have added an icon in the Chart's root directory called
`icon.png`

---

_Please don't blindly check all the boxes. Read them and only check
those that apply.
Those checkboxes are there for the reviewer to see what is this all
about and
the status of this PR with a quick glance._

---------

Co-authored-by: Kjeld Schouten <[email protected]>
  • Loading branch information
stavros-k and Kjeld Schouten authored Mar 22, 2024
1 parent 316001f commit fe02375
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 62 deletions.
71 changes: 71 additions & 0 deletions library/common-test/tests/container/resources_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,77 @@ tests:
cpu: 10m
memory: 1Gi

- it: should not add extra resources on "wait" containers and on excluded containers
set:
image: *image
redis:
enabled: true
resources:
limits:
"nvidia.com/gpu": "1"
workload:
workload-name1:
enabled: true
primary: true
type: Deployment
podSpec:
containers:
container-name1:
enabled: true
primary: true
imageSelector: image
probes: *probes
my-container:
enabled: true
imageSelector: image
probes: *probes
resources:
excludeExtra: true
asserts:
- documentIndex: &deploymentDoc 1
isKind:
of: Deployment
- documentIndex: *deploymentDoc
isAPIVersion:
of: apps/v1
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[0]
content:
name: test-release-name-common-test
resources:
limits:
cpu: 4000m
memory: 8Gi
nvidia.com/gpu: 1
requests:
cpu: 10m
memory: 50Mi
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.containers[1]
content:
name: test-release-name-common-test-my-container
resources:
limits:
cpu: 4000m
memory: 8Gi
requests:
cpu: 10m
memory: 50Mi
- documentIndex: *deploymentDoc
isSubset:
path: spec.template.spec.initContainers[0]
content:
name: test-release-name-common-test-system-redis-wait
resources:
limits:
cpu: 4000m
memory: 8Gi
requests:
cpu: 10m
memory: 50Mi

# Failures
- it: should fail with empty requests
set:
Expand Down
19 changes: 17 additions & 2 deletions library/common/templates/lib/container/_resources.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ objectData: The object data to be used to render the container.
{{- $resources = mustMergeOverwrite $resources $objectData.resources -}}
{{- end -}}

{{- include "tc.v1.common.lib.container.resources.validation" (dict "resources" $resources) -}}
{{/* We use the objectData instead of $resources,
as we only allow this flag on the container level */}}
{{- if not (hasKey $objectData "resources") -}}
{{- $_ := set $objectData "resources" dict -}}
{{- end -}}
{{- if not (hasKey $objectData.resources "excludeExtra") -}}
{{- $_ := set $objectData.resources "excludeExtra" false -}}
{{- end -}}

{{- $excludeContainersFromExtraResources := (list
"cnpg-wait" "solr-wait" "clickhouse-wait"
"mongodb-wait" "redis-wait" "mariadb-wait"
) -}}

{{- include "tc.v1.common.lib.container.resources.validation" (dict "resources" $resources) }}
requests:
cpu: {{ $resources.requests.cpu }}
memory: {{ $resources.requests.memory }}
Expand All @@ -27,8 +40,10 @@ limits:
{{- with $resources.limits.memory }} {{/* Passing 0, will not render it, meaning unlimited */}}
memory: {{ . }}
{{- end -}}
{{- range $k, $v := (omit $resources.limits "cpu" "memory") }} {{/* Omit cpu and memory, as they are handled above */}}
{{- if and (not $objectData.resources.excludeExtra) (not (mustHas $objectData.shortName $excludeContainersFromExtraResources)) -}}
{{- range $k, $v := (omit $resources.limits "cpu" "memory") }} {{/* Omit cpu and memory, as they are handled above */}}
{{ $k }}: {{ $v }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
Expand Down
120 changes: 60 additions & 60 deletions library/common/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -587,20 +587,20 @@ ingress:
# main: main
## Configure the hosts for the ingress
hosts: []
# - # -- Host address. Helm template can be passed.
# host: chart-example.local
# ## Configure the paths for the host
# paths:
# - # -- Path. Helm template can be passed.
# path: /
# # -- Ignored if not kubeVersion >= 1.14-0
# pathType: Prefix
# # -- Overrides the service reference for this path, by default the selector is honored
# overrideService:
# # -- Overrides the service name reference for this path
# name:
# # -- Overrides the service port reference for this path
# port:
# - # -- Host address. Helm template can be passed.
# host: chart-example.local
# ## Configure the paths for the host
# paths:
# - # -- Path. Helm template can be passed.
# path: /
# # -- Ignored if not kubeVersion >= 1.14-0
# pathType: Prefix
# # -- Overrides the service reference for this path, by default the selector is honored
# overrideService:
# # -- Overrides the service name reference for this path
# name:
# # -- Overrides the service port reference for this path
# port:
# -- Configure TLS for the ingress. Both secretName and hosts can process a Helm template.
# Gets ignored when clusterIssuer is filled
tls: []
Expand Down Expand Up @@ -628,10 +628,10 @@ ingress:
# # "lookup" the namespace based on the name
# namespace: ""
middlewares: []
# - name: my-middleware
# # Optional, by default will try to
# # "lookup" the namespace based on the name
# namespace: ""
# - name: my-middleware
# # Optional, by default will try to
# # "lookup" the namespace based on the name
# namespace: ""
homepage:
enabled: false
# Default: chart name
Expand All @@ -654,15 +654,15 @@ ingress:
# value: some value

certificate: {}
# main:
# enabled: false
# certificateIssuer: someissuer
# hosts:
# - somehost
# # Optional
# certificateSecretTemplate:
# labels: {}
# annotations: {}
# main:
# enabled: false
# certificateIssuer: someissuer
# hosts:
# - somehost
# # Optional
# certificateSecretTemplate:
# labels: {}
# annotations: {}

# -- BETA: Configure the gateway routes for the chart here.
# Additional routes can be added by adding a dictionary key similar to the 'main' route.
Expand All @@ -683,7 +683,7 @@ route:
labels: {}
# -- Configure the resource the route attaches to.
parentRefs:
- # Group of the referent resource.
- # Group of the referent resource.
group: gateway.networking.k8s.io
# Kind of the referent resource.
kind: Gateway
Expand Down Expand Up @@ -881,11 +881,11 @@ metrics:
prometheusRule:
enabled: false
groups: {}
# somegroup:
# # list of rules
# rules: []
# # list to support adding rules via the SCALE GUI without overwrithing the rules
# additionalrules: []
# somegroup:
# # list of rules
# rules: []
# # list to support adding rules via the SCALE GUI without overwrithing the rules
# additionalrules: []
# List to support adding groups using the SCALE GUI
additionalgroups:
#- name: "somegroup"
Expand Down Expand Up @@ -961,13 +961,13 @@ addons:
# -- All variables specified here will be added to the vpn sidecar container
# See the documentation of the VPN image for all config values
env: {}
# TZ: UTC
# TZ: UTC

# -- All variables specified here will be added to the vpn sidecar container
# See the documentation of the VPN image for all config values
envList: []
# - name: someenv
# value: somevalue
# - name: someenv
# value: somevalue

# -- you can directly specify the config file here
config: ""
Expand Down Expand Up @@ -1014,8 +1014,8 @@ addons:
# -- All variables specified here will be added to the codeserver sidecar container
# See the documentation of the codeserver image for all config values
envList: []
# - name: someenv
# value: somevalue
# - name: someenv
# value: somevalue
# -- Set codeserver command line arguments.
# Consider setting --user-data-dir to a persistent location to preserve code-server setting changes
args:
Expand Down Expand Up @@ -1045,7 +1045,7 @@ addons:
# -- Enable an ingress for the code-server add-on.
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/ingress.class: nginx
labels: {}
hosts:
- host: code.chart-example.local
Expand Down Expand Up @@ -1158,26 +1158,26 @@ cnpg:
# See: https://cloudnative-pg.io/documentation/current/bootstrap/
# See: https://cloudnative-pg.io/documentation/current/api_reference/#bootstrapinitdb
initdb: {}
# postInitSQL:
# - CREATE EXTENSION IF NOT EXISTS vector;
# postInitApplicationSQL:
# - CREATE EXTENSION IF NOT EXISTS someextension;
# postInitSQL:
# - CREATE EXTENSION IF NOT EXISTS vector;
# postInitApplicationSQL:
# - CREATE EXTENSION IF NOT EXISTS someextension;
# -- set to enable prometheus metrics
monitoring:
enablePodMonitor: true
disableDefaultQueries: false
customQueries: []
# - name: "pg_cache_hit_ratio"
# expandObjectName: true
# key: "custom-key" (defaults to "custom-queries")
# query: "SELECT current_database() as datname, sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read)) as ratio FROM pg_statio_user_tables;"
# metrics:
# - datname:
# usage: "LABEL"
# description: "Name of the database database"
# - ratio:
# usage: GAUGE
# description: "Cache hit ratio"
# - name: "pg_cache_hit_ratio"
# expandObjectName: true
# key: "custom-key" (defaults to "custom-queries")
# query: "SELECT current_database() as datname, sum(heap_blks_hit) / (sum(heap_blks_hit) + sum(heap_blks_read)) as ratio FROM pg_statio_user_tables;"
# metrics:
# - datname:
# usage: "LABEL"
# description: "Name of the database database"
# - ratio:
# usage: GAUGE
# description: "Cache hit ratio"
# Recovery settings if the chosen mode is `recovery`.
recovery:
##
Expand Down Expand Up @@ -1287,12 +1287,12 @@ cnpg:

# - Manual list of backups
manualBackups: []
# - name: today
# labels: {}
# annotations: {}
# - name: beforeUpgrade
# labels: {}
# annotations: {}
# - name: today
# labels: {}
# annotations: {}
# - name: beforeUpgrade
# labels: {}
# annotations: {}

# Database cluster PgBouncer configuration
pooler:
Expand Down

0 comments on commit fe02375

Please sign in to comment.