From d5200141b665944220a45daafadef26b9a53368a Mon Sep 17 00:00:00 2001 From: avi robusta Date: Wed, 17 May 2023 11:45:42 +0300 Subject: added slack integration --- README.md | 35 +++++++++++++++++++++++++++++++++++ images/krr_slack_example.png | Bin 0 -> 522981 bytes 2 files changed, 35 insertions(+) create mode 100644 images/krr_slack_example.png diff --git a/README.md b/README.md index 386c04a..dc1aac0 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,40 @@ More features (like seeing graphs, based on which recommendations were made) com

(back to top)

+ + +### Slack integration + +Put cost savings on autopilot. Get notified in Slack about recommendations above X%. Send a weekly global report, or one report per team. + +![Slack Screen Shot][slack-screenshot] + +#### Prerequisites +* A Slack workspace + +#### Setup +1. [Install Robusta with Helm to your cluster and configure slack](https://docs.robusta.dev/master/installation.html) +2. Create your KRR slack playbook by adding the following to `generated_values.yaml`: +``` +customPlaybooks: +# Runs a weekly krr scan on the namespace devs-namespace and sends it to the configured slack channel +customPlaybooks: +- triggers: + - on_schedule: + fixed_delay_repeat: + repeat: 1 # number of times to run or -1 to run forever + seconds_delay: 604800 # 1 week + actions: + - krr_scan: + args: "--namespace devs-namespace" ## KRR args here + sinks: + - "main_slack_sink" # slack sink you want to send the report to here +``` + +3. Do a Helm upgrade to apply the new values: `helm upgrade robusta robusta/robusta --values=generated_values.yaml --set clusterName=` + +

(back to top)

+ ## Getting Started @@ -393,4 +427,5 @@ Project Link: [https://github.com/robusta-dev/krr](https://github.com/robusta-de [linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555 [linkedin-url]: https://linkedin.com/in/othneildrew [product-screenshot]: images/screenshot.jpeg +[slack-screenshot]: images/krr_slack_example.png [ui-screenshot]: images/ui_screenshot.jpeg diff --git a/images/krr_slack_example.png b/images/krr_slack_example.png new file mode 100644 index 0000000..f7ce498 Binary files /dev/null and b/images/krr_slack_example.png differ -- cgit v1.2.3 From f85331c7bad4f94a6b92ed66b2490271d902abf3 Mon Sep 17 00:00:00 2001 From: Ganesh Rathinavel Date: Fri, 19 May 2023 00:36:32 +0530 Subject: added victoria metrics url auto discovery --- .gitignore | 3 ++- robusta_krr/core/integrations/prometheus/loader.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2930ebe..7fa9806 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Byte-compiled / optimized / DLL files +.idea/ __pycache__/ *.py[cod] *$py.class @@ -130,4 +131,4 @@ dmypy.json .DS_Store -robusta_lib \ No newline at end of file +robusta_lib diff --git a/robusta_krr/core/integrations/prometheus/loader.py b/robusta_krr/core/integrations/prometheus/loader.py index 685dd1c..5713ca8 100644 --- a/robusta_krr/core/integrations/prometheus/loader.py +++ b/robusta_krr/core/integrations/prometheus/loader.py @@ -33,6 +33,7 @@ class PrometheusDiscovery(ServiceDiscovery): "app=prometheus-msteams", "app=rancher-monitoring-prometheus", "app=prometheus-prometheus", + "app.kubernetes.io/name=vmsingle", ], api_client=api_client, ) -- cgit v1.2.3 From cce71b0fb4274a9b0e54384726d444f080ef25cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Thu, 25 May 2023 16:36:20 +0300 Subject: Add timezone info to metric --- robusta_krr/core/integrations/prometheus/metrics/base_metric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/robusta_krr/core/integrations/prometheus/metrics/base_metric.py b/robusta_krr/core/integrations/prometheus/metrics/base_metric.py index 2751f32..bf34479 100644 --- a/robusta_krr/core/integrations/prometheus/metrics/base_metric.py +++ b/robusta_krr/core/integrations/prometheus/metrics/base_metric.py @@ -43,7 +43,7 @@ class BaseMetricLoader(Configurable, abc.ABC): self, object: K8sObjectData, period: datetime.timedelta, step: datetime.timedelta ) -> ResourceHistoryData: query = self.get_query(object) - end_time = datetime.datetime.now() + end_time = datetime.datetime.now().astimezone() metric = Metric( query=query, start_time=end_time - period, -- cgit v1.2.3 From ff3be4a24d4fdb64cd4ec0836e9917c75f964dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 11:55:15 +0300 Subject: Fix tests to work without kubeconfig --- robusta_krr/api/models.py | 6 ++- robusta_krr/core/models/objects.py | 4 +- tests/conftest.py | 80 ++++++++++++++++++++++++++++++++++++++ tests/test_krr.py | 22 +++++------ 4 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 tests/conftest.py diff --git a/robusta_krr/api/models.py b/robusta_krr/api/models.py index be2a3ad..17a4487 100644 --- a/robusta_krr/api/models.py +++ b/robusta_krr/api/models.py @@ -1,6 +1,6 @@ -from robusta_krr.core.abstract.strategies import HistoryData, ResourceRecommendation, RunResult +from robusta_krr.core.abstract.strategies import HistoryData, ResourceRecommendation, RunResult, ResourceHistoryData from robusta_krr.core.models.allocations import RecommendationValue, ResourceAllocations, ResourceType -from robusta_krr.core.models.objects import K8sObjectData +from robusta_krr.core.models.objects import K8sObjectData, PodData from robusta_krr.core.models.result import ResourceScan, Result, Severity __all__ = [ @@ -8,10 +8,12 @@ __all__ = [ "ResourceAllocations", "RecommendationValue", "K8sObjectData", + "PodData", "Result", "Severity", "ResourceScan", "ResourceRecommendation", "HistoryData", + "ResourceHistoryData", "RunResult", ] diff --git a/robusta_krr/core/models/objects.py b/robusta_krr/core/models/objects.py index 21f5d61..29ce105 100644 --- a/robusta_krr/core/models/objects.py +++ b/robusta_krr/core/models/objects.py @@ -14,12 +14,12 @@ class PodData(pd.BaseModel): class K8sObjectData(pd.BaseModel): - cluster: Optional[str] + cluster: str name: str container: str pods: list[PodData] namespace: str - kind: Optional[str] + kind: str allocations: ResourceAllocations def __str__(self) -> str: diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..ab9ca01 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,80 @@ +from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch +import pytest +import numpy as np +from datetime import datetime, timedelta +import random +from robusta_krr.api.models import K8sObjectData, PodData, ResourceAllocations, ResourceHistoryData + + +TEST_OBJECT = K8sObjectData( + cluster="mock-cluster", + name="mock-object-1", + container="mock-container-1", + pods=[ + PodData(name="mock-pod-1", deleted=False), + PodData(name="mock-pod-2", deleted=False), + PodData(name="mock-pod-3", deleted=True), + ], + namespace="default", + kind="Deployment", + allocations=ResourceAllocations( + requests={"cpu": 1, "memory": 1}, # type: ignore + limits={"cpu": 2, "memory": 2}, # type: ignore + ), +) + + +@pytest.fixture(autouse=True, scope="session") +def mock_list_clusters(): + with patch( + "robusta_krr.core.integrations.kubernetes.KubernetesLoader.list_clusters", + new=AsyncMock(return_value=[TEST_OBJECT.cluster]), + ): + yield + + +@pytest.fixture(autouse=True, scope="session") +def mock_list_scannable_objects(): + with patch( + "robusta_krr.core.integrations.kubernetes.KubernetesLoader.list_scannable_objects", + new=AsyncMock(return_value=[TEST_OBJECT]), + ): + yield + + +@pytest.fixture(autouse=True, scope="session") +def mock_config_loaded(): + with patch("robusta_krr.core.models.config.Config.config_loaded", new_callable=PropertyMock) as mock_config: + mock_config.return_value = True + yield + + +@pytest.fixture(autouse=True, scope="session") +def mock_prometheus_loader(): + now = datetime.now() + start = now - timedelta(hours=1) + now_ts, start_ts = now.timestamp(), start.timestamp() + metric_points_data = np.array([(t, random.randrange(0, 100)) for t in np.linspace(start_ts, now_ts, 3600)]) + + with patch( + "robusta_krr.core.integrations.prometheus.loader.PrometheusLoader.gather_data", + new=AsyncMock( + return_value=ResourceHistoryData( + data={pod.name: metric_points_data for pod in TEST_OBJECT.pods}, + metric={ # type: ignore + "query": f"example_promql_metric{{pod_name=~\"{'|'.join(pod.name for pod in TEST_OBJECT.pods)}\"}}", + "start_time": start, + "end_time": now, + "step": "30s", + }, + ) + ), + ) as mock_prometheus_loader: + mock_prometheus_loader + yield + + +@pytest.fixture(autouse=True, scope="session") +def mock_prometheus_init(): + with patch("robusta_krr.core.integrations.prometheus.loader.PrometheusLoader.__init__", return_value=None): + yield diff --git a/tests/test_krr.py b/tests/test_krr.py index 23dab01..f013ee4 100644 --- a/tests/test_krr.py +++ b/tests/test_krr.py @@ -1,8 +1,3 @@ -""" - Test the krr command line interface and a general execution. - Requires a running kubernetes cluster with the kubectl command configured. -""" - import json import pytest @@ -36,14 +31,19 @@ def test_run(log_flag: str): @pytest.mark.parametrize("format", ["json", "yaml", "table", "pprint"]) def test_output_formats(format: str): - result = runner.invoke(app, [STRATEGY_NAME, "-q", "-f", format, "--namespace", "default"]) + result = runner.invoke(app, [STRATEGY_NAME, "-q", "-f", format]) try: assert result.exit_code == 0, result.exc_info except AssertionError as e: raise e from result.exception - if format == "json": - assert json.loads(result.stdout), result.stdout - - if format == "yaml": - assert yaml.safe_load(result.stdout), result.stdout + try: + if format == "json": + json_output = json.loads(result.stdout) + assert json_output, result.stdout + assert len(json_output["scans"]) > 0, result.stdout + + if format == "yaml": + assert yaml.safe_load(result.stdout), result.stdout + except Exception as e: + raise Exception(result.stdout) from e -- cgit v1.2.3 From 0dea86a8970a950e7c363c232817580ad5a0921d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 11:55:25 +0300 Subject: Add CI/CD pipelines --- .github/workflows/docker-build-on-tag.yml | 27 +++++++++++++++++++++++++++ .github/workflows/pytest-on-push.yml | 27 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 .github/workflows/docker-build-on-tag.yml create mode 100644 .github/workflows/pytest-on-push.yml diff --git a/.github/workflows/docker-build-on-tag.yml b/.github/workflows/docker-build-on-tag.yml new file mode 100644 index 0000000..4dfad32 --- /dev/null +++ b/.github/workflows/docker-build-on-tag.yml @@ -0,0 +1,27 @@ +name: Docker Build and Push + +on: + push: + tags: + - '*' + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push Docker images + uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/arm64,linux/amd64 + push: true + tags: us-central1-docker.pkg.dev/genuine-flight-317411/devel/krr:${{ github.ref }} + build-args: | + BUILDKIT_INLINE_CACHE=1 diff --git a/.github/workflows/pytest-on-push.yml b/.github/workflows/pytest-on-push.yml new file mode 100644 index 0000000..f14bbd2 --- /dev/null +++ b/.github/workflows/pytest-on-push.yml @@ -0,0 +1,27 @@ +name: Pytest + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -e . + pip install pytest + + - name: Test with pytest + run: | + pytest -- cgit v1.2.3 From 4903a8c8b30622d79b44a051e3a0768eb3cfd9bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 17:26:45 +0300 Subject: Black + isort + flake8 --- robusta_krr/api/models.py | 2 +- robusta_krr/core/models/objects.py | 2 -- tests/conftest.py | 11 ++++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/robusta_krr/api/models.py b/robusta_krr/api/models.py index 17a4487..a0c4ea9 100644 --- a/robusta_krr/api/models.py +++ b/robusta_krr/api/models.py @@ -1,4 +1,4 @@ -from robusta_krr.core.abstract.strategies import HistoryData, ResourceRecommendation, RunResult, ResourceHistoryData +from robusta_krr.core.abstract.strategies import HistoryData, ResourceHistoryData, ResourceRecommendation, RunResult from robusta_krr.core.models.allocations import RecommendationValue, ResourceAllocations, ResourceType from robusta_krr.core.models.objects import K8sObjectData, PodData from robusta_krr.core.models.result import ResourceScan, Result, Severity diff --git a/robusta_krr/core/models/objects.py b/robusta_krr/core/models/objects.py index 29ce105..84e468e 100644 --- a/robusta_krr/core/models/objects.py +++ b/robusta_krr/core/models/objects.py @@ -1,5 +1,3 @@ -from typing import Optional - import pydantic as pd from robusta_krr.core.models.allocations import ResourceAllocations diff --git a/tests/conftest.py b/tests/conftest.py index ab9ca01..0617ddc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,11 @@ -from unittest.mock import AsyncMock, MagicMock, PropertyMock, patch -import pytest -import numpy as np -from datetime import datetime, timedelta import random -from robusta_krr.api.models import K8sObjectData, PodData, ResourceAllocations, ResourceHistoryData +from datetime import datetime, timedelta +from unittest.mock import AsyncMock, PropertyMock, patch +import numpy as np +import pytest + +from robusta_krr.api.models import K8sObjectData, PodData, ResourceAllocations, ResourceHistoryData TEST_OBJECT = K8sObjectData( cluster="mock-cluster", -- cgit v1.2.3 From efa6b53b6bdd0abf139bf3c36ccc56c87e6d7d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 18:40:08 +0300 Subject: Add release build for linux, fix python version at 3.9 --- .github/workflows/pytest-on-push.yml | 2 +- .github/workflows/release-with-executable.yml | 40 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release-with-executable.yml diff --git a/.github/workflows/pytest-on-push.yml b/.github/workflows/pytest-on-push.yml index f14bbd2..a867168 100644 --- a/.github/workflows/pytest-on-push.yml +++ b/.github/workflows/pytest-on-push.yml @@ -13,7 +13,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.x' + python-version: '3.9' - name: Install dependencies run: | diff --git a/.github/workflows/release-with-executable.yml b/.github/workflows/release-with-executable.yml new file mode 100644 index 0000000..18233cf --- /dev/null +++ b/.github/workflows/release-with-executable.yml @@ -0,0 +1,40 @@ +name: Build and Release + +on: + release: + types: [created] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install pyinstaller + apt-get install binutils + + - name: Build with PyInstaller + run: | + pyinstaller krr.py + zip -r ./dist/krr + + - name: Upload Release Asset + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: . + asset_name: "krr-linux-${{ github.ref }}.zip" + asset_content_type: application/octet-stream -- cgit v1.2.3 From 9349f7f2e32ae68f23015f9a0517935619618461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 18:43:36 +0300 Subject: Fix tag usage in CD pipelines --- .github/workflows/docker-build-on-tag.yml | 2 +- .github/workflows/release-with-executable.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build-on-tag.yml b/.github/workflows/docker-build-on-tag.yml index 4dfad32..71f3456 100644 --- a/.github/workflows/docker-build-on-tag.yml +++ b/.github/workflows/docker-build-on-tag.yml @@ -22,6 +22,6 @@ jobs: context: . platforms: linux/arm64,linux/amd64 push: true - tags: us-central1-docker.pkg.dev/genuine-flight-317411/devel/krr:${{ github.ref }} + tags: us-central1-docker.pkg.dev/genuine-flight-317411/devel/krr:${{ github.ref#refs/tags/ }} build-args: | BUILDKIT_INLINE_CACHE=1 diff --git a/.github/workflows/release-with-executable.yml b/.github/workflows/release-with-executable.yml index 18233cf..e7da856 100644 --- a/.github/workflows/release-with-executable.yml +++ b/.github/workflows/release-with-executable.yml @@ -27,7 +27,7 @@ jobs: - name: Build with PyInstaller run: | pyinstaller krr.py - zip -r ./dist/krr + zip -r "krr-linux-${{ github.ref#refs/tags/ }}.zip" ./dist/krr - name: Upload Release Asset uses: actions/upload-release-asset@v1.0.2 @@ -36,5 +36,5 @@ jobs: with: upload_url: ${{ github.event.release.upload_url }} asset_path: . - asset_name: "krr-linux-${{ github.ref }}.zip" + asset_name: "krr-linux-${{ github.ref#refs/tags/ }}.zip" asset_content_type: application/octet-stream -- cgit v1.2.3 From 7508a3225cf2726a967210aa089c02e83bbd170f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 18:48:33 +0300 Subject: Fix refname in CD --- .github/workflows/docker-build-on-tag.yml | 2 +- .github/workflows/release-with-executable.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build-on-tag.yml b/.github/workflows/docker-build-on-tag.yml index 71f3456..7bd866c 100644 --- a/.github/workflows/docker-build-on-tag.yml +++ b/.github/workflows/docker-build-on-tag.yml @@ -22,6 +22,6 @@ jobs: context: . platforms: linux/arm64,linux/amd64 push: true - tags: us-central1-docker.pkg.dev/genuine-flight-317411/devel/krr:${{ github.ref#refs/tags/ }} + tags: us-central1-docker.pkg.dev/genuine-flight-317411/devel/krr:${{ github.ref_name }} build-args: | BUILDKIT_INLINE_CACHE=1 diff --git a/.github/workflows/release-with-executable.yml b/.github/workflows/release-with-executable.yml index e7da856..97c022b 100644 --- a/.github/workflows/release-with-executable.yml +++ b/.github/workflows/release-with-executable.yml @@ -27,7 +27,7 @@ jobs: - name: Build with PyInstaller run: | pyinstaller krr.py - zip -r "krr-linux-${{ github.ref#refs/tags/ }}.zip" ./dist/krr + zip -r "krr-linux-${{ github.ref_name }}.zip" ./dist/krr - name: Upload Release Asset uses: actions/upload-release-asset@v1.0.2 @@ -36,5 +36,5 @@ jobs: with: upload_url: ${{ github.event.release.upload_url }} asset_path: . - asset_name: "krr-linux-${{ github.ref#refs/tags/ }}.zip" + asset_name: "krr-linux-${{ github.ref_name }}.zip" asset_content_type: application/octet-stream -- cgit v1.2.3 From d0f5c3638c27ad8d27cd801cf4ccc6099a0e1016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 19:51:27 +0300 Subject: Add auth for docker on tag --- .github/workflows/docker-build-on-tag.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/docker-build-on-tag.yml b/.github/workflows/docker-build-on-tag.yml index 7bd866c..786c82b 100644 --- a/.github/workflows/docker-build-on-tag.yml +++ b/.github/workflows/docker-build-on-tag.yml @@ -13,6 +13,14 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Authenticate with Google Cloud + uses: google-github-actions/auth@v0.4.0 + with: + credentials_json: ${{ secrets.GCP_SA_KEY }} + + - name: Docker login + run: echo "_json_key" | docker login -u _json_key --password-stdin https://us-central1-docker.pkg.dev/genuine-flight-317411 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 -- cgit v1.2.3 From 45d101032387d0dd97ef3328d59acd4813a089a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 20:03:08 +0300 Subject: Fix docker login step --- .github/workflows/docker-build-on-tag.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-build-on-tag.yml b/.github/workflows/docker-build-on-tag.yml index 786c82b..94dd4a2 100644 --- a/.github/workflows/docker-build-on-tag.yml +++ b/.github/workflows/docker-build-on-tag.yml @@ -19,7 +19,7 @@ jobs: credentials_json: ${{ secrets.GCP_SA_KEY }} - name: Docker login - run: echo "_json_key" | docker login -u _json_key --password-stdin https://us-central1-docker.pkg.dev/genuine-flight-317411 + run: echo "${{ secrets.GCP_SA_KEY }}" | docker login -u _json_key --password-stdin https://us-central1-docker.pkg.dev/genuine-flight-317411 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 -- cgit v1.2.3 From 284872c5015e5f4e476902af18460bb6c9e19fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 21:13:09 +0300 Subject: Rework setup for setup-gcloud --- .github/workflows/docker-build-on-tag.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker-build-on-tag.yml b/.github/workflows/docker-build-on-tag.yml index 94dd4a2..97829f5 100644 --- a/.github/workflows/docker-build-on-tag.yml +++ b/.github/workflows/docker-build-on-tag.yml @@ -13,13 +13,21 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Authenticate with Google Cloud - uses: google-github-actions/auth@v0.4.0 + - name: Set up gcloud CLI + uses: google-github-actions/setup-gcloud@v0.2.0 with: - credentials_json: ${{ secrets.GCP_SA_KEY }} - - - name: Docker login - run: echo "${{ secrets.GCP_SA_KEY }}" | docker login -u _json_key --password-stdin https://us-central1-docker.pkg.dev/genuine-flight-317411 + service_account_key: ${{ secrets.GCP_SA_KEY }} + project_id: genuine-flight-317411 + export_default_credentials: true + + # Configure Docker to use the gcloud command-line tool as a credential helper for authentication + - name: Configure Docker + run: |- + gcloud auth configure-docker us-central1-docker.pkg.dev + + - name: Verify gcloud configuration + run: |- + gcloud config get-value project - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 -- cgit v1.2.3 From 39ffdf8ea4c96a0971b72108dbe0f49ab528e1b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 21:26:58 +0300 Subject: Remove release pipline --- .github/workflows/release-with-executable.yml | 40 --------------------------- 1 file changed, 40 deletions(-) delete mode 100644 .github/workflows/release-with-executable.yml diff --git a/.github/workflows/release-with-executable.yml b/.github/workflows/release-with-executable.yml deleted file mode 100644 index 97c022b..0000000 --- a/.github/workflows/release-with-executable.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Build and Release - -on: - release: - types: [created] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.9' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install pyinstaller - apt-get install binutils - - - name: Build with PyInstaller - run: | - pyinstaller krr.py - zip -r "krr-linux-${{ github.ref_name }}.zip" ./dist/krr - - - name: Upload Release Asset - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: . - asset_name: "krr-linux-${{ github.ref_name }}.zip" - asset_content_type: application/octet-stream -- cgit v1.2.3 From ed73cfbd95b9222c57950ff727397e251ebca247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 23:02:47 +0300 Subject: Refactor Formatters, use functional approach --- examples/custom_formatter.py | 20 ++-- robusta_krr/api/formatters.py | 4 +- robusta_krr/core/abstract/formatters.py | 73 ++++++-------- robusta_krr/core/models/config.py | 8 +- robusta_krr/core/models/result.py | 9 +- robusta_krr/formatters/__init__.py | 8 +- robusta_krr/formatters/json.py | 22 +--- robusta_krr/formatters/pprint.py | 22 +--- robusta_krr/formatters/table.py | 171 ++++++++++++++++---------------- robusta_krr/formatters/yaml.py | 23 +---- robusta_krr/main.py | 5 +- 11 files changed, 154 insertions(+), 211 deletions(-) diff --git a/examples/custom_formatter.py b/examples/custom_formatter.py index d3cb98d..f246404 100644 --- a/examples/custom_formatter.py +++ b/examples/custom_formatter.py @@ -3,21 +3,17 @@ from __future__ import annotations import robusta_krr -from robusta_krr.api.formatters import BaseFormatter +from robusta_krr.api import formatters from robusta_krr.api.models import Result -class CustomFormatter(BaseFormatter): - # This is the name that will be used to reference the formatter in the CLI - __display_name__ = "my_formatter" - - # This will pass the result to Rich Console for formatting. - # By default, the result is passed to `print` function. - # See https://rich.readthedocs.io/en/latest/ for more info - __rich_console__ = True - - def format(self, result: Result) -> str: - return "Custom formatter" +# This is a custom formatter +# It will be available to the CLI as `my_formatter` +# Rich console will be enabled in this case, so the output will be colored and formatted +@formatters.register(rich_console=True) +def my_formatter(result: Result) -> str: + # Return custom formatter + return "Custom formatter" # Running this file will register the formatter and make it available to the CLI diff --git a/robusta_krr/api/formatters.py b/robusta_krr/api/formatters.py index 3bd6927..d942efe 100644 --- a/robusta_krr/api/formatters.py +++ b/robusta_krr/api/formatters.py @@ -1,3 +1,3 @@ -from robusta_krr.core.abstract.formatters import BaseFormatter +from robusta_krr.core.abstract.formatters import register, find, list_available -__all__ = ["BaseFormatter"] +__all__ = ["register", "find", "list_available"] diff --git a/robusta_krr/core/abstract/formatters.py b/robusta_krr/core/abstract/formatters.py index a38e9f3..3422c4d 100644 --- a/robusta_krr/core/abstract/formatters.py +++ b/robusta_krr/core/abstract/formatters.py @@ -1,62 +1,55 @@ from __future__ import annotations -import abc -import os -from typing import TYPE_CHECKING, Any, TypeVar +from typing import Any, Optional, Callable -from robusta_krr.utils.display_name import add_display_name +from robusta_krr.core.models.result import Result -if TYPE_CHECKING: - from robusta_krr.core.models.result import Result +FormatterFunc = Callable[[Result], Any] -DEFAULT_FORMATTERS_PATH = os.path.join(os.path.dirname(__file__), "formatters") +FORMATTERS_REGISTRY: dict[str, FormatterFunc] = {} -Self = TypeVar("Self", bound="BaseFormatter") +# NOTE: Here asterisk is used to make the argument `rich_console` keyword-only +# This is done to avoid the following usage, where it is unclear what the boolean value is for: +# @register("My Formatter", True) +# def my_formatter(result: Result) -> str: +# return "My formatter" +# +# Instead, the following usage is enforced: +# @register("My Formatter", rich_console=True) +# def my_formatter(result: Result) -> str: +# return "My formatter" +def register(display_name: Optional[str] = None, *, rich_console: bool = False) -> Callable[[FormatterFunc], FormatterFunc]: + """Decorator to register a formatter.""" -@add_display_name(postfix="Formatter") -class BaseFormatter(abc.ABC): - """Base class for result formatters.""" + def decorator(func: FormatterFunc) -> FormatterFunc: + name = display_name or func.__name__ - __display_name__: str - __rich_console__: bool = False + FORMATTERS_REGISTRY[name] = func - def __str__(self) -> str: - return self.__display_name__.title() + func.__display_name__ = name # type: ignore + func.__rich_console__ = rich_console # type: ignore - @abc.abstractmethod - def format(self, result: Result) -> Any: - """Format the result. + return func - Args: - result: The result to format. + return decorator - Returns: - The formatted result. - """ - @classmethod - def get_all(cls: type[Self]) -> dict[str, type[Self]]: - """Get all available formatters.""" +def find(name: str) -> FormatterFunc: + """Find a formatter by name.""" - # NOTE: Load default formatters - from robusta_krr import formatters as _ # noqa: F401 + try: + return FORMATTERS_REGISTRY[name] + except KeyError as e: + raise ValueError(f"Formatter '{name}' not found") from e - return {sub_cls.__display_name__.lower(): sub_cls for sub_cls in cls.__subclasses__()} - @staticmethod - def find(name: str) -> type[BaseFormatter]: - """Get a strategy from its name.""" +def list_available() -> list[str]: + """List available formatters.""" - formatters = BaseFormatter.get_all() + return list(FORMATTERS_REGISTRY) - l_name = name.lower() - if l_name in formatters: - return formatters[l_name] - raise ValueError(f"Unknown formatter name: {name}. Available formatters: {', '.join(formatters)}") - - -__all__ = ["BaseFormatter"] +__all__ = ["register", "find"] diff --git a/robusta_krr/core/models/config.py b/robusta_krr/core/models/config.py index ff147af..6a79a19 100644 --- a/robusta_krr/core/models/config.py +++ b/robusta_krr/core/models/config.py @@ -4,7 +4,7 @@ import pydantic as pd from kubernetes import config from kubernetes.config.config_exception import ConfigException -from robusta_krr.core.abstract.formatters import BaseFormatter +from robusta_krr.core.abstract import formatters from robusta_krr.core.abstract.strategies import AnyStrategy, BaseStrategy try: @@ -44,8 +44,8 @@ class Config(pd.BaseSettings): other_args: dict[str, Any] @property - def Formatter(self) -> type[BaseFormatter]: - return BaseFormatter.find(self.format) + def Formatter(self) -> formatters.FormatterFunc: + return formatters.find(self.format) @pd.validator("namespaces") def validate_namespaces(cls, v: Union[list[str], Literal["*"]]) -> Union[list[str], Literal["*"]]: @@ -66,7 +66,7 @@ class Config(pd.BaseSettings): @pd.validator("format") def validate_format(cls, v: str) -> str: - BaseFormatter.find(v) # NOTE: raises if strategy is not found + formatters.find(v) # NOTE: raises if strategy is not found return v @property diff --git a/robusta_krr/core/models/result.py b/robusta_krr/core/models/result.py index f3df5d7..6e860b7 100644 --- a/robusta_krr/core/models/result.py +++ b/robusta_krr/core/models/result.py @@ -7,7 +7,7 @@ from typing import Any, Optional, Union import pydantic as pd -from robusta_krr.core.abstract.formatters import BaseFormatter +from robusta_krr.core.abstract import formatters from robusta_krr.core.models.allocations import RecommendationValue, ResourceAllocations, ResourceType from robusta_krr.core.models.objects import K8sObjectData @@ -115,7 +115,7 @@ class Result(pd.BaseModel): super().__init__(*args, **kwargs) self.score = self.__calculate_score() - def format(self, formatter: Union[type[BaseFormatter], str], **kwargs: Any) -> Any: + def format(self, formatter: Union[formatters.FormatterFunc, str]) -> Any: """Format the result. Args: @@ -125,9 +125,8 @@ class Result(pd.BaseModel): The formatted result. """ - FormatterType = BaseFormatter.find(formatter) if isinstance(formatter, str) else formatter - _formatter = FormatterType(**kwargs) - return _formatter.format(self) + formatter = formatters.find(formatter) if isinstance(formatter, str) else formatter + return formatter(self) @staticmethod def __percentage_difference(current: RecommendationValue, recommended: RecommendationValue) -> float: diff --git a/robusta_krr/formatters/__init__.py b/robusta_krr/formatters/__init__.py index 0fc1c80..325cf01 100644 --- a/robusta_krr/formatters/__init__.py +++ b/robusta_krr/formatters/__init__.py @@ -1,4 +1,4 @@ -from .json import JSONFormatter -from .pprint import PPrintFormatter -from .table import TableFormatter -from .yaml import YAMLFormatter +from .json import json +from .pprint import pprint +from .table import table +from .yaml import yaml diff --git a/robusta_krr/formatters/json.py b/robusta_krr/formatters/json.py index 2c3a51e..c391da2 100644 --- a/robusta_krr/formatters/json.py +++ b/robusta_krr/formatters/json.py @@ -1,21 +1,7 @@ -from __future__ import annotations - -from robusta_krr.core.abstract.formatters import BaseFormatter +from robusta_krr.core.abstract import formatters from robusta_krr.core.models.result import Result -class JSONFormatter(BaseFormatter): - """Formatter for JSON output.""" - - __display_name__ = "json" - - def format(self, result: Result) -> str: - """Format the result as JSON. - - :param result: The results to format. - :type result: :class:`core.result.Result` - :returns: The formatted results. - :rtype: str - """ - - return result.json(indent=2) +@formatters.register() +def json(result: Result) -> str: + return result.json(indent=2) diff --git a/robusta_krr/formatters/pprint.py b/robusta_krr/formatters/pprint.py index bdfcc4c..9be637c 100644 --- a/robusta_krr/formatters/pprint.py +++ b/robusta_krr/formatters/pprint.py @@ -1,23 +1,9 @@ -from __future__ import annotations - from pprint import pformat -from robusta_krr.core.abstract.formatters import BaseFormatter +from robusta_krr.core.abstract import formatters from robusta_krr.core.models.result import Result -class PPrintFormatter(BaseFormatter): - """Formatter for object output with python's pprint module.""" - - __display_name__ = "pprint" - - def format(self, result: Result) -> str: - """Format the result using pprint.pformat(...) - - :param result: The results to format. - :type result: :class:`core.result.Result` - :returns: The formatted results. - :rtype: str - """ - - return pformat(result.dict()) +@formatters.register() +def pprint(result: Result) -> str: + return pformat(result.dict()) diff --git a/robusta_krr/formatters/table.py b/robusta_krr/formatters/table.py index 8ef1696..9776d80 100644 --- a/robusta_krr/formatters/table.py +++ b/robusta_krr/formatters/table.py @@ -1,10 +1,8 @@ -from __future__ import annotations - import itertools from rich.table import Table -from robusta_krr.core.abstract.formatters import BaseFormatter +from robusta_krr.core.abstract import formatters from robusta_krr.core.models.allocations import RecommendationValue from robusta_krr.core.models.result import ResourceScan, ResourceType, Result from robusta_krr.utils import resource_units @@ -13,88 +11,85 @@ NONE_LITERAL = "unset" NAN_LITERAL = "?" -class TableFormatter(BaseFormatter): - """Formatter for text output.""" - - __display_name__ = "table" - __rich_console__ = True - - def _format(self, value: RecommendationValue) -> str: - if value is None: - return NONE_LITERAL - elif isinstance(value, str): - return NAN_LITERAL - else: - return resource_units.format(value) - - def _format_request_str(self, item: ResourceScan, resource: ResourceType, selector: str) -> str: - allocated = getattr(item.object.allocations, selector)[resource] - recommended = getattr(item.recommended, selector)[resource] - severity = recommended.severity - - return ( - f"[{severity.color}]" - + self._format(allocated) - + " -> " - + self._format(recommended.value) - + f"[/{severity.color}]" - ) - - def format(self, result: Result) -> Table: - """Format the result as text. - - :param result: The result to format. - :type result: :class:`core.result.Result` - :returns: The formatted results. - :rtype: str - """ - - table = Table( - show_header=True, - header_style="bold magenta", - title=f"\n{result.description}\n" if result.description else None, - title_justify="left", - title_style="", - # TODO: Fix points calculation at [MAIN-270] - # caption=f"Scan result ({result.score} points)", - ) - - table.add_column("Number", justify="right", no_wrap=True) - table.add_column("Cluster", style="cyan") - table.add_column("Namespace", style="cyan") - table.add_column("Name", style="cyan") - table.add_column("Pods", style="cyan") - table.add_column("Old Pods", style="cyan") - table.add_column("Type", style="cyan") - table.add_column("Container", style="cyan") - for resource in ResourceType: - table.add_column(f"{resource.name} Requests") - table.add_column(f"{resource.name} Limits") - - for _, group in itertools.groupby( - enumerate(result.scans), key=lambda x: (x[1].object.cluster, x[1].object.namespace, x[1].object.name) - ): - group_items = list(group) - - for j, (i, item) in enumerate(group_items): - last_row = j == len(group_items) - 1 - full_info_row = j == 0 - - table.add_row( - f"[{item.severity.color}]{i + 1}.[/{item.severity.color}]", - item.object.cluster if full_info_row else "", - item.object.namespace if full_info_row else "", - item.object.name if full_info_row else "", - f"{item.object.current_pods_count}" if full_info_row else "", - f"{item.object.deleted_pods_count}" if full_info_row else "", - item.object.kind if full_info_row else "", - item.object.container, - *[ - self._format_request_str(item, resource, selector) - for resource in ResourceType - for selector in ["requests", "limits"] - ], - end_section=last_row, - ) - - return table +def _format(value: RecommendationValue) -> str: + if value is None: + return NONE_LITERAL + elif isinstance(value, str): + return NAN_LITERAL + else: + return resource_units.format(value) + + +def _format_request_str(item: ResourceScan, resource: ResourceType, selector: str) -> str: + allocated = getattr(item.object.allocations, selector)[resource] + recommended = getattr(item.recommended, selector)[resource] + severity = recommended.severity + + return ( + f"[{severity.color}]" + + _format(allocated) + + " -> " + + _format(recommended.value) + + f"[/{severity.color}]" + ) + + +@formatters.register(rich_console=True) +def table(result: Result) -> Table: + """Format the result as text. + + :param result: The result to format. + :type result: :class:`core.result.Result` + :returns: The formatted results. + :rtype: str + """ + + table = Table( + show_header=True, + header_style="bold magenta", + title=f"\n{result.description}\n" if result.description else None, + title_justify="left", + title_style="", + # TODO: Fix points calculation at [MAIN-270] + # caption=f"Scan result ({result.score} points)", + ) + + table.add_column("Number", justify="right", no_wrap=True) + table.add_column("Cluster", style="cyan") + table.add_column("Namespace", style="cyan") + table.add_column("Name", style="cyan") + table.add_column("Pods", style="cyan") + table.add_column("Old Pods", style="cyan") + table.add_column("Type", style="cyan") + table.add_column("Container", style="cyan") + for resource in ResourceType: + table.add_column(f"{resource.name} Requests") + table.add_column(f"{resource.name} Limits") + + for _, group in itertools.groupby( + enumerate(result.scans), key=lambda x: (x[1].object.cluster, x[1].object.namespace, x[1].object.name) + ): + group_items = list(group) + + for j, (i, item) in enumerate(group_items): + last_row = j == len(group_items) - 1 + full_info_row = j == 0 + + table.add_row( + f"[{item.severity.color}]{i + 1}.[/{item.severity.color}]", + item.object.cluster if full_info_row else "", + item.object.namespace if full_info_row else "", + item.object.name if full_info_row else "", + f"{item.object.current_pods_count}" if full_info_row else "", + f"{item.object.deleted_pods_count}" if full_info_row else "", + item.object.kind if full_info_row else "", + item.object.container, + *[ + _format_request_str(item, resource, selector) + for resource in ResourceType + for selector in ["requests", "limits"] + ], + end_section=last_row, + ) + + return table diff --git a/robusta_krr/formatters/yaml.py b/robusta_krr/formatters/yaml.py index c494bc1..37a030c 100644 --- a/robusta_krr/formatters/yaml.py +++ b/robusta_krr/formatters/yaml.py @@ -1,24 +1,11 @@ -from __future__ import annotations - import json -import yaml +import yaml as yaml_module -from robusta_krr.core.abstract.formatters import BaseFormatter +from robusta_krr.core.abstract import formatters from robusta_krr.core.models.result import Result -class YAMLFormatter(BaseFormatter): - """Formatter for YAML output.""" - - __display_name__ = "yaml" - - def format(self, result: Result) -> str: - """Format the result as YAML. - - :param result: The results to format. - :type result: :class:`core.result.Result` - :returns: The formatted results. - :rtype: str - """ - return yaml.dump(json.loads(result.json()), sort_keys=False) +@formatters.register() +def yaml(result: Result) -> str: + return yaml_module.dump(json.loads(result.json()), sort_keys=False) diff --git a/robusta_krr/main.py b/robusta_krr/main.py index fdd654d..1734788 100644 --- a/robusta_krr/main.py +++ b/robusta_krr/main.py @@ -9,8 +9,9 @@ from uuid import UUID import typer import urllib3 -from robusta_krr.core.abstract.formatters import BaseFormatter +from robusta_krr import formatters as concrete_formatters # noqa: F401 from robusta_krr.core.abstract.strategies import AnyStrategy, BaseStrategy +from robusta_krr.core.abstract import formatters from robusta_krr.core.models.config import Config from robusta_krr.core.runner import Runner from robusta_krr.utils.version import get_version @@ -115,7 +116,7 @@ def load_commands() -> None: f"'{field_name}': {field_name}" for field_name in strategy_type.get_settings_type().__fields__ ) + "}", - formatters=", ".join(BaseFormatter.get_all()), + formatters=", ".join(formatters.list_available()), ), globals() | {strategy.__name__: strategy for strategy in AnyStrategy.get_all().values()} # Defined strategies -- cgit v1.2.3 From 6abd673bfdb11e81cf857fd2e0d7721d4e0cc93f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Fri, 26 May 2023 23:24:07 +0300 Subject: Improve docstrings and comments --- robusta_krr/core/abstract/formatters.py | 31 ++++++++++++++++-- robusta_krr/core/abstract/strategies.py | 57 +++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 10 deletions(-) diff --git a/robusta_krr/core/abstract/formatters.py b/robusta_krr/core/abstract/formatters.py index 3422c4d..b47d1e1 100644 --- a/robusta_krr/core/abstract/formatters.py +++ b/robusta_krr/core/abstract/formatters.py @@ -22,7 +22,16 @@ FORMATTERS_REGISTRY: dict[str, FormatterFunc] = {} # return "My formatter" def register(display_name: Optional[str] = None, *, rich_console: bool = False) -> Callable[[FormatterFunc], FormatterFunc]: - """Decorator to register a formatter.""" + """ + A decorator to register a formatter function. + + Args: + display_name (str, optional): The name to use for the formatter in the registry. + rich_console (bool): Whether or not the formatter is for a rich console. Defaults to False. + + Returns: + Callable[[FormatterFunc], FormatterFunc]: The decorator function. + """ def decorator(func: FormatterFunc) -> FormatterFunc: name = display_name or func.__name__ @@ -38,7 +47,18 @@ def register(display_name: Optional[str] = None, *, rich_console: bool = False) def find(name: str) -> FormatterFunc: - """Find a formatter by name.""" + """ + Find a formatter by name in the registry. + + Args: + name (str): The name of the formatter. + + Returns: + FormatterFunc: The formatter function. + + Raises: + ValueError: If a formatter with the given name does not exist. + """ try: return FORMATTERS_REGISTRY[name] @@ -47,7 +67,12 @@ def find(name: str) -> FormatterFunc: def list_available() -> list[str]: - """List available formatters.""" + """ + List available formatters in the registry. + + Returns: + list[str]: A list of the names of the available formatters. + """ return list(FORMATTERS_REGISTRY) diff --git a/robusta_krr/core/abstract/strategies.py b/robusta_krr/core/abstract/strategies.py index 4f70e89..e97c408 100644 --- a/robusta_krr/core/abstract/strategies.py +++ b/robusta_krr/core/abstract/strategies.py @@ -16,6 +16,12 @@ SelfRR = TypeVar("SelfRR", bound="ResourceRecommendation") class ResourceRecommendation(pd.BaseModel): + """A class to represent resource recommendation with optional request and limit values. + + The NaN values are used to represent undefined values: the strategy did not provide a recommendation for the resource. + None values are used to represent the strategy says that value should not be set. + """ + request: Optional[float] limit: Optional[float] @@ -25,6 +31,15 @@ class ResourceRecommendation(pd.BaseModel): class StrategySettings(pd.BaseModel): + """A class to represent strategy settings with configurable history and timeframe duration. + + It is used in CLI to generate the help, parameters and validate values. + Description is used to generate the help. + Other pydantic features can be used to validate the values. + + Nested classes are not supported here. + """ + history_duration: float = pd.Field( 24 * 7 * 2, ge=1, description="The duration of the history data to use (in hours)." ) @@ -39,14 +54,19 @@ class StrategySettings(pd.BaseModel): return datetime.timedelta(minutes=self.timeframe_duration) -_StrategySettings = TypeVar("_StrategySettings", bound=StrategySettings) - +# A type alias for a numpy array of shape (N, 2). ArrayNx2 = Annotated[NDArray[np.float64], Literal["N", 2]] class ResourceHistoryData(pd.BaseModel): + """A class to represent resource history data. + + metric is the metric information used to gather the history data. + data is a mapping from pod to a numpy array of time and value. + """ + metric: Metric - data: dict[str, ArrayNx2] # Mapping: pod -> (time, value) + data: dict[str, ArrayNx2] # Mapping: pod -> [(time, value)] class Config: arbitrary_types_allowed = True @@ -56,10 +76,30 @@ HistoryData = dict[ResourceType, ResourceHistoryData] RunResult = dict[ResourceType, ResourceRecommendation] SelfBS = TypeVar("SelfBS", bound="BaseStrategy") +_StrategySettings = TypeVar("_StrategySettings", bound=StrategySettings) +# An abstract base class for strategy implementation. +# This class requires implementation of a 'run' method for calculating recommendation. +# Make a subclass if you want to create a concrete strategy. @add_display_name(postfix="Strategy") class BaseStrategy(abc.ABC, Generic[_StrategySettings]): + """An abstract base class for strategy implementation. + + This class is generic, and requires a type for the settings. + This settings type will be used for the settings property of the strategy. + It will be used to generate CLI parameters for this strategy, validated by pydantic. + + This class requires implementation of a 'run' method for calculating recommendation. + Additionally, it provides a 'description' property for generating a description for the strategy. + Description property uses the docstring of the strategy class and the settings of the strategy. + + The name of the strategy is the name of the class in lowercase, without the 'Strategy' suffix, if exists. + If you want to change the name of the strategy, you can change the __display_name__ attribute. + + The strategy will automatically be registered in the strategy registry using __subclasses__ mechanism. + """ + __display_name__: str settings: _StrategySettings @@ -83,27 +123,29 @@ class BaseStrategy(abc.ABC, Generic[_StrategySettings]): return f"[b]{self} Strategy[/b]\n\n" + dedent(self.__doc__.format_map(self.settings.dict())).strip() + # Abstract method that needs to be implemented by subclass. + # This method is intended to calculate resource recommendation based on history data and kubernetes object data. @abc.abstractmethod def run(self, history_data: HistoryData, object_data: K8sObjectData) -> RunResult: - """Run the strategy to calculate the recommendation""" + pass + # This method is intended to return a strategy by its name. @classmethod def find(cls: type[SelfBS], name: str) -> type[SelfBS]: - """Get a strategy from its name.""" - strategies = cls.get_all() if name.lower() in strategies: return strategies[name.lower()] raise ValueError(f"Unknown strategy name: {name}. Available strategies: {', '.join(strategies)}") + # This method is intended to return all the available strategies. @classmethod def get_all(cls: type[SelfBS]) -> dict[str, type[SelfBS]]: - # NOTE: Load default formatters from robusta_krr import strategies as _ # noqa: F401 return {sub_cls.__display_name__.lower(): sub_cls for sub_cls in cls.__subclasses__()} + # This method is intended to return the type of settings used in strategy. @classmethod def get_settings_type(cls) -> type[StrategySettings]: return get_args(cls.__orig_bases__[0])[0] # type: ignore @@ -111,6 +153,7 @@ class BaseStrategy(abc.ABC, Generic[_StrategySettings]): AnyStrategy = BaseStrategy[StrategySettings] + __all__ = [ "AnyStrategy", "BaseStrategy", -- cgit v1.2.3 From 38716e99b15a43274db1a8c512cb82ced1708990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 00:05:01 +0300 Subject: Add more documentation --- robusta_krr/core/abstract/strategies.py | 4 ++-- robusta_krr/utils/configurable.py | 4 +++- robusta_krr/utils/display_name.py | 23 +++++++++++++++++------ robusta_krr/utils/progress_bar.py | 7 +++++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/robusta_krr/core/abstract/strategies.py b/robusta_krr/core/abstract/strategies.py index e97c408..b0d9bf4 100644 --- a/robusta_krr/core/abstract/strategies.py +++ b/robusta_krr/core/abstract/strategies.py @@ -10,7 +10,7 @@ import pydantic as pd from numpy.typing import NDArray from robusta_krr.core.models.result import K8sObjectData, Metric, ResourceType -from robusta_krr.utils.display_name import add_display_name +from robusta_krr.utils.display_name import display_name_property SelfRR = TypeVar("SelfRR", bound="ResourceRecommendation") @@ -82,7 +82,7 @@ _StrategySettings = TypeVar("_StrategySettings", bound=StrategySettings) # An abstract base class for strategy implementation. # This class requires implementation of a 'run' method for calculating recommendation. # Make a subclass if you want to create a concrete strategy. -@add_display_name(postfix="Strategy") +@display_name_property(suffix="Strategy") class BaseStrategy(abc.ABC, Generic[_StrategySettings]): """An abstract base class for strategy implementation. diff --git a/robusta_krr/utils/configurable.py b/robusta_krr/utils/configurable.py index 4777a9c..c2b2465 100644 --- a/robusta_krr/utils/configurable.py +++ b/robusta_krr/utils/configurable.py @@ -10,7 +10,9 @@ from robusta_krr.core.models.config import Config class Configurable(abc.ABC): """ A class that can be configured with a Config object. - Opens the possibility to use echo and debug methods + Opens the possibility to use custom logging methods, that can be configured with the Config object. + + Also makes a `console` attribute available, which is a rich console. """ def __init__(self, config: Config) -> None: diff --git a/robusta_krr/utils/display_name.py b/robusta_krr/utils/display_name.py index 9082fc0..69541ae 100644 --- a/robusta_krr/utils/display_name.py +++ b/robusta_krr/utils/display_name.py @@ -1,16 +1,27 @@ -from typing import Callable, TypeVar +from typing import Callable, TypeVar, Any _T = TypeVar("_T") -def add_display_name(*, postfix: str) -> Callable[[type[_T]], type[_T]]: - """Add a decorator factory to add __display_name__ property to the class.""" +def display_name_property(*, suffix: str) -> Callable[[type[_T]], type[_T]]: + """Add a decorator factory to add __display_name__ property to the class. + + It is a utility function for BaseStrategy. + It makes a __display_name__ property for the class, that uses the name of the class. + By default, it will remove the suffix from the name of the class. + For example, if the name of the class is 'MyStrategy', the __display_name__ property will be 'My'. + If the name of the class is 'Foo', the __display_name__ property will be 'Foo', because it does not end with 'Strategy'. + + If you then override the __display_name__ property, it will be used instead of the default one. + """ def decorator(cls: type[_T]) -> type[_T]: class DisplayNameProperty: - def __get__(self, instance, owner): - if owner.__name__.lower().endswith(postfix.lower()): - return owner.__name__[: -len(postfix)] + # This is a descriptor that returns the name of the class. + # It is used to generate the __display_name__ property. + def __get__(self, instance: Any, owner: type[_T]) -> str: + if owner.__name__.lower().endswith(suffix.lower()): + return owner.__name__[: -len(suffix)] return owner.__name__ diff --git a/robusta_krr/utils/progress_bar.py b/robusta_krr/utils/progress_bar.py index 808a380..32bf211 100644 --- a/robusta_krr/utils/progress_bar.py +++ b/robusta_krr/utils/progress_bar.py @@ -5,6 +5,13 @@ from robusta_krr.utils.configurable import Configurable class ProgressBar(Configurable): + """ + Progress bar for displaying progress of gathering recommendations. + + Use `ProgressBar` as a context manager to automatically handle the progress bar. + Use `progress` method to step the progress bar. + """ + def __init__(self, config: Config, **kwargs) -> None: super().__init__(config) self.show_bar = self.echo_active -- cgit v1.2.3 From a562d52986aaec384e4363699e3b97c85d6318f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 00:05:46 +0300 Subject: Fix version literal inside the code --- pyproject.toml | 2 +- robusta_krr/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fe9317c..d6db5aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "robusta-krr" -version = "1.0.0" +version = "1.1.1" description = "Robusta's Resource Recommendation engine for Kubernetes" authors = ["Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com>"] license = "MIT" diff --git a/robusta_krr/__init__.py b/robusta_krr/__init__.py index 3417aa1..cc72604 100644 --- a/robusta_krr/__init__.py +++ b/robusta_krr/__init__.py @@ -1,4 +1,4 @@ from .main import run -__version__ = "1.0.0" +__version__ = "1.1.1" __all__ = ["run", "__version__"] -- cgit v1.2.3 From b266535f06ab7e2955e16d1e1dc7676db53e0d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 00:41:35 +0300 Subject: Add even more documentation in code --- robusta_krr/core/integrations/prometheus/loader.py | 61 +++++++++++++++++- .../prometheus/metrics/base_filtered_metric.py | 1 - .../integrations/prometheus/metrics/base_metric.py | 74 +++++++++++++++++++++- 3 files changed, 133 insertions(+), 3 deletions(-) diff --git a/robusta_krr/core/integrations/prometheus/loader.py b/robusta_krr/core/integrations/prometheus/loader.py index 1f0c14e..a687ddb 100644 --- a/robusta_krr/core/integrations/prometheus/loader.py +++ b/robusta_krr/core/integrations/prometheus/loader.py @@ -20,7 +20,20 @@ from .metrics import BaseMetricLoader class PrometheusDiscovery(ServiceDiscovery): + """ + Service discovery for Prometheus. + """ + def find_prometheus_url(self, *, api_client: Optional[ApiClient] = None) -> Optional[str]: + """ + Finds the Prometheus URL using selectors. + + Args: + api_client (Optional[ApiClient]): A Kubernetes API client. Defaults to None. + + Returns: + Optional[str]: The discovered Prometheus URL, or None if not found. + """ return super().find_url( selectors=[ "app=kube-prometheus-stack-prometheus", @@ -36,10 +49,18 @@ class PrometheusDiscovery(ServiceDiscovery): class PrometheusNotFound(Exception): + """ + An exception raised when Prometheus is not found. + """ + pass class CustomPrometheusConnect(PrometheusConnect): + """ + Custom PrometheusConnect class to handle retries. + """ + @no_type_check def __init__( self, @@ -55,12 +76,24 @@ class CustomPrometheusConnect(PrometheusConnect): class PrometheusLoader(Configurable): + """ + A loader class for fetching metrics from Prometheus. + """ + def __init__( self, config: Config, *, cluster: Optional[str] = None, ) -> None: + """ + Initializes the Prometheus Loader. + + Args: + config (Config): The configuration object. + cluster (Optional[str]): The name of the cluster. Defaults to None. + """ + super().__init__(config=config) self.info(f"Connecting to Prometheus for {cluster or 'default'} cluster") @@ -93,6 +126,13 @@ class PrometheusLoader(Configurable): self.info(f"Prometheus connected successfully for {cluster or 'default'} cluster") def _check_prometheus_connection(self): + """ + Checks the connection to Prometheus. + + Raises: + PrometheusNotFound: If the connection to Prometheus cannot be established. + """ + try: response = self.prometheus._session.get( f"{self.prometheus.url}/api/v1/query", @@ -115,6 +155,19 @@ class PrometheusLoader(Configurable): *, step: datetime.timedelta = datetime.timedelta(minutes=30), ) -> ResourceHistoryData: + """ + Gathers data from Prometheus for a specified object and resource. + + Args: + object (K8sObjectData): The Kubernetes object. + resource (ResourceType): The resource type. + period (datetime.timedelta): The time period for which to gather data. + step (datetime.timedelta, optional): The time step between data points. Defaults to 30 minutes. + + Returns: + ResourceHistoryData: The gathered resource history data. + """ + self.debug(f"Gathering data for {object} and {resource}") await self.add_historic_pods(object, period) @@ -124,7 +177,13 @@ class PrometheusLoader(Configurable): return await metric_loader.load_data(object, period, step) async def add_historic_pods(self, object: K8sObjectData, period: datetime.timedelta) -> None: - """Find pods that were already deleted, but still have some metrics in Prometheus""" + """ + Finds pods that have been deleted but still have some metrics in Prometheus. + + Args: + object (K8sObjectData): The Kubernetes object. + period (datetime.timedelta): The time period for which to gather data. + """ if len(object.pods) == 0: return diff --git a/robusta_krr/core/integrations/prometheus/metrics/base_filtered_metric.py b/robusta_krr/core/integrations/prometheus/metrics/base_filtered_metric.py index 9ede988..6a4d964 100644 --- a/robusta_krr/core/integrations/prometheus/metrics/base_filtered_metric.py +++ b/robusta_krr/core/integrations/prometheus/metrics/base_filtered_metric.py @@ -22,7 +22,6 @@ class BaseFilteredMetricLoader(BaseMetricLoader): return series["metric"][label] return None - # TODO: Rework this, as now our query can return multiple metrics for different pods @staticmethod def filter_prom_jobs_results( series_list_result: list[PrometheusSeries], diff --git a/robusta_krr/core/integrations/prometheus/metrics/base_metric.py b/robusta_krr/core/integrations/prometheus/metrics/base_metric.py index bf34479..a0731c5 100644 --- a/robusta_krr/core/integrations/prometheus/metrics/base_metric.py +++ b/robusta_krr/core/integrations/prometheus/metrics/base_metric.py @@ -15,22 +15,59 @@ from robusta_krr.utils.configurable import Configurable if TYPE_CHECKING: from ..loader import CustomPrometheusConnect +# A registry of metrics that can be used to fetch a corresponding metric loader. REGISTERED_METRICS: dict[str, type[BaseMetricLoader]] = {} class BaseMetricLoader(Configurable, abc.ABC): + """ + Base class for all metric loaders. + + Metric loaders are used to load metrics from a specified source (like Prometheus in this case). + """ + def __init__(self, config: Config, prometheus: CustomPrometheusConnect) -> None: super().__init__(config) self.prometheus = prometheus @abc.abstractmethod def get_query(self, object: K8sObjectData) -> str: - ... + """ + This method should be implemented by all subclasses to provide a query string to fetch metrics. + + Args: + object (K8sObjectData): The object for which metrics need to be fetched. + + Returns: + str: The query string. + """ + + pass def _step_to_string(self, step: datetime.timedelta) -> str: + """ + Converts step in datetime.timedelta format to a string format used by Prometheus. + + Args: + step (datetime.timedelta): Step size in datetime.timedelta format. + + Returns: + str: Step size in string format used by Prometheus. + """ + return f"{int(step.total_seconds()) // 60}m" async def query_prometheus(self, metric: Metric) -> list[dict]: + """ + Asynchronous method that queries Prometheus to fetch metrics. + + Args: + metric (Metric): An instance of the Metric class specifying what metrics to fetch. + + Returns: + list[dict]: A list of dictionary where each dictionary represents metrics for a pod. + """ + return await asyncio.to_thread( self.prometheus.custom_query_range, query=metric.query, @@ -42,6 +79,18 @@ class BaseMetricLoader(Configurable, abc.ABC): async def load_data( self, object: K8sObjectData, period: datetime.timedelta, step: datetime.timedelta ) -> ResourceHistoryData: + """ + Asynchronous method that loads metric data for a specific object. + + Args: + object (K8sObjectData): The object for which metrics need to be loaded. + period (datetime.timedelta): The time period for which metrics need to be loaded. + step (datetime.timedelta): The time interval between successive metric values. + + Returns: + ResourceHistoryData: An instance of the ResourceHistoryData class representing the loaded metrics. + """ + query = self.get_query(object) end_time = datetime.datetime.now().astimezone() metric = Metric( @@ -65,6 +114,19 @@ class BaseMetricLoader(Configurable, abc.ABC): @staticmethod def get_by_resource(resource: str) -> type[BaseMetricLoader]: + """ + Fetches the metric loader corresponding to the specified resource. + + Args: + resource (str): The name of the resource. + + Returns: + type[BaseMetricLoader]: The class of the metric loader corresponding to the resource. + + Raises: + KeyError: If the specified resource is not registered. + """ + try: return REGISTERED_METRICS[resource] except KeyError as e: @@ -75,6 +137,16 @@ Self = TypeVar("Self", bound=BaseMetricLoader) def bind_metric(resource: str) -> Callable[[type[Self]], type[Self]]: + """ + A decorator that binds a metric loader to a resource. + + Args: + resource (str): The name of the resource. + + Returns: + Callable[[type[Self]], type[Self]]: The decorator that does the binding. + """ + def decorator(cls: type[Self]) -> type[Self]: REGISTERED_METRICS[resource] = cls return cls -- cgit v1.2.3 From 6605f8089d36b0c9f19b03527db0d6b38bdb2283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 16:41:06 +0300 Subject: Add the build with pyinstaller on release pipeline --- .github/workflows/build-on-release.yml | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/build-on-release.yml diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml new file mode 100644 index 0000000..26b2c55 --- /dev/null +++ b/.github/workflows/build-on-release.yml @@ -0,0 +1,69 @@ +name: Build and Release + +on: + release: + types: [created] + +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install pyinstaller + + - name: Install dependancies (Linux) + if: matrix.os == 'ubuntu-latest' + run: | + apt-get install -y binutils + + - name: Build with PyInstaller + run: | + pyinstaller krr.py + + - name: Sign the application + run: | + echo "${{ secrets.APPLE_DEV_PASSWORD }}" | xcrun altool --store-password-in-keychain-item "AC_PASSWORD" + codesign --force --options runtime --sign "Developer ID Application: pavel@robusta.dev" dist/your_script + + # - name: Sign the application (macOS) + # if: matrix.os == 'macos-latest' + # run: | + # security create-keychain -p "" build + # security import ./cert.p12 -k build -P ${{ secrets.CERT_PASSWORD }} -T /usr/bin/codesign + # security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k build build + # codesign -s "Developer ID Application: Your Name (XXXXXX)" --timestamp --options runtime ./dist/krr/krr + + - name: Sign the application + if: matrix.os == 'macos-latest' + run: | + echo "${{ secrets.APPLE_DEV_PASSWORD }}" | xcrun altool --store-password-in-keychain-item "AC_PASSWORD" + codesign --force --options runtime --sign "Developer ID Application: pavel@robusta.dev" dist/krr/krr + + - name: Zip the application + run: | + zip -r krr-${{ matrix.os }}-${{ github.ref_name }}.zip dist/krr + + - name: Upload Release Asset + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: . + asset_name: krr-${{ matrix.os }}-${{ github.ref_name }}.zip + asset_content_type: application/octet-stream -- cgit v1.2.3 From b6f5ab144a87c79c7bdcdea32807d3ee4f515e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 17:14:55 +0300 Subject: Fix signing step --- .github/workflows/build-on-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 26b2c55..9102854 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -38,7 +38,7 @@ jobs: - name: Sign the application run: | echo "${{ secrets.APPLE_DEV_PASSWORD }}" | xcrun altool --store-password-in-keychain-item "AC_PASSWORD" - codesign --force --options runtime --sign "Developer ID Application: pavel@robusta.dev" dist/your_script + codesign --force --options runtime --sign "Developer ID Application: pavel@robusta.dev" dist/krr/krr # - name: Sign the application (macOS) # if: matrix.os == 'macos-latest' -- cgit v1.2.3 From 945262ba65c23c4e9919e9d2e5ebfa5666b54286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 17:21:07 +0300 Subject: Remove not needed steps from build-on-release --- .github/workflows/build-on-release.yml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 9102854..2a0a238 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -35,19 +35,6 @@ jobs: run: | pyinstaller krr.py - - name: Sign the application - run: | - echo "${{ secrets.APPLE_DEV_PASSWORD }}" | xcrun altool --store-password-in-keychain-item "AC_PASSWORD" - codesign --force --options runtime --sign "Developer ID Application: pavel@robusta.dev" dist/krr/krr - - # - name: Sign the application (macOS) - # if: matrix.os == 'macos-latest' - # run: | - # security create-keychain -p "" build - # security import ./cert.p12 -k build -P ${{ secrets.CERT_PASSWORD }} -T /usr/bin/codesign - # security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k build build - # codesign -s "Developer ID Application: Your Name (XXXXXX)" --timestamp --options runtime ./dist/krr/krr - - name: Sign the application if: matrix.os == 'macos-latest' run: | -- cgit v1.2.3 From 462fd6be497e3ac9a115fc54b18ac8a478f6638b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 18:05:36 +0300 Subject: Fix linux install binutils step --- .github/workflows/build-on-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 2a0a238..619d8e1 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -29,7 +29,7 @@ jobs: - name: Install dependancies (Linux) if: matrix.os == 'ubuntu-latest' run: | - apt-get install -y binutils + sudo apt-get install -y binutils - name: Build with PyInstaller run: | -- cgit v1.2.3 From 8b7abd743f64e22b61c9ce1ad13353d40c4a55ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 18:44:27 +0300 Subject: Fix Upload and macos signing --- .github/workflows/build-on-release.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 619d8e1..93d8d47 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -37,9 +37,10 @@ jobs: - name: Sign the application if: matrix.os == 'macos-latest' + env: + APPLE_DEV_PASSWORD: ${{ secrets.APPLE_DEV_PASSWORD }} run: | - echo "${{ secrets.APPLE_DEV_PASSWORD }}" | xcrun altool --store-password-in-keychain-item "AC_PASSWORD" - codesign --force --options runtime --sign "Developer ID Application: pavel@robusta.dev" dist/krr/krr + codesign --force --options runtime --sign "Developer ID Application: pavel@robusta.dev" --keychain-password "$APPLE_DEV_PASSWORD" dist/krr/krr - name: Zip the application run: | @@ -51,6 +52,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ github.event.release.upload_url }} - asset_path: . + asset_path: ./krr-${{ matrix.os }}-${{ github.ref_name }}.zip asset_name: krr-${{ matrix.os }}-${{ github.ref_name }}.zip asset_content_type: application/octet-stream -- cgit v1.2.3 From a953146ef1e995b2cc3eb16e981ca8a7947060fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 19:21:58 +0300 Subject: Rework apple certificate, add grapheme fix --- .github/workflows/build-on-release.yml | 44 ++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 93d8d47..6d983cf 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -31,16 +31,40 @@ jobs: run: | sudo apt-get install -y binutils - - name: Build with PyInstaller - run: | - pyinstaller krr.py - - - name: Sign the application + - name: Install the Apple certificate and provisioning profile if: matrix.os == 'macos-latest' env: - APPLE_DEV_PASSWORD: ${{ secrets.APPLE_DEV_PASSWORD }} + BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }} + P12_PASSWORD: ${{ secrets.P12_PASSWORD }} + BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }} + KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} + run: | + # create variables + CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 + PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision + KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db + + # import certificate and provisioning profile from secrets + echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH + echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode -o $PP_PATH + + # create temporary keychain + security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH + security set-keychain-settings -lut 21600 $KEYCHAIN_PATH + security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH + + # import certificate to keychain + security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH + security list-keychain -d user -s $KEYCHAIN_PATH + + # apply provisioning profile + mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles + cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles + + - name: Build with PyInstaller run: | - codesign --force --options runtime --sign "Developer ID Application: pavel@robusta.dev" --keychain-password "$APPLE_DEV_PASSWORD" dist/krr/krr + pyinstaller krr.py + ${{ fromJSON('{"ubuntu-latest":"cp","macos-latest":"cp","windows-latest":"copy"}')[matrix.os] || matrix.os }} $(python3.9 -c "import grapheme; print(grapheme.__path__[0] + '/data/grapheme_break_property.json')") ./dist/krr/grapheme/data/grapheme_break_property.json - name: Zip the application run: | @@ -55,3 +79,9 @@ jobs: asset_path: ./krr-${{ matrix.os }}-${{ github.ref_name }}.zip asset_name: krr-${{ matrix.os }}-${{ github.ref_name }}.zip asset_content_type: application/octet-stream + + - name: Clean up keychain and provisioning profile + if: (matrix.os == 'macos-latest') && always() + run: | + security delete-keychain $RUNNER_TEMP/app-signing.keychain-db + rm ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision -- cgit v1.2.3 From 4e80580b248c783dd530396564bcfcf3244bd729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 19:42:56 +0300 Subject: Fix windows build, add mkdir --- .github/workflows/build-on-release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 6d983cf..a569e8a 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -62,11 +62,14 @@ jobs: cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles - name: Build with PyInstaller + shell: bash run: | pyinstaller krr.py - ${{ fromJSON('{"ubuntu-latest":"cp","macos-latest":"cp","windows-latest":"copy"}')[matrix.os] || matrix.os }} $(python3.9 -c "import grapheme; print(grapheme.__path__[0] + '/data/grapheme_break_property.json')") ./dist/krr/grapheme/data/grapheme_break_property.json + mkdir -p ./dist/krr/grapheme/data + cp $(python3.9 -c "import grapheme; print(grapheme.__path__[0] + '/data/grapheme_break_property.json')") ./dist/krr/grapheme/data/grapheme_break_property.json - name: Zip the application + shell: bash run: | zip -r krr-${{ matrix.os }}-${{ github.ref_name }}.zip dist/krr -- cgit v1.2.3 From 38b3d28ed53bb109c5ec79cb6709d13b47a98293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 19:47:43 +0300 Subject: Fix python 3.9 in pipeline --- .github/workflows/build-on-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index a569e8a..5e1b6ed 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.x' + python-version: '3.9' - name: Install dependencies run: | @@ -66,7 +66,7 @@ jobs: run: | pyinstaller krr.py mkdir -p ./dist/krr/grapheme/data - cp $(python3.9 -c "import grapheme; print(grapheme.__path__[0] + '/data/grapheme_break_property.json')") ./dist/krr/grapheme/data/grapheme_break_property.json + cp $(python -c "import grapheme; print(grapheme.__path__[0] + '/data/grapheme_break_property.json')") ./dist/krr/grapheme/data/grapheme_break_property.json - name: Zip the application shell: bash -- cgit v1.2.3 From a2c756fac91b43274782c3706494ff0c0790a64f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 19:56:02 +0300 Subject: Fix zip step on windows --- .github/workflows/build-on-release.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 5e1b6ed..efc89c4 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -68,11 +68,16 @@ jobs: mkdir -p ./dist/krr/grapheme/data cp $(python -c "import grapheme; print(grapheme.__path__[0] + '/data/grapheme_break_property.json')") ./dist/krr/grapheme/data/grapheme_break_property.json - - name: Zip the application - shell: bash + - name: Zip the application (Unix) + if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest' run: | zip -r krr-${{ matrix.os }}-${{ github.ref_name }}.zip dist/krr + - name: Zip the application (Windows) + if: matrix.os == 'windows-latest' + run: | + Compress-Archive dist/krr krr-${{ matrix.os }}-${{ github.ref_name }}.zip + - name: Upload Release Asset uses: actions/upload-release-asset@v1.0.2 env: -- cgit v1.2.3 From d743357624c3d5918da3376aa09a7325fd2d19f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 21:57:46 +0300 Subject: Add update brew tap jobs --- .github/workflows/build-on-release.yml | 54 ++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index efc89c4..f8d45b7 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -93,3 +93,57 @@ jobs: run: | security delete-keychain $RUNNER_TEMP/app-signing.keychain-db rm ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision + + # Define MacOS hash job + mac-hash: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Download MacOS artifact + uses: actions/download-artifact@v2 + with: + name: krr-macos-latest-${{ github.ref_name }}.zip + - name: Calculate hash + run: echo "MAC_BUILD_HASH=$(sha256sum krr-macos-latest-${{ github.ref_name }}.zip | awk '{print $1}')" >> $GITHUB_ENV + + # Define Linux hash job + linux-hash: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + - name: Download Linux artifact + uses: actions/download-artifact@v2 + with: + name: krr-ubuntu-latest-${{ github.ref_name }}.zip + - name: Calculate hash + run: echo "LINUX_BUILD_HASH=$(sha256sum krr-ubuntu-latest-${{ github.ref_name }}.zip | awk '{print $1}')" >> $GITHUB_ENV + + # Define job to update homebrew formula + update-formula: + needs: [mac-hash, linux-hash] + runs-on: ubuntu-latest + steps: + - name: Checkout homebrew-krr repository + uses: actions/checkout@v2 + with: + repository: robusta-dev/homebrew-krr-test + token: ${{ secrets.GITHUB_TOKEN }} + - name: Update krr.rb formula + run: | + MAC_BUILD_HASH=${{ needs.mac-hash.outputs.MAC_BUILD_HASH }} + LINUX_BUILD_HASH=${{ needs.linux-hash.outputs.LINUX_BUILD_HASH }} + RELEASE_VERSION=${{ github.ref_name }} + sed -i "s|url .*/krr-macos.*|url \"https://github.com/robusta-dev/krr/releases/download/${RELEASE_VERSION}/krr-macos-latest-${RELEASE_VERSION}.zip\"|" Formula/krr.rb + sed -i "s|sha256 .* # macOS|sha256 \"${MAC_BUILD_HASH}\" # macOS|" Formula/krr.rb + sed -i "s|url .*/krr-linux.*|url \"https://github.com/robusta-dev/krr/releases/download/${RELEASE_VERSION}/krr-linux-latest-${RELEASE_VERSION}.zip\"|" Formula/krr.rb + sed -i "s|sha256 .* # Linux|sha256 \"${LINUX_BUILD_HASH}\" # Linux|" Formula/krr.rb + - name: Commit and push changes + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git commit -am "Update formula for release ${RELEASE_VERSION}" + git push -- cgit v1.2.3 From 60ea18c609e81bb163cf8e84518c7f9bec903460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 22:24:16 +0300 Subject: Fix upload artifacts --- .github/workflows/build-on-release.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index f8d45b7..e28923a 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -88,6 +88,12 @@ jobs: asset_name: krr-${{ matrix.os }}-${{ github.ref_name }}.zip asset_content_type: application/octet-stream + - name: Upload build as artifact + uses: actions/upload-artifact@v2 + with: + name: krr-${{ matrix.os }}-${{ github.ref_name }} + path: ./krr-${{ matrix.os }}-${{ github.ref_name }}.zip + - name: Clean up keychain and provisioning profile if: (matrix.os == 'macos-latest') && always() run: | -- cgit v1.2.3 From 9cb82ee56c8866c60a9531eb5cb9c0a1db064e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 22:56:04 +0300 Subject: Fix artifact download --- .github/workflows/build-on-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index e28923a..0fe7c37 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -110,7 +110,7 @@ jobs: - name: Download MacOS artifact uses: actions/download-artifact@v2 with: - name: krr-macos-latest-${{ github.ref_name }}.zip + name: krr-macos-latest-${{ github.ref_name }} - name: Calculate hash run: echo "MAC_BUILD_HASH=$(sha256sum krr-macos-latest-${{ github.ref_name }}.zip | awk '{print $1}')" >> $GITHUB_ENV @@ -124,7 +124,7 @@ jobs: - name: Download Linux artifact uses: actions/download-artifact@v2 with: - name: krr-ubuntu-latest-${{ github.ref_name }}.zip + name: krr-ubuntu-latest-${{ github.ref_name }} - name: Calculate hash run: echo "LINUX_BUILD_HASH=$(sha256sum krr-ubuntu-latest-${{ github.ref_name }}.zip | awk '{print $1}')" >> $GITHUB_ENV -- cgit v1.2.3 From 0cc1c8be2536cfde159f7f7efd204850885c4652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 23:13:49 +0300 Subject: Authorize checkout to homebrew-krr-test --- .github/workflows/build-on-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 0fe7c37..d7f1b94 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -137,7 +137,7 @@ jobs: uses: actions/checkout@v2 with: repository: robusta-dev/homebrew-krr-test - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.MULTIREPO_GITHUB_TOKEN }} - name: Update krr.rb formula run: | MAC_BUILD_HASH=${{ needs.mac-hash.outputs.MAC_BUILD_HASH }} -- cgit v1.2.3 From 69900c43817919199389012de87d798a70e9d78b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sat, 27 May 2023 23:46:21 +0300 Subject: Rework how git commit change is done --- .github/workflows/build-on-release.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index d7f1b94..f8f60ab 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -143,10 +143,10 @@ jobs: MAC_BUILD_HASH=${{ needs.mac-hash.outputs.MAC_BUILD_HASH }} LINUX_BUILD_HASH=${{ needs.linux-hash.outputs.LINUX_BUILD_HASH }} RELEASE_VERSION=${{ github.ref_name }} - sed -i "s|url .*/krr-macos.*|url \"https://github.com/robusta-dev/krr/releases/download/${RELEASE_VERSION}/krr-macos-latest-${RELEASE_VERSION}.zip\"|" Formula/krr.rb - sed -i "s|sha256 .* # macOS|sha256 \"${MAC_BUILD_HASH}\" # macOS|" Formula/krr.rb - sed -i "s|url .*/krr-linux.*|url \"https://github.com/robusta-dev/krr/releases/download/${RELEASE_VERSION}/krr-linux-latest-${RELEASE_VERSION}.zip\"|" Formula/krr.rb - sed -i "s|sha256 .* # Linux|sha256 \"${LINUX_BUILD_HASH}\" # Linux|" Formula/krr.rb + awk 'NR==6{$0=" url \"https://github.com/robusta-dev/krr/releases/download/'"$TAG_NAME"'/krr-macos-latest-'"$TAG_NAME"'.zip\""}1' ./Formula/krr.rb > temp && mv temp ./Formula/krr.rb + awk 'NR==7{$0=" sha256 \"'$MAC_BUILD_HASH'\""}1' ./Formula/krr.rb > temp && mv temp ./Formula/krr.rb + awk 'NR==9{$0=" url \"https://github.com/robusta-dev/krr/releases/download/'"$TAG_NAME"'/krr-linux-latest-'"$TAG_NAME"'.zip\""}1' ./Formula/krr.rb > temp && mv temp ./Formula/krr.rb + awk 'NR==10{$0=" sha256 \"'$LINUX_BUILD_HASH'\""}1' ./Formula/krr.rb > temp && mv temp ./Formula/krr.rb - name: Commit and push changes run: | git config --local user.email "action@github.com" -- cgit v1.2.3 From 8991b1d8e55c5c22238520db1e45b081254ca39d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 00:06:05 +0300 Subject: Fix env variables in commit to homebrew --- .github/workflows/build-on-release.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index f8f60ab..166e7b7 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -112,7 +112,8 @@ jobs: with: name: krr-macos-latest-${{ github.ref_name }} - name: Calculate hash - run: echo "MAC_BUILD_HASH=$(sha256sum krr-macos-latest-${{ github.ref_name }}.zip | awk '{print $1}')" >> $GITHUB_ENV + id: calc-hash + run: echo "::set-output name=MAC_BUILD_HASH::$(sha256sum krr-macos-latest-${{ github.ref_name }}.zip | awk '{print $1}')" # Define Linux hash job linux-hash: @@ -126,7 +127,8 @@ jobs: with: name: krr-ubuntu-latest-${{ github.ref_name }} - name: Calculate hash - run: echo "LINUX_BUILD_HASH=$(sha256sum krr-ubuntu-latest-${{ github.ref_name }}.zip | awk '{print $1}')" >> $GITHUB_ENV + id: calc-hash + run: echo "::set-output name=LINUX_BUILD_HASH::$(sha256sum krr-ubuntu-latest-${{ github.ref_name }}.zip | awk '{print $1}')" # Define job to update homebrew formula update-formula: @@ -140,9 +142,9 @@ jobs: token: ${{ secrets.MULTIREPO_GITHUB_TOKEN }} - name: Update krr.rb formula run: | - MAC_BUILD_HASH=${{ needs.mac-hash.outputs.MAC_BUILD_HASH }} - LINUX_BUILD_HASH=${{ needs.linux-hash.outputs.LINUX_BUILD_HASH }} - RELEASE_VERSION=${{ github.ref_name }} + MAC_BUILD_HASH=${{ needs.mac-hash.outputs.calc-hash.MAC_BUILD_HASH }} + LINUX_BUILD_HASH=${{ needs.linux-hash.outputs.calc-hash.LINUX_BUILD_HASH }} + TAG_NAME=${{ github.ref_name }} awk 'NR==6{$0=" url \"https://github.com/robusta-dev/krr/releases/download/'"$TAG_NAME"'/krr-macos-latest-'"$TAG_NAME"'.zip\""}1' ./Formula/krr.rb > temp && mv temp ./Formula/krr.rb awk 'NR==7{$0=" sha256 \"'$MAC_BUILD_HASH'\""}1' ./Formula/krr.rb > temp && mv temp ./Formula/krr.rb awk 'NR==9{$0=" url \"https://github.com/robusta-dev/krr/releases/download/'"$TAG_NAME"'/krr-linux-latest-'"$TAG_NAME"'.zip\""}1' ./Formula/krr.rb > temp && mv temp ./Formula/krr.rb @@ -151,5 +153,5 @@ jobs: run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - git commit -am "Update formula for release ${RELEASE_VERSION}" + git commit -am "Update formula for release ${TAG_NAME}" git push -- cgit v1.2.3 From ab60f502ed46c56f8126b65c048966ecdedbeb83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 00:24:47 +0300 Subject: Fix output not working --- .github/workflows/build-on-release.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 166e7b7..f98aad8 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -104,6 +104,8 @@ jobs: mac-hash: needs: build runs-on: ubuntu-latest + outputs: + MAC_BUILD_HASH: ${{ steps.calc-hash.outputs.MAC_BUILD_HASH }} steps: - name: Checkout Repository uses: actions/checkout@v2 @@ -119,6 +121,8 @@ jobs: linux-hash: needs: build runs-on: ubuntu-latest + outputs: + LINUX_BUILD_HASH: ${{ steps.calc-hash.outputs.LINUX_BUILD_HASH }} steps: - name: Checkout Repository uses: actions/checkout@v2 @@ -142,8 +146,8 @@ jobs: token: ${{ secrets.MULTIREPO_GITHUB_TOKEN }} - name: Update krr.rb formula run: | - MAC_BUILD_HASH=${{ needs.mac-hash.outputs.calc-hash.MAC_BUILD_HASH }} - LINUX_BUILD_HASH=${{ needs.linux-hash.outputs.calc-hash.LINUX_BUILD_HASH }} + MAC_BUILD_HASH=${{ needs.mac-hash.outputs.MAC_BUILD_HASH }} + LINUX_BUILD_HASH=${{ needs.linux-hash.outputs.LINUX_BUILD_HASH }} TAG_NAME=${{ github.ref_name }} awk 'NR==6{$0=" url \"https://github.com/robusta-dev/krr/releases/download/'"$TAG_NAME"'/krr-macos-latest-'"$TAG_NAME"'.zip\""}1' ./Formula/krr.rb > temp && mv temp ./Formula/krr.rb awk 'NR==7{$0=" sha256 \"'$MAC_BUILD_HASH'\""}1' ./Formula/krr.rb > temp && mv temp ./Formula/krr.rb -- cgit v1.2.3 From d9306447112e5308e5bfdda011d30ffc3ad1f6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 00:37:11 +0300 Subject: Brew only on latest release --- .github/workflows/build-on-release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index f98aad8..8b2ff8d 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -104,6 +104,7 @@ jobs: mac-hash: needs: build runs-on: ubuntu-latest + if: github.event.release.id == github.event.repository.latest_release.id outputs: MAC_BUILD_HASH: ${{ steps.calc-hash.outputs.MAC_BUILD_HASH }} steps: @@ -121,6 +122,7 @@ jobs: linux-hash: needs: build runs-on: ubuntu-latest + if: github.event.release.id == github.event.repository.latest_release.id outputs: LINUX_BUILD_HASH: ${{ steps.calc-hash.outputs.LINUX_BUILD_HASH }} steps: @@ -138,6 +140,7 @@ jobs: update-formula: needs: [mac-hash, linux-hash] runs-on: ubuntu-latest + if: github.event.release.id == github.event.repository.latest_release.id steps: - name: Checkout homebrew-krr repository uses: actions/checkout@v2 -- cgit v1.2.3 From 14b76496ae104ab04081282749fb2338697b66e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 01:04:39 +0300 Subject: Fix zip archives --- .github/workflows/build-on-release.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 8b2ff8d..1ee966f 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -71,12 +71,18 @@ jobs: - name: Zip the application (Unix) if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest' run: | - zip -r krr-${{ matrix.os }}-${{ github.ref_name }}.zip dist/krr + cd dist + zip -r krr-${{ matrix.os }}-${{ github.ref_name }}.zip krr + mv krr-${{ matrix.os }}-${{ github.ref_name }}.zip ../ + cd .. - name: Zip the application (Windows) if: matrix.os == 'windows-latest' run: | - Compress-Archive dist/krr krr-${{ matrix.os }}-${{ github.ref_name }}.zip + Set-Location -Path dist + Compress-Archive -Path krr -DestinationPath krr-${{ matrix.os }}-${{ github.ref_name }}.zip -Force + Move-Item -Path krr-${{ matrix.os }}-${{ github.ref_name }}.zip -Destination ..\ + Set-Location -Path .. - name: Upload Release Asset uses: actions/upload-release-asset@v1.0.2 -- cgit v1.2.3 From 403d8310f29dfafc0f4a617431fca71a9632cdee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 01:57:23 +0300 Subject: Rework skip on not latest update --- .github/workflows/build-on-release.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 1ee966f..8e24ab4 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -110,7 +110,6 @@ jobs: mac-hash: needs: build runs-on: ubuntu-latest - if: github.event.release.id == github.event.repository.latest_release.id outputs: MAC_BUILD_HASH: ${{ steps.calc-hash.outputs.MAC_BUILD_HASH }} steps: @@ -148,6 +147,22 @@ jobs: runs-on: ubuntu-latest if: github.event.release.id == github.event.repository.latest_release.id steps: + - name: Check if latest release + id: check + run: | + LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/robusta-dev/krr/releases/latest | jq -r .tag_name) + CURRENT_RELEASE=${{ github.ref_name }} + if [ "$LATEST_RELEASE" != "$CURRENT_RELEASE" ]; then + echo "::set-output name=is_latest::false" + else + echo "::set-output name=is_latest::true" + fi + - name: Fail if not latest release + if: steps.check.outputs.is_latest != 'true' + continue-on-error: true + run: | + echo "Not the latest release, cancelling job" + exit 1 - name: Checkout homebrew-krr repository uses: actions/checkout@v2 with: -- cgit v1.2.3 From fb873608d42c13eb5151679a430d8f0159b8bbbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 02:04:08 +0300 Subject: Remove remaining old ifs --- .github/workflows/build-on-release.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 8e24ab4..bd743f2 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -127,7 +127,6 @@ jobs: linux-hash: needs: build runs-on: ubuntu-latest - if: github.event.release.id == github.event.repository.latest_release.id outputs: LINUX_BUILD_HASH: ${{ steps.calc-hash.outputs.LINUX_BUILD_HASH }} steps: @@ -145,7 +144,6 @@ jobs: update-formula: needs: [mac-hash, linux-hash] runs-on: ubuntu-latest - if: github.event.release.id == github.event.repository.latest_release.id steps: - name: Check if latest release id: check -- cgit v1.2.3 From f39f8ea379eaa8bd8306dc7fbfc5981faab69150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 12:59:24 +0300 Subject: Rework checking for latest workflow --- .github/workflows/build-on-release.yml | 35 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index bd743f2..f4c320e 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -106,10 +106,23 @@ jobs: security delete-keychain $RUNNER_TEMP/app-signing.keychain-db rm ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision + check-latest: + needs: build + runs-on: ubuntu-latest + outputs: + IS_LATEST: ${{ steps.check-latest.outputs.release == github.ref_name }} + steps: + - id: check-latest + uses: pozetroninc/github-action-get-latest-release@v0.7.0 + with: + repository: ${{ github.repository }} + excludes: prerelease, draft + # Define MacOS hash job mac-hash: - needs: build + needs: check-latest runs-on: ubuntu-latest + if: steps.check-latest.outputs.IS_LATEST outputs: MAC_BUILD_HASH: ${{ steps.calc-hash.outputs.MAC_BUILD_HASH }} steps: @@ -125,8 +138,9 @@ jobs: # Define Linux hash job linux-hash: - needs: build + needs: check-latest runs-on: ubuntu-latest + if: steps.check-latest.outputs.IS_LATEST outputs: LINUX_BUILD_HASH: ${{ steps.calc-hash.outputs.LINUX_BUILD_HASH }} steps: @@ -144,23 +158,8 @@ jobs: update-formula: needs: [mac-hash, linux-hash] runs-on: ubuntu-latest + if: steps.check-latest.outputs.IS_LATEST steps: - - name: Check if latest release - id: check - run: | - LATEST_RELEASE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/robusta-dev/krr/releases/latest | jq -r .tag_name) - CURRENT_RELEASE=${{ github.ref_name }} - if [ "$LATEST_RELEASE" != "$CURRENT_RELEASE" ]; then - echo "::set-output name=is_latest::false" - else - echo "::set-output name=is_latest::true" - fi - - name: Fail if not latest release - if: steps.check.outputs.is_latest != 'true' - continue-on-error: true - run: | - echo "Not the latest release, cancelling job" - exit 1 - name: Checkout homebrew-krr repository uses: actions/checkout@v2 with: -- cgit v1.2.3 From 8cf4b56daef2d2befde126f3fde6cafeab3ee5ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 13:01:47 +0300 Subject: Fix ifs on hashing steps --- .github/workflows/build-on-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index f4c320e..ede9f55 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -122,7 +122,7 @@ jobs: mac-hash: needs: check-latest runs-on: ubuntu-latest - if: steps.check-latest.outputs.IS_LATEST + if: needs.check-latest.outputs.IS_LATEST outputs: MAC_BUILD_HASH: ${{ steps.calc-hash.outputs.MAC_BUILD_HASH }} steps: @@ -140,7 +140,7 @@ jobs: linux-hash: needs: check-latest runs-on: ubuntu-latest - if: steps.check-latest.outputs.IS_LATEST + if: needs.check-latest.outputs.IS_LATEST outputs: LINUX_BUILD_HASH: ${{ steps.calc-hash.outputs.LINUX_BUILD_HASH }} steps: -- cgit v1.2.3 From d5999887ab529f72e98828f7b2bc7a8e55c13be6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 13:04:00 +0300 Subject: Remove if in update-formula --- .github/workflows/build-on-release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index ede9f55..55eacd6 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -158,7 +158,6 @@ jobs: update-formula: needs: [mac-hash, linux-hash] runs-on: ubuntu-latest - if: steps.check-latest.outputs.IS_LATEST steps: - name: Checkout homebrew-krr repository uses: actions/checkout@v2 -- cgit v1.2.3 From 1657b696931ed34ef65b7ec14c10be000615f3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 13:32:02 +0300 Subject: Add token to check-latest, autoset version to CLI --- .github/workflows/build-on-release.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 55eacd6..f4abc61 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -61,6 +61,10 @@ jobs: mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles + - name: Set version in code + run: | + awk 'NR==3{$0="__version__\"'${{ github.ref_name }}'\""}1' ./robusta_krr/__init__.py > temp && mv temp ./robusta_krr/__init__.py + - name: Build with PyInstaller shell: bash run: | @@ -115,6 +119,7 @@ jobs: - id: check-latest uses: pozetroninc/github-action-get-latest-release@v0.7.0 with: + token: ${{ secrets.GITHUB_TOKEN }} repository: ${{ github.repository }} excludes: prerelease, draft -- cgit v1.2.3 From 6562b63d1c8f12cf35d61d4d05acd4d3f8093ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 13:38:15 +0300 Subject: Fix set version for Windows --- .github/workflows/build-on-release.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index f4abc61..9c619e3 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -61,10 +61,22 @@ jobs: mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles - - name: Set version in code + - name: Set version in code (Unix) + if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest' run: | awk 'NR==3{$0="__version__\"'${{ github.ref_name }}'\""}1' ./robusta_krr/__init__.py > temp && mv temp ./robusta_krr/__init__.py + - name: Set version in code (Windows) + if: matrix.os == 'windows-latest' + run: | + $content = Get-Content -Path .\robusta_krr\__init__.py + $content[2] = "__version__=`"$($env:GITHUB_REF_NAME)`"" + $content | Out-File -FilePath .\robusta_krr\__init__.py -Encoding ascii + shell: pwsh + env: + GITHUB_REF_NAME: ${{ github.ref_name }} + + - name: Build with PyInstaller shell: bash run: | -- cgit v1.2.3 From bbe5d517b7406eaf50267fca53b85ce8987b7123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 13:53:25 +0300 Subject: Add cat to set version --- .github/workflows/build-on-release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 9c619e3..511847e 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -65,6 +65,7 @@ jobs: if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest' run: | awk 'NR==3{$0="__version__\"'${{ github.ref_name }}'\""}1' ./robusta_krr/__init__.py > temp && mv temp ./robusta_krr/__init__.py + cat ./robusta_krr/__init__.py - name: Set version in code (Windows) if: matrix.os == 'windows-latest' @@ -72,6 +73,7 @@ jobs: $content = Get-Content -Path .\robusta_krr\__init__.py $content[2] = "__version__=`"$($env:GITHUB_REF_NAME)`"" $content | Out-File -FilePath .\robusta_krr\__init__.py -Encoding ascii + Get-Content .\robusta_krr\__init__.py shell: pwsh env: GITHUB_REF_NAME: ${{ github.ref_name }} -- cgit v1.2.3 From bc7f9b92ed5a51cdbea731de4450536822066eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 13:57:37 +0300 Subject: Fix AWK for Unix missing = sign --- .github/workflows/build-on-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index 511847e..ba6a8d1 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -64,7 +64,7 @@ jobs: - name: Set version in code (Unix) if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest' run: | - awk 'NR==3{$0="__version__\"'${{ github.ref_name }}'\""}1' ./robusta_krr/__init__.py > temp && mv temp ./robusta_krr/__init__.py + awk 'NR==3{$0="__version__ = \"'${{ github.ref_name }}'\""}1' ./robusta_krr/__init__.py > temp && mv temp ./robusta_krr/__init__.py cat ./robusta_krr/__init__.py - name: Set version in code (Windows) -- cgit v1.2.3 From 2b0c4e938e3d967b0c21782fa39e4dd7b4084cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=96=D1=83=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= <33721692+LeaveMyYard@users.noreply.github.com> Date: Sun, 28 May 2023 20:44:49 +0300 Subject: Change homebrew repo to real one --- .github/workflows/build-on-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-on-release.yml b/.github/workflows/build-on-release.yml index ba6a8d1..498393f 100644 --- a/.github/workflows/build-on-release.yml +++ b/.github/workflows/build-on-release.yml @@ -181,7 +181,7 @@ jobs: - name: Checkout homebrew-krr repository uses: actions/checkout@v2 with: - repository: robusta-dev/homebrew-krr-test + repository: robusta-dev/homebrew-krr token: ${{ secrets.MULTIREPO_GITHUB_TOKEN }} - name: Update krr.rb formula run: | -- cgit v1.2.3 From 2f1729852028f67ceecd0f692b5b25683fbcfd9e Mon Sep 17 00:00:00 2001 From: avi robusta Date: Mon, 29 May 2023 11:37:33 +0300 Subject: Fixed prometheus error --- robusta_krr/core/integrations/prometheus/loader.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/robusta_krr/core/integrations/prometheus/loader.py b/robusta_krr/core/integrations/prometheus/loader.py index 4e50626..93bc031 100644 --- a/robusta_krr/core/integrations/prometheus/loader.py +++ b/robusta_krr/core/integrations/prometheus/loader.py @@ -129,8 +129,9 @@ class PrometheusLoader(Configurable): if len(object.pods) == 0: return - - period_literal = f"{int(period.total_seconds()) // 60 // 24}d" + + days_literal = min(int(period.total_seconds()) // 60 // 24, 32) # the max can be 32 days + period_literal = f"{days_literal}d" owner = await asyncio.to_thread( self.prometheus.custom_query, query=f'kube_pod_owner{{pod="{next(iter(object.pods)).name}"}}[{period_literal}]', -- cgit v1.2.3 From ea7d72868c2dac87879ea87e31b6a953c884c0b2 Mon Sep 17 00:00:00 2001 From: avi robusta Date: Mon, 29 May 2023 11:57:36 +0300 Subject: comment fix --- robusta_krr/core/integrations/prometheus/loader.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/robusta_krr/core/integrations/prometheus/loader.py b/robusta_krr/core/integrations/prometheus/loader.py index 93bc031..68cade3 100644 --- a/robusta_krr/core/integrations/prometheus/loader.py +++ b/robusta_krr/core/integrations/prometheus/loader.py @@ -130,7 +130,8 @@ class PrometheusLoader(Configurable): if len(object.pods) == 0: return - days_literal = min(int(period.total_seconds()) // 60 // 24, 32) # the max can be 32 days + # Prometheus limit, the max can be 32 days + days_literal = min(int(period.total_seconds()) // 60 // 24, 32) period_literal = f"{days_literal}d" owner = await asyncio.to_thread( self.prometheus.custom_query, -- cgit v1.2.3