@@ -135,6 +135,7 @@ def install_operator(
135
135
target_namespaces = None ,
136
136
timeout = TIMEOUT_30MIN ,
137
137
operator_namespace = None ,
138
+ source_image = None ,
138
139
iib_index_image = None ,
139
140
brew_token = None ,
140
141
):
@@ -145,13 +146,17 @@ def install_operator(
145
146
admin_client (DynamicClient): Cluster client.
146
147
name (str): Name of the operator to install.
147
148
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.
149
150
target_namespaces (list, optional): Target namespaces for the operator install process.
150
151
If not provided, a namespace with te operator name will be created and used.
151
152
timeout (int): Timeout in seconds to wait for operator to be ready.
152
153
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.
153
155
iib_index_image (str, optional): iib index image url, If provided install operator from iib index image.
154
156
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)
155
160
"""
156
161
catalog_source = None
157
162
operator_market_namespace = "openshift-marketplace"
@@ -167,9 +172,17 @@ def install_operator(
167
172
operator_market_namespace = operator_market_namespace ,
168
173
admin_client = admin_client ,
169
174
)
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
+ )
170
183
else :
171
184
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 " )
173
186
174
187
operator_namespace = operator_namespace or name
175
188
if target_namespaces :
@@ -339,14 +352,42 @@ def _icsp(_repository_digest_mirrors):
339
352
admin_client = admin_client ,
340
353
)
341
354
342
- catalog_source = CatalogSource (
355
+ iib_catalog_source = create_catalog_source_from_image (
356
+ admin_client = admin_client ,
343
357
name = name ,
344
358
namespace = operator_market_namespace ,
345
- display_name = name ,
346
359
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 ,
347
388
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" ,
350
391
)
351
392
catalog_source .deploy (wait = True )
352
393
return catalog_source
0 commit comments