2121import yaml
2222
2323from .ocp import createNamespace
24+ from .utils import isVersionEqualOrAfter
2425
2526logger = logging .getLogger (__name__ )
2627
@@ -121,6 +122,9 @@ def getSubscription(dynClient: DynamicClient, namespace: str, packageName: str):
121122
122123def _getSubscriptionConstraintMessage (subscriptionResource ):
123124 conditions = getattr (getattr (subscriptionResource , "status" , None ), "conditions" , [])
125+ if not isinstance (conditions , list ):
126+ return None
127+
124128 for condition in conditions :
125129 conditionType = getattr (condition , "type" , None )
126130 reason = getattr (condition , "reason" , None )
@@ -137,14 +141,15 @@ def _parseConstraintMessage(message: str):
137141 existingCSV = existingCSVMatch .group (1 ) if existingCSVMatch else None
138142 requiredCSV = requiredCSVMatch .group (1 ) if requiredCSVMatch else None
139143
144+ existingVersion = existingCSV .rsplit (".v" , 1 )[- 1 ] if existingCSV and ".v" in existingCSV else None
145+ requiredVersion = requiredCSV .rsplit (".v" , 1 )[- 1 ] if requiredCSV and ".v" in requiredCSV else None
146+
140147 scenario = None
141- if existingCSV and requiredCSV :
142- existingVersion = existingCSV .rsplit (".v" , 1 )[- 1 ] if ".v" in existingCSV else existingCSV
143- requiredVersion = requiredCSV .rsplit (".v" , 1 )[- 1 ] if ".v" in requiredCSV else requiredCSV
144- if existingVersion > requiredVersion :
145- scenario = "catalog_behind"
146- else :
148+ if existingVersion and requiredVersion :
149+ if isVersionEqualOrAfter (existingVersion , requiredVersion ):
147150 scenario = "marketplace_cache"
151+ else :
152+ scenario = "catalog_behind"
148153
149154 return {
150155 "scenario" : scenario ,
0 commit comments