25 Commits

Author SHA1 Message Date
Timofei Larkin
91ddbb06ef [cozy-lib] Improve flatten function
This patch breaks introduces a helper function in cozy-lib to correctly
handle special case resources when transforming a nested map of limits
and requests to a flat map suitable for use in resourceQuotas. As a
result, admins can now specify any types of resources as resource quotas
for tenants, and they will be correctly transformed to the correct
format for the underlying kubernetes ResourceQuota. In addition to the
previously supported compute resources, such as CPU, memory, and custom
resources, like GPUs, special quota strings such as
"services.loadbalancers" are now correctly handled.

```release-note
[cozy-lib,platform] Support resource quotas for special kubernetes
quotas, such as service.loadbalncer count and others.
```

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
2025-11-21 17:41:21 +03:00
IvanHunters
a070573af9 fix flatten for tests
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
2025-11-20 12:01:49 +03:00
IvanHunters
492aef93f5 fix flatten with rabbit recomendation
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
2025-11-20 10:55:47 +03:00
IvanHunters
23e6cf735a fix flatten with rabbit recomendation
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
2025-11-20 10:55:47 +03:00
IvanHunters
c5b1177149 fix flatten with rabbit recomendation
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
2025-11-20 10:55:47 +03:00
IvanHunters
84133ef2d3 [cozy-lib] Fix malformed ResourceQuota rendering for LoadBalancer services
This patch adds special handling for raw Kubernetes ResourceQuota fields,
such as `services.loadbalancers`, preventing them from being wrapped as
`limits.*` or `requests.*` keys by the flatten helper. This ensures that
LoadBalancer quotas render correctly in tenant specifications.

```release-note
[cozy-lib] Correctly render services.loadbalancers in ResourceQuota without limits.* or requests.* prefixes.
```

Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
2025-11-20 10:55:47 +03:00
Timofei Larkin
1c9ae2bec5 [ci,dx] Add unit tests for cozy-lib
## What this PR does

The cozy-lib library package got complicated enough to warrant its own
unit tests. Since unit tests are a "good thing" (tm), a somewhat generic
framework for running all kinds of unit tests was introduced into the CI
pipeline and Makefile targets. For now all it runs is `make test`
against the `packages/{library,apps,system,extra}/*` directories,
wherever a `test` target is present in the Makefile, and for now this is
only for the `cozy-lib` Helm library chart.

### Release note

```release-note
[ci,dx] Introduce a scaffold for running unit tests locally and in CI
and add the first unit tests for the cozy-lib helper Helm chart.
```

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
2025-11-19 17:56:17 +03:00
Andrei Kvapil
00328c8a31 [cozy-lib] Fix: handling resources=nil
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Co-authored-by: Timofei Larkin <lllamnyp@gmail.com>
2025-11-07 11:02:02 +01:00
Andrei Kvapil
f871fbdb1e Remove versions_map logic
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2025-09-24 12:32:37 +02:00
IvanHunters
3e03b1bd86 add resource quota for testing ns
Signed-off-by: IvanHunters <xorokhotnikov@gmail.com>
2025-09-09 17:42:52 +03:00
Andrei Kvapil
fe869b97fd Fix missing cozy-lib.resources.flatten template
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2025-09-01 12:13:23 +02:00
Timofei Larkin
46c2ee3c31 [cozy-lib] Fix incorrect retrieval of cozyConfig
A malformed access to the global context was preventing some helm charts
from rendering correctly.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
2025-08-19 15:35:45 +03:00
Nick Volynkin
f864b40a85 [apps] Use new OpenAPI schema and README generator for packages/apps
- clickhouse
- ferretdb
- http-cache
- kafka
- kubernetes
- mysql
- nats
- rabbitmq
- redis
- tcp-balancer
- vm-disk
- vm-instance
- vpn

Signed-off-by: Nick Volynkin <nick.volynkin@gmail.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2025-08-11 12:59:50 +03:00
Timofei Larkin
917a6f354d [platform] Autodetect RobotLB
If running in Hetzner and using Hetzner's cloud load balancers, node
ports need to be allocated for the load balancer to function correctly.
Therefore if RobotLB is enabled, we probably need to assign node ports.

Release note:
[platform] Autodetect if node ports should be assigned to load balancer
services.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
2025-07-24 18:55:30 +03:00
Andrei Kvapil
72e7b5e0b5 Get rid of bitnami's readme-generator
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2025-07-18 00:40:31 +02:00
Timofei Larkin
9adcd48c44 [keycloak, cozy-lib] Calculate Java heap params
This patch passes Java heap parameters to Keycloak to prevent OOM errors
when the JVM lacks compatibility with cgroups v2 and fails to recognize
container memory requests and limits. A new function is introduced in
cozy-lib to calculate the heap parameters from requests and limits,
setting Xmx to 75% of the memory limit and Xms to the lesser of the
memory request or 25% of the memory limits.

Change log:
[keycloak] Calculate and pass Java heap parameters explicitly to prevent
OOM errors.
[cozy-lib] Introduce helper function to calculate Java heap params based
on memory requests and limits.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
2025-07-03 22:15:04 +03:00
Timofei Larkin
bd9e283d3b [platform] Always set resources for managed apps
This patch removes the loophole to leave resource requests and limits
unspecified in managed apps. Any of cpu, memory, and ephemeral storage
are now filled in from the resource preset (default or user-specified)
if not explicitly specified in .Values.resources. "none" is no longer an
accepted value in resourcePresets and the primary resources now always
have some explicit value for proper billing and isolation.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
2025-07-03 17:45:32 +03:00
Andrei Kvapil
bb46aa4b7d [cozy-lib] Introduce memory-allocation-ratio and ephemeral-strorage-allocation-ratio options
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2025-07-03 15:00:41 +03:00
Andrei Kvapil
6256e40169 [cozy-lib] remove handler for nested resources/requests map
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2025-07-03 15:00:40 +03:00
Andrei Kvapil
22cda073b9 [cozy-lib, bug] divf by cpu ratio, not mulf (#1125)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

* **Refactor**
* Updated the structure of resource presets for improved clarity and
processing.
* Adjusted template logic to streamline resource handling and removed
previous resource limit calculations.
* Modified template parameters to enhance flexibility in resource
processing.
* **Chores**
* Improved internal template invocation for better compatibility with
resource data.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2025-07-03 15:00:24 +03:00
Andrei Kvapil
f83741eb09 Add extra helper function to generate subjects
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2025-06-16 20:11:41 +02:00
Timofei Larkin
028f2e4e8d Add helper function to generate subjects
Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
2025-06-16 19:19:57 +03:00
Timofei Larkin
7023abdba7 Let users specify CPU requests in VCPUs
With this change a request for a virtual machine with 3 vCPUs will
reserve exactly the same amount of physical compute, as a request for a
Clickhouse instance with `{"resources": {"cpu": "3"}}` in its values,
with the scaling factor being KubeVirt's CPU allocation ratio.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
2025-05-30 00:55:19 +02:00
Andrei Kvapil
6cbfab9b2a [dx] remove version_map and building for library charts
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
2025-05-28 12:01:31 +02:00
Timofei Larkin
9592f7fe46 Remove user-facing config of limits and requests
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.

Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
2025-05-23 17:32:42 +03:00