Skip to content

Commit a8ba6b1

Browse files
authored
Remove user-facing config of limits and requests (#935)
This patch introduces reusable library charts that provide backward-compatibility for users that specify their resources as explicit requests and limits for cpu, however this input is processed so that limits are set equal to requests except for CPU which only gets requests. Users can now embrace the new form by directly specifying resources in the first level of nesting (e.g. resources.cpu=100m instead of .resources.requests.cpu=100m). The order of precedence is top-level, then requests, then limits, ensuring that nothing will break in terms of scheduling, however workloads that specified limits much higher than requests might get a performance hit, now that they cannot use all this excess capacity. This should only affect memory-hungry workloads in low-contention environments. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a reusable Helm library chart, "cozy-lib", providing common templates and resource helpers for other charts. - Added resource preset and sanitization templates to standardize Kubernetes resource configurations. - ClickHouse chart now depends on "cozy-lib" for improved resource handling. - Added a new packaging script and streamlined Helm chart packaging processes across multiple packages. - **Bug Fixes** - Resource configuration logic in the ClickHouse deployment was updated to use the new library templates, ensuring more consistent resource definitions. - **Chores** - Added new Makefiles and version mapping for streamlined Helm chart packaging and validation. - Updated ClickHouse chart version to 0.9.0 and reflected this in version mapping files. - Refactored Makefile targets to consolidate packaging logic and improve maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 609e7ed + 9592f7f commit a8ba6b1

20 files changed

Lines changed: 255 additions & 25 deletions

‎Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ build: build-deps
2929

3030
repos:
3131
rm -rf _out
32+
make -C packages/library check-version-map
3233
make -C packages/apps check-version-map
3334
make -C packages/extra check-version-map
35+
make -C packages/library repo
3436
make -C packages/system repo
3537
make -C packages/apps repo
3638
make -C packages/extra repo

‎hack/gen_versions_map.sh‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ if [ ! -f "$file" ] || [ ! -s "$file" ]; then
1616
exit 0
1717
fi
1818

19-
miss_map=$(echo "$new_map" | awk 'NR==FNR { nm[$1 " " $2] = $3; next } { if (!($1 " " $2 in nm)) print $1, $2, $3}' - "$file")
19+
miss_map=$(mktemp)
20+
trap 'rm -f "$miss_map"' EXIT
21+
echo -n "$new_map" | awk 'NR==FNR { nm[$1 " " $2] = $3; next } { if (!($1 " " $2 in nm)) print $1, $2, $3}' - "$file" > $miss_map
2022

2123
# search accross all tags sorted by version
2224
search_commits=$(git ls-remote --tags origin | awk -F/ '$3 ~ /v[0-9]+.[0-9]+.[0-9]+/ {print}' | sort -k2,2 -rV | awk '{print $1}')
2325

2426
resolved_miss_map=$(
25-
echo "$miss_map" | while read -r chart version commit; do
27+
while read -r chart version commit; do
2628
# if version is found in HEAD, it's HEAD
2729
if [ "$(awk '$1 == "version:" {print $2}' ./${chart}/Chart.yaml)" = "${version}" ]; then
2830
echo "$chart $version HEAD"
@@ -56,7 +58,7 @@ resolved_miss_map=$(
5658
fi
5759
5860
echo "$chart $version $found_tag"
59-
done
61+
done < $miss_map
6062
)
6163

6264
printf "%s\n" "$new_map" "$resolved_miss_map" | sort -k1,1 -k2,2 -V | awk '$1' > "$file"

‎hack/package_chart.sh‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
usage() {
6+
printf "%s\n" "Usage:" >&2 ;
7+
printf -- "%s\n" '---' >&2 ;
8+
printf "%s %s\n" "$0" "INPUT_DIR OUTPUT_DIR TMP_DIR [DEPENDENCY_DIR]" >&2 ;
9+
printf -- "%s\n" '---' >&2 ;
10+
printf "%s\n" "Takes a helm repository from INPUT_DIR, with an optional library repository in" >&2 ;
11+
printf "%s\n" "DEPENDENCY_DIR, prepares a view of the git archive at select points in history" >&2 ;
12+
printf "%s\n" "in TMP_DIR and packages helm charts, outputting the tarballs to OUTPUT_DIR" >&2 ;
13+
}
14+
15+
if [ "x$(basename $PWD)" != "xpackages" ]
16+
then
17+
echo "Error: This script must run from the ./packages/ directory" >&2
18+
echo >&2
19+
usage
20+
exit 1
21+
fi
22+
23+
if [ "x$#" != "x3" ] && [ "x$#" != "x4" ]
24+
then
25+
echo "Error: This script takes 3 or 4 arguments" >&2
26+
echo "Got $# arguments:" "$@" >&2
27+
echo >&2
28+
usage
29+
exit 1
30+
fi
31+
32+
input_dir=$1
33+
output_dir=$2
34+
tmp_dir=$3
35+
36+
if [ "x$#" = "x4" ]
37+
then
38+
dependency_dir=$4
39+
fi
40+
41+
rm -rf "${output_dir:?}"
42+
mkdir -p "${output_dir}"
43+
while read package _ commit
44+
do
45+
# this lets devs build the packages from a dirty repo for quick local testing
46+
if [ "x$commit" = "xHEAD" ]
47+
then
48+
helm package "${input_dir}/${package}" -d "${output_dir}"
49+
continue
50+
fi
51+
git archive --format tar "${commit}" "${input_dir}/${package}" | tar -xf- -C "${tmp_dir}/"
52+
53+
# the library chart is not present in older commits and git archive doesn't fail gracefully if the path is not found
54+
if [ "x${dependency_dir}" != "x" ] && git ls-tree --name-only "${commit}" "${dependency_dir}" | grep -qx "${dependency_dir}"
55+
then
56+
git archive --format tar "${commit}" "${dependency_dir}" | tar -xf- -C "${tmp_dir}/"
57+
fi
58+
helm package "${tmp_dir}/${input_dir}/${package}" -d "${output_dir}"
59+
rm -rf "${tmp_dir:?}/${input_dir:?}/${package:?}"
60+
if [ "x${dependency_dir}" != "x" ]
61+
then
62+
rm -rf "${tmp_dir:?}/${dependency_dir:?}"
63+
fi
64+
done < "${input_dir}/versions_map"
65+
helm repo index "${output_dir}"

‎packages/apps/Makefile‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
OUT=../../_out/repos/apps
2-
TMP=../../_out/repos/apps/historical
1+
OUT=../_out/repos/apps
2+
TMP := $(shell mktemp -d)
33

44
repo:
5-
rm -rf "$(OUT)"
6-
mkdir -p "$(OUT)"
7-
awk '$$3 != "HEAD" {print "mkdir -p $(TMP)/" $$1 "-" $$2}' versions_map | sh -ex
8-
awk '$$3 != "HEAD" {print "git archive " $$3 " " $$1 " | tar -xf- --strip-components=1 -C $(TMP)/" $$1 "-" $$2 }' versions_map | sh -ex
9-
helm package -d "$(OUT)" $$(find . $(TMP) -mindepth 2 -maxdepth 2 -name Chart.yaml | awk 'sub("/Chart.yaml", "")' | sort -V)
10-
cd "$(OUT)" && helm repo index . --url http://cozystack.cozy-system.svc/repos/apps
11-
rm -rf "$(TMP)"
5+
cd .. && ../hack/package_chart.sh apps $(OUT) $(TMP) library
126

137
fix-chartnames:
148
find . -maxdepth 2 -name Chart.yaml | awk -F/ '{print $$2}' | while read i; do sed -i "s/^name: .*/name: $$i/" "$$i/Chart.yaml"; done

‎packages/apps/clickhouse/Chart.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type: application
1616
# This is the chart version. This version number should be incremented each time you make changes
1717
# to the chart and its templates, including the app version.
1818
# Versions are expected to follow Semantic Versioning (https://semver.org/)
19-
version: 0.8.0
19+
version: 0.9.0
2020

2121
# This is the version number of the application being deployed. This version number should be
2222
# incremented each time you make changes to the application. Versions are not expected to
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../library/cozy-lib

‎packages/apps/clickhouse/templates/clickhouse.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ spec:
122122
- name: clickhouse
123123
image: clickhouse/clickhouse-server:24.9.2.42
124124
{{- if .Values.resources }}
125-
resources: {{- toYaml .Values.resources | nindent 16 }}
125+
resources: {{- include "cozy-lib.resources.sanitize" .Values.resources | nindent 16 }}
126126
{{- else if ne .Values.resourcesPreset "none" }}
127-
resources: {{- include "resources.preset" (dict "type" .Values.resourcesPreset "Release" .Release) | nindent 16 }}
127+
resources: {{- include "cozy-lib.resources.preset" .Values.resourcesPreset | nindent 16 }}
128128
{{- end }}
129129
volumeMounts:
130130
- name: data-volume-template

‎packages/apps/versions_map‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ clickhouse 0.6.0 1ec10165
99
clickhouse 0.6.1 c62a83a7
1010
clickhouse 0.6.2 8267072d
1111
clickhouse 0.7.0 93bdf411
12-
clickhouse 0.8.0 HEAD
12+
clickhouse 0.9.0 HEAD
1313
ferretdb 0.1.0 e9716091
1414
ferretdb 0.1.1 91b0499a
1515
ferretdb 0.2.0 6c5cf5bf

‎packages/extra/Makefile‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
OUT=../../_out/repos/extra
2-
TMP=../../_out/repos/extra/historical
1+
OUT=../_out/repos/extra
2+
TMP := $(shell mktemp -d)
33

44
repo:
5-
rm -rf "$(OUT)"
6-
mkdir -p "$(OUT)"
7-
awk '$$3 != "HEAD" {print "mkdir -p $(TMP)/" $$1 "-" $$2}' versions_map | sh -ex
8-
awk '$$3 != "HEAD" {print "git archive " $$3 " " $$1 " | tar -xf- --strip-components=1 -C $(TMP)/" $$1 "-" $$2 }' versions_map | sh -ex
9-
helm package -d "$(OUT)" $$(find . $(TMP) -mindepth 2 -maxdepth 2 -name Chart.yaml | awk 'sub("/Chart.yaml", "")' | sort -V)
10-
cd "$(OUT)" && helm repo index . --url http://cozystack.cozy-system.svc/repos/extra
11-
rm -rf "$(TMP)"
5+
cd .. && ../hack/package_chart.sh extra $(OUT) $(TMP) library
126

137
fix-chartnames:
148
find . -maxdepth 2 -name Chart.yaml | awk -F/ '{print $$2}' | while read i; do sed -i "s/^name: .*/name: $$i/" "$$i/Chart.yaml"; done

‎packages/library/Makefile‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
OUT=../_out/repos/library
2+
TMP := $(shell mktemp -d)
3+
4+
repo:
5+
cd .. && ../hack/package_chart.sh library $(OUT) $(TMP)
6+
7+
fix-chartnames:
8+
find . -maxdepth 2 -name Chart.yaml | awk -F/ '{print $$2}' | while read i; do sed -i "s/^name: .*/name: $$i/" "$$i/Chart.yaml"; done
9+
10+
gen-versions-map: fix-chartnames
11+
../../hack/gen_versions_map.sh
12+
13+
check-version-map: gen-versions-map
14+
git diff --exit-code -- versions_map
15+

0 commit comments

Comments
 (0)