Skip to content

Commit eaea18e

Browse files
authored
Add option to uninstall_operator to avoid ns cleanup (#364)
* Add option to uninstall_operator to avoid ns cleanup * Add option to uninstall_operator to avoid ns cleanup
1 parent e237f3b commit eaea18e

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

ocp_utilities/operators.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def uninstall_operator(
273273
name: str,
274274
timeout: int = TIMEOUT_30MIN,
275275
operator_namespace: str = "",
276+
clean_up_namespace: bool = True,
276277
) -> None:
277278
"""
278279
Uninstall operator on cluster.
@@ -282,8 +283,8 @@ def uninstall_operator(
282283
name (str): Name of the operator to uninstall.
283284
timeout (int): Timeout in seconds to wait for operator to be uninstalled.
284285
operator_namespace (str, optional): Operator namespace, if not provided, operator name will be used
286+
clean_up_namespace (bool, optional): Used to decide if operator_namespace should be cleaned up. Defaults to True.
285287
"""
286-
287288
csv_name = None
288289
operator_namespace = operator_namespace or name
289290
subscription = Subscription(
@@ -301,13 +302,14 @@ def uninstall_operator(
301302
namespace=operator_namespace,
302303
).clean_up()
303304

304-
for _operator in Operator.get(dyn_client=admin_client):
305-
if _operator.name.startswith(name):
306-
# operator name convention is <name>.<namespace>
307-
namespace = operator_namespace or name.split(".")[-1]
308-
ns = Namespace(client=admin_client, name=namespace)
309-
if ns.exists:
310-
ns.clean_up()
305+
if clean_up_namespace:
306+
for _operator in Operator.get(dyn_client=admin_client):
307+
if _operator.name.startswith(name):
308+
# operator name convention is <name>.<namespace>
309+
namespace = operator_namespace or name.split(".")[-1]
310+
ns = Namespace(client=admin_client, name=namespace)
311+
if ns.exists:
312+
ns.clean_up()
311313

312314
if csv_name:
313315
csv = ClusterServiceVersion(
@@ -316,7 +318,7 @@ def uninstall_operator(
316318
name=csv_name,
317319
)
318320

319-
csv.wait_deleted(timeout=timeout)
321+
csv.wait_deleted(timeout=timeout) if clean_up_namespace else csv.clean_up(wait=True)
320322

321323

322324
def create_catalog_source_for_iib_install(

0 commit comments

Comments
 (0)