Skip to content

Commit 9988554

Browse files
authored
Merge branch 'main' into feature/update-deprecated-prometheus-mem-cpu-queries
2 parents 6700a5d + 7afd7d0 commit 9988554

41 files changed

Lines changed: 3264 additions & 108 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Dockerfile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Use the official Python 3.9 slim image as the base image
2-
FROM python:3.12-slim as builder
1+
# Use the official Python 3.12 slim image as the base image
2+
FROM python:3.12-slim AS builder
33
ENV LANG=C.UTF-8
44
ENV PYTHONDONTWRITEBYTECODE=1
55
ENV PYTHONUNBUFFERED=1
@@ -9,11 +9,6 @@ ENV PATH="/app/venv/bin:$PATH"
99
RUN apt-get update && \
1010
dpkg --add-architecture arm64
1111

12-
# We're installing here libexpat1, to upgrade the package to include a fix to 3 high CVEs. CVE-2024-45491,CVE-2024-45490,CVE-2024-45492
13-
RUN apt-get update \
14-
&& apt-get install -y --no-install-recommends libexpat1 \
15-
&& rm -rf /var/lib/apt/lists/*
16-
1712
# Set the working directory
1813
WORKDIR /app
1914

README.md

Lines changed: 125 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
.
2020
<a href="#how-krr-works"><strong>How KRR works</strong></a>
2121
.
22-
<a href="#slack-integration"><strong>Slack Integration</strong></a>
23-
.
2422
<a href="#free-krr-ui-on-robusta-saas"><strong>Free KRR UI</strong></a>
2523
<br />
2624
<a href="#usage">Usage</a>
@@ -30,7 +28,9 @@
3028
<a href="https://github.com/robusta-dev/krr/issues">Request Feature</a>
3129
·
3230
<a href="#support">Support</a>
33-
<br /> Like KRR? Please ⭐ this repository to show your support!
31+
<br />
32+
<br />
33+
<a href="https://trendshift.io/repositories/7087" target="_blank"><img src="https://trendshift.io/api/badge/repositories/7087" alt="robusta-dev%2Fkrr | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
3434
</p>
3535
</div>
3636
<!-- TABLE OF CONTENTS -->
@@ -64,6 +64,10 @@
6464

6565
Robusta KRR (Kubernetes Resource Recommender) is a CLI tool for **optimizing resource allocation** in Kubernetes clusters. It gathers pod usage data from Prometheus and **recommends requests and limits** for CPU and memory. This **reduces costs and improves performance**.
6666

67+
### Auto-Apply Mode
68+
69+
**New:** Put right-sizing on auto-pilot by applying recommendations automatically. [Request beta access](https://robusta-dev.typeform.com/krr-auto-apply).
70+
6771
### Data Integrations
6872

6973
[![Used to send data to KRR](./images/krr-datasources.svg)](#data-source-integrations)
@@ -77,7 +81,7 @@ _View Instructions for: [Prometheus](#prometheus-victoria-metrics-and-thanos-aut
7781

7882
[![Used to receive information from KRR](./images/krr-other-integrations.svg)](#integrations)
7983

80-
_View instructions for: [Seeing recommendations in a UI](#free-ui-for-krr-recommendations), [Sending recommendations to Slack](#slack-notification), [Setting up KRR as a k9s plugin](#k9s-plugin)_
84+
_View instructions for: [Seeing recommendations in a UI](#free-ui-for-krr-recommendations), [Sending recommendations to Slack](#slack-notification), [Setting up KRR as a k9s plugin](#k9s-plugin), [Azure Blob Storage Export with Teams Notification](#azure-blob-teams-integration)_
8185

8286
### Features
8387

@@ -348,6 +352,43 @@ python krr.py simple --selector 'app.kubernetes.io/instance in (robusta, ingress
348352
```
349353
</details>
350354

355+
<details>
356+
<summary>Group jobs by specific labels</summary>
357+
358+
Group jobs that have specific labels into GroupedJob objects for consolidated resource recommendations. This is useful for batch jobs, data processing pipelines, or any workload where you want to analyze resource usage across multiple related jobs.
359+
360+
```sh
361+
krr simple --job-grouping-labels app,team
362+
```
363+
364+
This will:
365+
- Group jobs that have either `app` or `team` labels (or both)
366+
- Create GroupedJob objects with names like `app=frontend`, `team=backend`, etc.
367+
- Provide resource recommendations for the entire group instead of individual jobs
368+
- Jobs with the specified labels will be excluded from regular Job listing
369+
370+
You can specify multiple labels separated by commas:
371+
372+
```sh
373+
krr simple --job-grouping-labels app,team,environment
374+
```
375+
376+
Each job will be grouped by each label it has, so a job with `app=api,team=backend` will appear in both `app=api` and `team=backend` groups.
377+
378+
### Limiting how many jobs are included per group
379+
380+
Use `--job-grouping-limit <N>` to cap how many jobs are included **per group** (useful when there are many historical jobs).
381+
382+
```sh
383+
krr simple --job-grouping-labels app,team --job-grouping-limit 3
384+
```
385+
386+
* Each label group will include at most **N** jobs (e.g., the first 3 returned by the API).
387+
* Other matching jobs beyond the limit are ignored for that group.
388+
* If not specified, the default limit is **500** jobs per group.
389+
390+
</details>
391+
351392
<details>
352393
<summary>Override the kubectl context</summary>
353394

@@ -369,6 +410,7 @@ Currently KRR ships with a few formatters to represent the scan data:
369410
- `yaml`
370411
- `pprint` - data representation from python's pprint library
371412
- `csv` - export data to a csv file in the current directory
413+
- `csv-raw` - csv with raw data for calculation
372414
- `html`
373415

374416
To run a strategy with a selected formatter, add a `-f` flag. Usually this should be combined with `--fileoutput <filename>` to write clean output to file without logs:
@@ -677,6 +719,84 @@ customPlaybooks:
677719
Installation instructions: [k9s docs](https://k9scli.io/topics/plugins/)
678720
</details>
679721

722+
<details id="azure-blob-teams-integration">
723+
<summary>Azure Blob Storage Export with Microsoft Teams Notifications</summary>
724+
725+
Export KRR reports directly to Azure Blob Storage and get notified in Microsoft Teams when reports are generated.
726+
727+
![Teams Notification Screenshot][teams-screenshot]
728+
729+
### Prerequisites
730+
731+
- An Azure Storage Account with a container for storing reports
732+
- A Microsoft Teams channel with an incoming webhook configured
733+
- Azure SAS URL with write permissions to your storage container
734+
735+
### Setup
736+
737+
1. **Create Azure Storage Container**: Set up a container in your Azure Storage Account (e.g., `fileuploads`)
738+
739+
2. **Generate SAS URL**: Create a SAS URL for your container with write permissions:
740+
```bash
741+
# Example SAS URL format (replace with your actual values)
742+
https://yourstorageaccount.blob.core.windows.net/fileuploads?sv=2024-11-04&ss=bf&srt=o&sp=wactfx&se=2026-07-21T21:12:48Z&st=2025-07-21T12:57:48Z&spr=https&sig=...
743+
```
744+
745+
3. **Configure Teams Webhook**: Set up an incoming webhook in your Microsoft Teams channel (located in the Workflows tab)
746+
747+
4. **Run KRR with Azure Integration**:
748+
```bash
749+
krr simple -f html \
750+
--azurebloboutput "https://yourstorageaccount.blob.core.windows.net/fileuploads?sv=..." \
751+
--teams-webhook "https://your-teams-webhook-url" \
752+
--azure-subscription-id "your-subscription-id" \
753+
--azure-resource-group "your-resource-group"
754+
```
755+
756+
### Features
757+
758+
- **Automatic File Upload**: Reports are automatically uploaded to Azure Blob Storage with timestamped filenames
759+
- **Teams Notifications**: Rich adaptive cards are sent to Teams when reports are generated
760+
- **Direct Links**: Teams notifications include direct links to view files in Azure Portal
761+
- **Multiple Formats**: Supports all KRR output formats (JSON, CSV, HTML, YAML, etc.)
762+
- **Secure**: Uses SAS URLs for secure, time-limited access to your storage
763+
764+
### Command Options
765+
766+
| Flag | Description |
767+
|------|-------------|
768+
| `--azurebloboutput` | Azure Blob Storage SAS URL base path (make sure you include the container name; filename will be auto-appended) |
769+
| `--teams-webhook` | Microsoft Teams webhook URL for notifications |
770+
| `--azure-subscription-id` | Azure Subscription ID (for Azure Portal links in Teams) |
771+
| `--azure-resource-group` | Azure Resource Group name (for Azure Portal links in Teams) |
772+
773+
### Example Usage
774+
775+
```bash
776+
# Basic Azure Blob export
777+
krr simple -f json --azurebloboutput "https://mystorageaccount.blob.core.windows.net/reports?sv=..."
778+
779+
# With Teams notifications
780+
krr simple -f html \
781+
--azurebloboutput "https://mystorageaccount.blob.core.windows.net/reports?sv=..." \
782+
--teams-webhook "https://outlook.office.com/webhook/..." \
783+
--azure-subscription-id "12345678-1234-1234-1234-123456789012" \
784+
--azure-resource-group "my-resource-group"
785+
```
786+
787+
### Teams Notification Features
788+
789+
The Teams adaptive card includes:
790+
- 📊 Report generation announcement
791+
- Namespace and format details
792+
- Generation timestamp
793+
- Storage account and container information
794+
- Direct "View in Azure Storage" button linking to Azure Portal
795+
796+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
797+
798+
</details>
799+
680800
## Creating a Custom Strategy/Formatter
681801

682802
Look into the [examples](https://github.com/robusta-dev/krr/tree/main/examples) directory for examples on how to create a custom strategy/formatter.
@@ -763,3 +883,4 @@ If you have any questions, feel free to contact **support@robusta.dev** or messa
763883
[product-screenshot]: images/screenshot.jpeg
764884
[slack-screenshot]: images/krr_slack_example.png
765885
[ui-screenshot]: images/ui_video.gif
886+
[teams-screenshot]: images/krr_teams_example.png

conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Make sure pytest loads the asyncio plugin so `async def` tests run.
2+
pytest_plugins = ("pytest_asyncio",)

enforcer/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM python:3.12-alpine
2+
ENV LANG=C.UTF-8
3+
ENV PYTHONDONTWRITEBYTECODE=1
4+
ENV PYTHONUNBUFFERED=1
5+
ENV PATH="/app/venv/bin:$PATH"
6+
7+
# Patching CVE-2025-6965
8+
RUN apk update && apk add --no-cache --upgrade \
9+
sqlite-libs=3.49.2-r1 sqlite=3.49.2-r1
10+
11+
# Set the working directory
12+
WORKDIR /app/enforcer
13+
14+
COPY ./*.py .
15+
COPY ./dal/ dal/
16+
COPY ./resources/ resources/
17+
COPY ./requirements.txt requirements.txt
18+
19+
20+
RUN pip install --no-cache-dir --upgrade pip
21+
# Install the project dependencies
22+
RUN python -m ensurepip --upgrade
23+
RUN pip install --no-cache-dir -r requirements.txt
24+
25+
CMD ["python", "enforcer_main.py"]

0 commit comments

Comments
 (0)