-
Notifications
You must be signed in to change notification settings - Fork 283
fix: add support for Strimzi v1.0+ api #534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mzglinski
wants to merge
2
commits into
robusta-dev:main
Choose a base branch
from
mzglinski:fix/strimzi-v1-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
| from kubernetes.client import ApiException | ||
|
|
||
| from robusta_krr.core.integrations.kubernetes import ClusterLoader | ||
| from robusta_krr.core.models.config import Config | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_config(): | ||
| config = MagicMock(spec=Config) | ||
| config.max_workers = 4 | ||
| config.get_kube_client = MagicMock() | ||
| config.resources = "*" | ||
| config.selector = None | ||
| config.namespaces = "*" | ||
| return config | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def loader(mock_config): | ||
| with patch("robusta_krr.core.integrations.kubernetes.settings", mock_config): | ||
| yield ClusterLoader(cluster="test-cluster") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def namespaced_loader(mock_config): | ||
| mock_config.namespaces = ["sentry"] | ||
| with patch("robusta_krr.core.integrations.kubernetes.settings", mock_config): | ||
| yield ClusterLoader(cluster="test-cluster") | ||
|
|
||
|
|
||
| def test_resolve_strimzipodset_api_version_prefers_v1(loader): | ||
| loader.custom_objects = MagicMock() | ||
|
|
||
| version = loader._resolve_strimzipodset_api_version() | ||
|
|
||
| assert version == "v1" | ||
| loader.custom_objects.list_cluster_custom_object.assert_called_once_with( | ||
| group="core.strimzi.io", | ||
| version="v1", | ||
| plural="strimzipodsets", | ||
| limit=1, | ||
| ) | ||
| loader.custom_objects.list_namespaced_custom_object.assert_not_called() | ||
|
|
||
|
|
||
| def test_resolve_strimzipodset_api_version_falls_back_to_v1beta2(loader): | ||
| loader.custom_objects = MagicMock() | ||
| loader.custom_objects.list_cluster_custom_object.side_effect = [ | ||
| ApiException(status=404, reason="Not Found"), | ||
| {"items": []}, | ||
| ] | ||
|
|
||
| version = loader._resolve_strimzipodset_api_version() | ||
|
|
||
| assert version == "v1beta2" | ||
| assert loader.custom_objects.list_cluster_custom_object.call_count == 2 | ||
| loader.custom_objects.list_cluster_custom_object.assert_any_call( | ||
| group="core.strimzi.io", | ||
| version="v1", | ||
| plural="strimzipodsets", | ||
| limit=1, | ||
| ) | ||
| loader.custom_objects.list_cluster_custom_object.assert_any_call( | ||
| group="core.strimzi.io", | ||
| version="v1beta2", | ||
| plural="strimzipodsets", | ||
| limit=1, | ||
| ) | ||
|
|
||
|
|
||
| def test_resolve_strimzipodset_api_version_returns_none_when_unavailable(loader): | ||
| loader.custom_objects = MagicMock() | ||
| loader.custom_objects.list_cluster_custom_object.side_effect = ApiException(status=404, reason="Not Found") | ||
|
|
||
| version = loader._resolve_strimzipodset_api_version() | ||
|
|
||
| assert version is None | ||
| assert loader._strimzipodset_api_version_checked | ||
| assert loader.custom_objects.list_cluster_custom_object.call_count == 2 | ||
|
|
||
|
|
||
| def test_resolve_strimzipodset_api_version_is_cached(loader): | ||
| loader.custom_objects = MagicMock() | ||
|
|
||
| assert loader._resolve_strimzipodset_api_version() == "v1" | ||
| assert loader._resolve_strimzipodset_api_version() == "v1" | ||
| loader.custom_objects.list_cluster_custom_object.assert_called_once() | ||
|
|
||
|
|
||
| def test_resolve_strimzipodset_api_version_uses_namespaced_probe(namespaced_loader): | ||
| namespaced_loader.custom_objects = MagicMock() | ||
|
|
||
| version = namespaced_loader._resolve_strimzipodset_api_version() | ||
|
|
||
| assert version == "v1" | ||
| namespaced_loader.custom_objects.list_cluster_custom_object.assert_not_called() | ||
| namespaced_loader.custom_objects.list_namespaced_custom_object.assert_called_once_with( | ||
| group="core.strimzi.io", | ||
| version="v1", | ||
| plural="strimzipodsets", | ||
| namespace="sentry", | ||
| limit=1, | ||
| ) | ||
|
|
||
|
|
||
| def test_resolve_strimzipodset_api_version_tries_v1beta2_after_v1_non_404(loader): | ||
| loader.custom_objects = MagicMock() | ||
| loader.custom_objects.list_cluster_custom_object.side_effect = [ | ||
| ApiException(status=403, reason="Forbidden"), | ||
| {"items": []}, | ||
| ] | ||
|
|
||
| version = loader._resolve_strimzipodset_api_version() | ||
|
|
||
| assert version == "v1beta2" | ||
| assert loader.custom_objects.list_cluster_custom_object.call_count == 2 | ||
|
|
||
|
|
||
| def test_resolve_strimzipodset_api_version_does_not_cache_transient_errors(loader): | ||
| loader.custom_objects = MagicMock() | ||
| loader.custom_objects.list_cluster_custom_object.side_effect = RuntimeError("connection reset") | ||
|
|
||
| assert loader._resolve_strimzipodset_api_version() is None | ||
| assert not loader._strimzipodset_api_version_checked | ||
|
|
||
| loader.custom_objects.list_cluster_custom_object.side_effect = None | ||
| loader.custom_objects.list_cluster_custom_object.return_value = {"items": []} | ||
|
|
||
| assert loader._resolve_strimzipodset_api_version() == "v1" | ||
| assert loader._strimzipodset_api_version_checked | ||
|
|
||
|
|
||
| def test_resolve_strimzipodset_api_version_probes_until_namespace_succeeds(mock_config): | ||
| mock_config.namespaces = ["blocked", "sentry"] | ||
| with patch("robusta_krr.core.integrations.kubernetes.settings", mock_config): | ||
| loader = ClusterLoader(cluster="test-cluster") | ||
| loader.custom_objects = MagicMock() | ||
| loader.custom_objects.list_namespaced_custom_object.side_effect = [ | ||
| ApiException(status=403, reason="Forbidden"), | ||
| {"items": []}, | ||
| ] | ||
|
|
||
| version = loader._resolve_strimzipodset_api_version() | ||
|
|
||
| assert version == "v1" | ||
| assert loader.custom_objects.list_namespaced_custom_object.call_count == 2 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.