Skip to content
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

Add support for annotations in Resource #1887

Merged
merged 1 commit into from
Jun 28, 2024
Merged
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
5 changes: 5 additions & 0 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ def __init__(
config_dict: Dict[str, Any] | None = None,
context: str = "",
label: Dict[str, str] | None = None,
annotations: Dict[str, str] | None = None,
timeout_seconds: int = TIMEOUT_1MINUTE,
api_group: str = "",
hash_log_data: bool = True,
Expand All @@ -393,6 +394,7 @@ def __init__(
context (str): Context name for connecting to remote cluster.
timeout_seconds (int): timeout for a get api call, call out be terminated after this many seconds
label (dict): Resource labels
annotations (Dict[str, str] | None): Resource annotations
api_group (str): Resource API group; will overwrite API group definition in resource class
hash_log_data (bool): Hash resource content based on resource keys_to_hash property
(example: Secret resource)
Expand All @@ -417,6 +419,7 @@ def __init__(
self.config_dict = config_dict or {}
self.context = context
self.label = label
self.annotations = annotations
self.timeout_seconds = timeout_seconds
self.client: DynamicClient = client or get_client(config_file=self.config_file, context=self.context)
self.api_group: str = api_group or self.api_group
Expand Down Expand Up @@ -494,6 +497,8 @@ def _base_body(self) -> None:
}
if self.label:
self.res.setdefault("metadata", {}).setdefault("labels", {}).update(self.label)
if self.annotations:
self.res.setdefault("metadata", {}).setdefault("annotations", {}).update(self.annotations)

def to_dict(self) -> None:
"""
Expand Down