@@ -51,15 +51,46 @@ def installOpenShiftPipelines(dynClient: DynamicClient, customStorageClassName:
5151 subscriptionsAPI = dynClient .resources .get (api_version = "operators.coreos.com/v1alpha1" , kind = "Subscription" )
5252
5353 # Create the Operator Subscription
54- try :
55- if not crdExists (dynClient , "pipelines.tekton.dev" ):
56- manifest = packagemanifestAPI .get (name = "openshift-pipelines-operator-rh" , namespace = "openshift-marketplace" )
54+ if not crdExists (dynClient , "pipelines.tekton.dev" ):
55+ # Retry logic for finding the package manifest
56+ max_retries = 50
57+ retry_delay = 20 # seconds
58+ attempts = 0
59+ manifest = None
60+
61+ logger .info ("Attempting to locate OpenShift Pipelines Operator package manifest..." )
62+
63+ while attempts < max_retries :
64+ try :
65+ manifest = packagemanifestAPI .get (name = "openshift-pipelines-operator-rh" , namespace = "openshift-marketplace" )
66+ logger .info ("Successfully found OpenShift Pipelines Operator package manifest" )
67+ break
68+ except NotFoundError as e :
69+ attempts += 1
70+ if attempts < max_retries :
71+ logger .warning (f"Package manifest not found (attempt { attempts } /{ max_retries } ). Retrying in { retry_delay } seconds..." )
72+ sleep (retry_delay )
73+ else :
74+ logger .error (f"Failed to find package manifest for Red Hat OpenShift Pipelines Operator after { max_retries } attempts" )
75+ logger .error (f"The operator package manifest is not available in the openshift-marketplace namespace: { e } " )
76+ return False
77+ except Exception as e :
78+ logger .error (f"Unexpected error while retrieving package manifest: { e } " )
79+ return False
80+
81+ if manifest is None :
82+ logger .error ("Failed to retrieve package manifest - cannot proceed with operator installation" )
83+ return False
84+
85+ # Extract operator details from manifest
86+ try :
5787 defaultChannel = manifest .status .defaultChannel
5888 catalogSource = manifest .status .catalogSource
5989 catalogSourceNamespace = manifest .status .catalogSourceNamespace
6090
6191 logger .info (f"OpenShift Pipelines Operator Details: { catalogSourceNamespace } /{ catalogSource } @{ defaultChannel } " )
6292
93+ # Create subscription
6394 templateDir = path .join (path .abspath (path .dirname (__file__ )), "templates" )
6495 env = Environment (
6596 loader = FileSystemLoader (searchpath = templateDir )
@@ -75,11 +106,14 @@ def installOpenShiftPipelines(dynClient: DynamicClient, customStorageClassName:
75106 )
76107 subscription = yaml .safe_load (renderedTemplate )
77108 subscriptionsAPI .apply (body = subscription , namespace = "openshift-operators" )
109+ logger .info ("OpenShift Pipelines Operator subscription created successfully" )
78110
79- except NotFoundError :
80- logger .warning ("Error: Couldn't find package manifest for Red Hat Openshift Pipelines Operator" )
81- except UnprocessibleEntityError :
82- logger .warning ("Error: Couldn't create/update OpenShift Pipelines Operator Subscription" )
111+ except UnprocessibleEntityError as e :
112+ logger .error (f"Error: Couldn't create/update OpenShift Pipelines Operator Subscription: { e } " )
113+ return False
114+ except Exception as e :
115+ logger .error (f"Unexpected error while creating operator subscription: { e } " )
116+ return False
83117
84118 # Wait for the CRD to be available
85119 logger .debug ("Waiting for tasks.tekton.dev CRD to be available" )
0 commit comments