Skip to content

Commit

Permalink
Deprecate node selector type (#1913)
Browse files Browse the repository at this point in the history
* deprecate node_selector str type in Resource

* deprecate node_selector str type in Resource

* Remove ignored type check from ingress_controleer

* Add empty test in tox to match the list from main
  • Loading branch information
myakove authored Jul 21, 2024
1 parent e06ac4f commit 7778c28
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ocp_resources/ingress_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(
self.endpoint_publishing_strategy = endpoint_publishing_strategy
self.default_certificate = default_certificate
self.namespace_selector = namespace_selector
self.node_selector = node_selector # type: ignore
self.node_selector = node_selector
self.route_selector = route_selector
self.tls_security_profile = tls_security_profile
self.logging = logging
Expand Down
15 changes: 13 additions & 2 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from collections.abc import Callable, Generator
from warnings import warn
import contextlib
import copy
import json
Expand Down Expand Up @@ -364,7 +365,7 @@ def __init__(
yaml_file: str = "",
delete_timeout: int = TIMEOUT_4MINUTES,
dry_run: bool = False,
node_selector: str = "",
node_selector: Dict[str, Any] | None = None,
node_selector_labels: Dict[str, str] | None = None,
config_file: str = "",
config_dict: Dict[str, Any] | None = None,
Expand Down Expand Up @@ -461,9 +462,19 @@ def _set_logger(self) -> logging.Logger:

def _prepare_node_selector_spec(self) -> Dict[str, str]:
if self.node_selector:
return {f"{self.ApiGroup.KUBERNETES_IO}/hostname": self.node_selector}
if isinstance(self.node_selector, dict):
return self.node_selector
else:
warn(
"node_selector `str` will be deprecated in next release (4.17), pass `dict` instead",
DeprecationWarning,
stacklevel=2,
)
return {f"{self.ApiGroup.KUBERNETES_IO}/hostname": self.node_selector}

elif self.node_selector_labels:
return self.node_selector_labels

else:
return {}

Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ commands =
poetry run pytest tests/test_validate_resources.py
allowlist_externals =
poetry

[testenv:resource_class_generator]

0 comments on commit 7778c28

Please sign in to comment.