Skip to content

Commit

Permalink
Deprecate privileged_client, use client. (#2242)
Browse files Browse the repository at this point in the history
* Deprecate `privileged_client`, use client.

* Use warn for DeprecationWarning

* Fix pod execute client

* Fix _kube_v1_api
  • Loading branch information
myakove authored Dec 19, 2024
1 parent d11a911 commit 0908166
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 39 deletions.
5 changes: 1 addition & 4 deletions ocp_resources/datavolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def __init__(
bind_immediate_annotation=None,
preallocation=None,
teardown=True,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
api_name="pvc",
Expand Down Expand Up @@ -119,7 +118,6 @@ def __init__(
should be bound immediately.
preallocation (bool, default: None): preallocate disk space.
teardown (bool, default: True): Indicates if this resource would need to be deleted.
privileged_client (DynamicClient, default: None): Instance of Dynamic client
yaml_file (yaml, default: None): yaml file for the resource.
delete_timeout (int, default: 4 minutes): timeout associated with delete action.
api_name (str, default: "pvc"): api used for DV, pvc/storage
Expand All @@ -130,7 +128,6 @@ def __init__(
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand Down Expand Up @@ -230,7 +227,7 @@ def wait(self, timeout=TIMEOUT_10MINUTES, failure_timeout=TIMEOUT_2MINUTES, wait
@property
def pvc(self):
return PersistentVolumeClaim(
client=self.privileged_client or self.client,
client=self.client,
name=self.name,
namespace=self.namespace,
)
Expand Down
3 changes: 0 additions & 3 deletions ocp_resources/endpoint_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def __init__(
endpoints=None,
ports=None,
teardown=True,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
**kwargs,
Expand All @@ -33,7 +32,6 @@ def __init__(
endpoints (list): List of unique endpoints in this slice
ports (list, optional): List of port numbers available on the related ip addresses
teardown (bool): Indicates if the resource should be torn down at the end
privileged_client (DynamicClient): Privileged client for api calls
yaml_file (str): yaml file for the resource.
delete_timeout (int): timeout associated with delete action
"""
Expand All @@ -42,7 +40,6 @@ def __init__(
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand Down
3 changes: 0 additions & 3 deletions ocp_resources/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(
addresses=None,
ports=None,
teardown=True,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
**kwargs,
Expand All @@ -31,7 +30,6 @@ def __init__(
addresses (list): List of ip addresses which offers the related ports that are marked as ready
ports (list): List of port numbers available on the related ip addresses
teardown (bool): Indicates if the resource should be torn down at the end
privileged_client (DynamicClient): Privileged client for api calls
yaml_file (str): yaml file for the resource.
delete_timeout (int): timeout associated with delete action
"""
Expand All @@ -40,7 +38,6 @@ def __init__(
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand Down
2 changes: 0 additions & 2 deletions ocp_resources/image_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(
lookup_policy=False,
tags=None,
teardown=True,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
**kwargs,
Expand All @@ -28,7 +27,6 @@ def __init__(
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand Down
3 changes: 0 additions & 3 deletions ocp_resources/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class Job(NamespacedResource):
namespace (str): Namespace name.
client (DynamicClient): Dynamic client for connecting to a remote cluster.
teardown (bool): Indicates if this resource would need to be deleted.
privileged_client (DynamicClient): Instance of Dynamic client.
yaml_file (str): Yaml file for the resource.
delete_timeout (int): Timeout associated with delete action.
backoff_limit (int): The number of retries for a job.
Expand All @@ -37,7 +36,6 @@ def __init__(
namespace=None,
client=None,
teardown=True,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
backoff_limit=None,
Expand All @@ -52,7 +50,6 @@ def __init__(
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand Down
3 changes: 0 additions & 3 deletions ocp_resources/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(
namespace=None,
client=None,
teardown=True,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
holder_identity=None,
Expand All @@ -37,7 +36,6 @@ def __init__(
lease_transitions (int, optional): number of transitions of a lease between holders.
acquire_time (time, optional): when the current lease was acquired
renew_time (time, optional): when current holder of the lease has last updated it
privileged_client (DynamicClient): Privileged client for api calls
yaml_file (str): yaml file for the resource.
delete_timeout (int): timeout associated with delete action
"""
Expand All @@ -46,7 +44,6 @@ def __init__(
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand Down
2 changes: 0 additions & 2 deletions ocp_resources/ocs_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def __init__(
namespace=None,
client=None,
teardown=False,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
enable_ceph_tools=None,
Expand All @@ -33,7 +32,6 @@ def __init__(
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand Down
2 changes: 1 addition & 1 deletion ocp_resources/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def node(self) -> Node:
node_name = self.instance.spec.nodeName
assert node_name, f"Node not found for pod {self.name}"
return Node(
client=self.privileged_client or self.client,
client=self.client,
name=node_name,
)

Expand Down
17 changes: 12 additions & 5 deletions ocp_resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import copy
import json
from warnings import warn

import os
import re
import sys
Expand Down Expand Up @@ -499,21 +501,28 @@ def __init__(
kind_dict (dict): dict which represents the resource object
wait_for_resource (bool): Waits for the resource to be created
"""
if privileged_client:
warn(
"privileged_client is deprecated and will be removed in the future. Use client instead.",
DeprecationWarning,
stacklevel=2,
)

if yaml_file and kind_dict:
raise ValueError("yaml_file and resource_dict are mutually exclusive")

self.name = name
self.teardown = teardown
self.timeout = timeout
self.privileged_client = privileged_client
self.privileged_client = client
self.yaml_file = yaml_file
self.kind_dict = kind_dict
self.delete_timeout = delete_timeout
self.dry_run = dry_run
self.node_selector = node_selector
self.node_selector_labels = node_selector_labels
self.config_file = config_file
if not isinstance(config_file, str):
if not isinstance(self.config_file, str):
# If we pass config_file which isn't a string, get_client will fail and it will be very hard to know why.
# Better fail here and let the user know.
raise ValueError("config_file must be a string")
Expand Down Expand Up @@ -1121,7 +1130,7 @@ def api_request(self, method: str, action: str, url: str, **params: Any) -> Dict
data(dict): response data
"""
client: DynamicClient = self.privileged_client or self.client
client: DynamicClient = self.client
response = client.client.request(
method=method,
url=f"{url}/{action}",
Expand Down Expand Up @@ -1313,7 +1322,6 @@ def __init__(
yaml_file: str = "",
delete_timeout: int = TIMEOUT_4MINUTES,
client: DynamicClient | None = None,
privileged_client: DynamicClient | None = None,
ensure_exists: bool = False,
**kwargs: Any,
):
Expand All @@ -1322,7 +1330,6 @@ def __init__(
client=client,
teardown=teardown,
timeout=timeout,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand Down
2 changes: 0 additions & 2 deletions ocp_resources/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def __init__(
backup_name=None,
client=None,
teardown=False,
privileged_client=None,
yaml_file=None,
**kwargs,
):
Expand All @@ -27,7 +26,6 @@ def __init__(
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
**kwargs,
)
Expand Down
3 changes: 0 additions & 3 deletions ocp_resources/virtual_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def __init__(
client=None,
body=None,
teardown=True,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
**kwargs,
Expand All @@ -57,7 +56,6 @@ def __init__(
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand Down Expand Up @@ -142,7 +140,6 @@ def vmi(self):
client=self.client,
name=self.name,
namespace=self.namespace,
privileged_client=self.privileged_client or self.client,
)

@property
Expand Down
3 changes: 0 additions & 3 deletions ocp_resources/virtual_machine_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def __init__(
resource_mapping_namespace=None,
warm=False,
finalize_date=None,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
**kwargs,
Expand All @@ -113,7 +112,6 @@ def __init__(
namespace=namespace,
client=client,
teardown=teardown,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand All @@ -139,7 +137,6 @@ def vm(self):
name=self.target_vm_name,
namespace=self.namespace,
client=self.client,
privileged_client=self.privileged_client or self.client,
)

def to_dict(self) -> None:
Expand Down
8 changes: 3 additions & 5 deletions ocp_resources/virtual_machine_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def __init__(
name=None,
namespace=None,
client=None,
privileged_client=None,
yaml_file=None,
delete_timeout=TIMEOUT_4MINUTES,
**kwargs,
Expand All @@ -35,7 +34,6 @@ def __init__(
name=name,
namespace=namespace,
client=client,
privileged_client=privileged_client,
yaml_file=yaml_file,
delete_timeout=delete_timeout,
**kwargs,
Expand Down Expand Up @@ -70,7 +68,7 @@ def interfaces(self):
def virt_launcher_pod(self):
pods = list(
Pod.get(
dyn_client=self.privileged_client or self.client,
dyn_client=self.client,
namespace=self.namespace,
label_selector=f"kubevirt.io=virt-launcher,kubevirt.io/created-by={self.instance.metadata.uid}",
)
Expand All @@ -92,7 +90,7 @@ def virt_launcher_pod(self):
def virt_handler_pod(self):
pods = list(
Pod.get(
dyn_client=self.privileged_client or self.client,
dyn_client=self.client,
label_selector="kubevirt.io=virt-handler",
)
)
Expand Down Expand Up @@ -189,7 +187,7 @@ def node(self):
Node: Node
"""
return Node(
client=self.privileged_client or self.client,
client=self.client,
name=self.instance.status.nodeName,
)

Expand Down

0 comments on commit 0908166

Please sign in to comment.