Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add support for StrimziPodSet #388

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/actions/get-python-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "Get Python Version"
description: "Read the python version from .python-version file"
outputs:
python-version:
description: "Python version"
value: ${{ steps.get_version.outputs.python-version }}
runs:
using: "composite"
steps:
- name: get python-version
shell: bash
id: get_version
run: |
echo "python-version=$(cat .python-version)" >> $GITHUB_OUTPUT
15 changes: 9 additions & 6 deletions .github/workflows/build-on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: ./.github/actions/get-python-version
id: get_version

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: "${{ steps.get_version.outputs.python-version }}"

- name: Install dependencies
run: |
Expand Down Expand Up @@ -157,7 +160,7 @@ jobs:
MAC_BUILD_HASH: ${{ steps.calc-hash.outputs.MAC_BUILD_HASH }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Download MacOS artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -175,7 +178,7 @@ jobs:
LINUX_BUILD_HASH: ${{ steps.calc-hash.outputs.LINUX_BUILD_HASH }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Download Linux artifact
uses: actions/download-artifact@v4
with:
Expand All @@ -190,7 +193,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout homebrew-krr repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: robusta-dev/homebrew-krr
token: ${{ secrets.MULTIREPO_GITHUB_TOKEN }}
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/docker-build-on-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/#-action@v1
Expand All @@ -20,17 +20,21 @@ jobs:
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- uses: ./.github/actions/get-python-version
id: get_version

- name: Build and push Docker images
uses: docker/build-push-action@v2
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/arm64,linux/amd64
push: true
tags: robustadev/krr:${{ github.ref_name }}
build-args: |
BUILDKIT_INLINE_CACHE=1
PYTHON_VERSION=${{ steps.get_version.outputs.python-version }}
- name: Set up gcloud CLI
uses: google-github-actions/setup-gcloud@v0.2.0
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/pytest-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: ./.github/actions/get-python-version
id: get_version

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: "${{ steps.get_version.outputs.python-version }}"

- name: Install dependencies
run: |
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Use the official Python 3.9 slim image as the base image
FROM python:3.12-slim as builder
# PYTHON_VERSION is passed as a build argument which uses .python-version
ARG PYTHON_VERSION
FROM python:${PYTHON_VERSION}-slim as builder
ENV LANG=C.UTF-8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
Expand Down
5 changes: 5 additions & 0 deletions build_release.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/bin/bash

python_version=$(cat .python-version)

docker buildx build \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg "PYTHON_VERSION=${python_version}" \
--platform linux/arm64,linux/amd64 \
--tag us-central1-docker.pkg.dev/genuine-flight-317411/devel/krr:${TAG} \
--push \
Expand Down
1,489 changes: 808 additions & 681 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins = "numpy.typing.mypy_plugin,pydantic.mypy"
krr = "robusta_krr.main:run"

[tool.poetry.dependencies]
python = ">=3.9,<=3.12.3"
python = ">=3.9,<=3.12.7"
typer = { extras = ["all"], version = "^0.7.0" }
pydantic = "^1.10.7"
kubernetes = "^26.1.0"
Expand Down
30 changes: 29 additions & 1 deletion robusta_krr/core/integrations/kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ async def list_scannable_objects(self) -> list[K8sObjectData]:
workload_object_lists = await asyncio.gather(
self._list_deployments(),
self._list_rollouts(),
self._list_strimzipodsets(),
self._list_deploymentconfig(),
self._list_all_statefulsets(),
self._list_all_daemon_set(),
Expand Down Expand Up @@ -204,7 +205,10 @@ def __build_scannable_object(
labels = {}
annotations = {}
if item.metadata.labels:
labels = item.metadata.labels
if type(item.metadata.labels) is ObjectLikeDict:
labels = item.metadata.labels.__dict__
else:
labels = item.metadata.labels

if item.metadata.annotations:
if type(item.metadata.annotations) is ObjectLikeDict:
Expand Down Expand Up @@ -364,6 +368,30 @@ async def _extract_containers(item: Any) -> list[V1Container]:
extract_containers=_extract_containers,
)

def _list_strimzipodsets(self) -> list[K8sObjectData]:
# NOTE: Using custom objects API returns dicts, but all other APIs return objects
# We need to handle this difference using a small wrapper
return self._list_scannable_objects(
kind="StrimziPodSet",
all_namespaces_request=lambda **kwargs: ObjectLikeDict(
self.custom_objects.list_cluster_custom_object(
group="core.strimzi.io",
version="v1beta2",
plural="strimzipodsets",
**kwargs,
)
),
namespaced_request=lambda **kwargs: ObjectLikeDict(
self.custom_objects.list_namespaced_custom_object(
group="core.strimzi.io",
version="v1beta2",
plural="strimzipodsets",
**kwargs,
)
),
extract_containers=lambda item: item.spec.pods[0].spec.containers,
)

def _list_deploymentconfig(self) -> list[K8sObjectData]:
# NOTE: Using custom objects API returns dicts, but all other APIs return objects
# We need to handle this difference using a small wrapper
Expand Down
2 changes: 1 addition & 1 deletion robusta_krr/core/models/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from robusta_krr.utils.batched import batched
from kubernetes.client.models import V1LabelSelector

KindLiteral = Literal["Deployment", "DaemonSet", "StatefulSet", "Job", "CronJob", "Rollout", "DeploymentConfig"]
KindLiteral = Literal["Deployment", "DaemonSet", "StatefulSet", "Job", "CronJob", "Rollout", "DeploymentConfig", "StrimziPodSet"]


class PodData(pd.BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion robusta_krr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run_strategy(
None,
"--resource",
"-r",
help="List of resources to run on (Deployment, StatefulSet, DaemonSet, Job, Rollout). By default, will run on all resources. Case insensitive.",
help="List of resources to run on (Deployment, StatefulSet, DaemonSet, Job, Rollout, StrimziPodSet). By default, will run on all resources. Case insensitive.",
rich_help_panel="Kubernetes Settings",
),
selector: Optional[str] = typer.Option(
Expand Down