diff options
| author | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-04-06 13:02:58 +0300 |
|---|---|---|
| committer | Павел Жуков <33721692+LeaveMyYard@users.noreply.github.com> | 2023-04-06 13:02:58 +0300 |
| commit | ef5bf65f07a661ae895542a14f95abbd39c06fca (patch) | |
| tree | 056b8bf56ef721a2cff5d6122c3b3e8a381bb893 | |
| parent | fcc008b2907c3ca1af19f2861c7c719598ad4f62 (diff) | |
Add the custom api interface for custom objects, add custom formatter example
| -rw-r--r-- | examples/custom_formatter.py | 20 | ||||
| -rw-r--r-- | examples/custom_strategy.py | 19 | ||||
| -rw-r--r-- | robusta_krr/__init__.py | 4 | ||||
| -rw-r--r-- | robusta_krr/api/formatters.py | 3 | ||||
| -rw-r--r-- | robusta_krr/api/models.py | 16 | ||||
| -rw-r--r-- | robusta_krr/api/strategies.py | 3 |
6 files changed, 52 insertions, 13 deletions
diff --git a/examples/custom_formatter.py b/examples/custom_formatter.py new file mode 100644 index 0000000..a091e22 --- /dev/null +++ b/examples/custom_formatter.py @@ -0,0 +1,20 @@ +# This is an example on how to create your own custom formatter + +from __future__ import annotations + +import robusta_krr +from robusta_krr.api.formatters import BaseFormatter +from robusta_krr.api.models import Result + + +class CustomFormatter(BaseFormatter): + __display_name__ = "my_formatter" + + def format(self, result: Result) -> str: + return "Custom formatter" + + +# Running this file will register the formatter and make it available to the CLI +# Run it as `python ./custom_formatter.py simple --formater my_formatter` +if __name__ == "__main__": + robusta_krr.run() diff --git a/examples/custom_strategy.py b/examples/custom_strategy.py index f88edd3..f5f2e6c 100644 --- a/examples/custom_strategy.py +++ b/examples/custom_strategy.py @@ -4,25 +4,19 @@ from decimal import Decimal import pydantic as pd -from robusta_krr import run -from robusta_krr.core.abstract.strategies import ( - BaseStrategy, - HistoryData, - K8sObjectData, - ResourceRecommendation, - ResourceType, - RunResult, - StrategySettings, -) +import robusta_krr +from robusta_krr.api.models import HistoryData, K8sObjectData, ResourceRecommendation, ResourceType, RunResult +from robusta_krr.api.strategies import BaseStrategy, StrategySettings +# Providing description to the settings will make it available in the CLI help class CustomStrategySettings(StrategySettings): param_1: Decimal = pd.Field(99, gt=0, description="First example parameter") param_2: Decimal = pd.Field(105_000, gt=0, description="Second example parameter") class CustomStrategy(BaseStrategy[CustomStrategySettings]): - __display_name__ = "custom" + __display_name__ = "my_strategy" def run(self, history_data: HistoryData, object_data: K8sObjectData) -> RunResult: return { @@ -32,5 +26,6 @@ class CustomStrategy(BaseStrategy[CustomStrategySettings]): # Running this file will register the strategy and make it available to the CLI +# Run it as `python ./custom_strategy.py my_strategy` if __name__ == "__main__": - run() + robusta_krr.run() diff --git a/robusta_krr/__init__.py b/robusta_krr/__init__.py index 9c4f0db..cd50bf6 100644 --- a/robusta_krr/__init__.py +++ b/robusta_krr/__init__.py @@ -1,3 +1,5 @@ +from . import api from .main import run -__all__ = ["run"] +__version__ = "0.1.0" +__all__ = ["run", "api", "__version__"] diff --git a/robusta_krr/api/formatters.py b/robusta_krr/api/formatters.py new file mode 100644 index 0000000..3bd6927 --- /dev/null +++ b/robusta_krr/api/formatters.py @@ -0,0 +1,3 @@ +from robusta_krr.core.abstract.formatters import BaseFormatter + +__all__ = ["BaseFormatter"] diff --git a/robusta_krr/api/models.py b/robusta_krr/api/models.py new file mode 100644 index 0000000..3efc9ff --- /dev/null +++ b/robusta_krr/api/models.py @@ -0,0 +1,16 @@ +from robusta_krr.core.abstract.strategies import HistoryData, ResourceRecommendation, RunResult +from robusta_krr.core.models.allocations import ResourceAllocations, ResourceType +from robusta_krr.core.models.objects import K8sObjectData +from robusta_krr.core.models.result import ResourceScan, Result, Severity + +__all__ = [ + "ResourceType", + "ResourceAllocations", + "K8sObjectData", + "Result", + "Severity", + "ResourceScan", + "ResourceRecommendation", + "HistoryData", + "RunResult", +] diff --git a/robusta_krr/api/strategies.py b/robusta_krr/api/strategies.py new file mode 100644 index 0000000..af43664 --- /dev/null +++ b/robusta_krr/api/strategies.py @@ -0,0 +1,3 @@ +from robusta_krr.core.abstract.strategies import BaseStrategy, StrategySettings + +__all__ = ["BaseStrategy", "StrategySettings"] |
