Skip to content

Commit

Permalink
Merge pull request #99 from warpstreamlabs/epot/millicores
Browse files Browse the repository at this point in the history
Fix cpu request in millicores
  • Loading branch information
epot authored Sep 3, 2024
2 parents d931089 + 870ce50 commit eecfce8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
6 changes: 5 additions & 1 deletion charts/warpstream-agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.13.21] - 2024-08-30
## [0.13.22] - 2024-08-30

### Added

- Fix a regression introduced in 0.13.19 that was preventing users to use a cpu request in millicores.

### Added

Expand Down
2 changes: 1 addition & 1 deletion charts/warpstream-agent/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: warpstream-agent
description: WarpStream Agent for Kubernetes.
type: application
version: 0.13.21
version: 0.13.22
appVersion: v578
icon: https://avatars.githubusercontent.com/u/132156278
home: https://docs.warpstream.com/warpstream/
Expand Down
19 changes: 19 additions & 0 deletions charts/warpstream-agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,22 @@ Convert units like 4GiB and 2000MiB to bytes.
{{- end -}}
{{- $bytes -}}
{{- end -}}

{{/*
Convert CPU requests to millicores integers.
Let's take a few examples:
- if the cpu request is "900m", it will return 900
- if the cpu request is 0.7, it will return 700
- if the cpu request is 4, it will return 4000
*/}}
{{- define "convertToMillicores" -}}
{{- $cpu := . | toString -}}
{{- $cpuMillicores := 0}}
{{- if hasSuffix "m" $cpu -}}
{{- $value := trimSuffix "m" $cpu | int -}}
{{- $cpuMillicores = $value -}}
{{- else -}}
{{- $cpuMillicores = mulf . 1000 | int -}}
{{- end -}}
{{- $cpuMillicores -}}
{{- end -}}
18 changes: 9 additions & 9 deletions charts/warpstream-agent/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ spec:
initialDelaySeconds: 10
periodSeconds: 5
resources:
{{- $cpuMillicoresRequest := .Values.resources.requests.cpu | include "convertToMillicores" -}}
{{- $goMaxProcs := divf $cpuMillicoresRequest 1000 -}}
{{- $goMaxProcs := ceil $goMaxProcs -}}
{{- if .Values.enforceProductionResourceRequirements}}
{{- $cpuRequest := .Values.resources.requests.cpu | int -}}
{{- $memoryRequest := .Values.resources.requests.memory | include "convertToBytes" -}}
{{- $memoryPerCpu := div $memoryRequest $cpuRequest -}}
{{- $minMemoryPerCpu := 4000000000 -}}
{{- if lt $memoryPerCpu $minMemoryPerCpu -}}
{{ fail (printf "Memory request per CPU (%.2f GiB) is less than the required 4 GiB per CPU. Please increase the memory request." (divf $memoryPerCpu 1073741824)) }}
{{- $memoryPerMillicore := divf $memoryRequest $cpuMillicoresRequest -}}
{{- $memoryPerCPU := mulf $memoryPerMillicore 1000.0 -}}
{{- $minMemoryPerCPU := 4000000000.0 -}}
{{- if lt $memoryPerCPU $minMemoryPerCPU -}}
{{ fail (printf "Memory request per CPU (%.2f GiB) is less than the required 4 GiB per CPU. Please increase the memory request." (divf $memoryPerCPU 1073741824)) }}
{{- end -}}
{{- end -}}
{{- toYaml .Values.resources | nindent 12 }}
Expand All @@ -94,11 +97,8 @@ spec:
{{- end }}
{{- if and .Values.resources (not .Values.goMaxProcs) }}
{{- if .Values.resources.requests }}
{{- if not (regexMatch "^[0-9]+$" (toString .Values.resources.requests.cpu)) }}
{{- fail "Only use whole numbers for cpu request because we are using it to set GOMAXPROCS." }}
{{- end }}
- name: GOMAXPROCS
value: {{ .Values.resources.requests.cpu | quote }}
value: {{ $goMaxProcs | quote }}
{{- end }}
{{- end }}
{{- if .Values.goMaxProcs }}
Expand Down

0 comments on commit eecfce8

Please sign in to comment.