Skip to content

Commit a684441

Browse files
install operator from source_image (#290)
* install operator from source_image * add catalogsource func * add client param
1 parent d9fe02c commit a684441

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed

ocp_utilities/operators.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def install_operator(
135135
target_namespaces=None,
136136
timeout=TIMEOUT_30MIN,
137137
operator_namespace=None,
138+
source_image=None,
138139
iib_index_image=None,
139140
brew_token=None,
140141
):
@@ -145,13 +146,17 @@ def install_operator(
145146
admin_client (DynamicClient): Cluster client.
146147
name (str): Name of the operator to install.
147148
channel (str): Channel to install operator from.
148-
source (str, optional): CatalogSource name.
149+
source (str, optional): CatalogSource name. Source must be provided if iib_index_image or source_image not provided.
149150
target_namespaces (list, optional): Target namespaces for the operator install process.
150151
If not provided, a namespace with te operator name will be created and used.
151152
timeout (int): Timeout in seconds to wait for operator to be ready.
152153
operator_namespace (str, optional): Operator namespace, if not provided, operator name will be used.
154+
source_image (str, optional): Source image url, If provided install operator from this CatalogSource Image.
153155
iib_index_image (str, optional): iib index image url, If provided install operator from iib index image.
154156
brew_token (str, optional): Token to access iib index image registry.
157+
158+
Raises:
159+
ValueError: When either one of them not provided (source, source_image, iib_index_image)
155160
"""
156161
catalog_source = None
157162
operator_market_namespace = "openshift-marketplace"
@@ -167,9 +172,17 @@ def install_operator(
167172
operator_market_namespace=operator_market_namespace,
168173
admin_client=admin_client,
169174
)
175+
elif source_image:
176+
source_name = f"catalog-{name}"
177+
catalog_source = create_catalog_source_from_image(
178+
admin_client=admin_client,
179+
name=source_name,
180+
namespace=operator_market_namespace,
181+
image=source_image,
182+
)
170183
else:
171184
if not source:
172-
raise ValueError("source must be provided if not using iib_index_image")
185+
raise ValueError("source must be provided if not using iib_index_image or source_image")
173186

174187
operator_namespace = operator_namespace or name
175188
if target_namespaces:
@@ -339,14 +352,42 @@ def _icsp(_repository_digest_mirrors):
339352
admin_client=admin_client,
340353
)
341354

342-
catalog_source = CatalogSource(
355+
iib_catalog_source = create_catalog_source_from_image(
356+
admin_client=admin_client,
343357
name=name,
344358
namespace=operator_market_namespace,
345-
display_name=name,
346359
image=_iib_index_image,
360+
)
361+
return iib_catalog_source
362+
363+
364+
def create_catalog_source_from_image(
365+
name, namespace, image, source_type=None, update_strategy_registry_poll_interval=None, admin_client=None
366+
):
367+
"""
368+
Create CatalogSource for given image
369+
370+
Args:
371+
admin_client (DynamicClient): Cluster client.
372+
name (str): Name for the catalog source (used in 'name, display_name and publisher').
373+
image (str): Image index for the catalog.
374+
namespace (str): Namespace where CatalogSource will be created.
375+
source_type (str, optional): Name of the source type.
376+
update_strategy_registry_poll_interval (str, optional): Time interval between checks of the latest
377+
catalog_source version.
378+
379+
Returns:
380+
CatalogSource: catalog source object.
381+
"""
382+
catalog_source = CatalogSource(
383+
client=admin_client,
384+
name=name,
385+
namespace=namespace,
386+
display_name=name,
387+
image=image,
347388
publisher=name,
348-
source_type="grpc",
349-
update_strategy_registry_poll_interval="30m",
389+
source_type=source_type or "grpc",
390+
update_strategy_registry_poll_interval=update_strategy_registry_poll_interval or "30m",
350391
)
351392
catalog_source.deploy(wait=True)
352393
return catalog_source

0 commit comments

Comments
 (0)