4040from ..utils .file import write_tmp_file
4141from ..utils .console import xpk_print , xpk_exit , ask_for_user_consent
4242from ..utils .templates import TEMPLATE_PATH , get_templates_absolute_path
43- from packaging .version import Version
43+ from packaging .version import Version , InvalidVersion
4444
4545KUEUE_VERSION = Version ("v0.15.2" )
4646LATEST_BREAKING_VERSION = Version ("v0.15.0" )
@@ -113,7 +113,13 @@ def install_or_upgrade(
113113 return_code , installed_version = get_installed_kueue_version ()
114114
115115 if return_code == 0 and installed_version :
116- if installed_version > self .kueue_version :
116+ if isinstance (installed_version , str ):
117+ xpk_print (
118+ "Cluster has an unknown or custom Kueue version installed. Skipping"
119+ " installation."
120+ )
121+ return 0
122+ elif installed_version > self .kueue_version :
117123 xpk_print (
118124 f"Cluster has a newer Kueue version, { installed_version } . Skipping"
119125 " installation."
@@ -532,7 +538,16 @@ def __autocorrect_resource_limits(
532538
533539def get_installed_kueue_version (
534540 dry_run_version : Version | None = None ,
535- ) -> tuple [int , Version | None ]:
541+ ) -> tuple [int , Version | str | None ]:
542+ """Gets the currently installed Kueue version from the cluster.
543+
544+ Returns a tuple containing:
545+ - The return code of the kubectl command.
546+ - The version information:
547+ - None if the command fails or the value is empty (e.g. Kueue not installed).
548+ - A Version object if the image tag can be parsed as a valid version.
549+ - A string if the image tag contains a custom SHA or is unparseable.
550+ """
536551 command = (
537552 "kubectl get deployment kueue-controller-manager -n kueue-system -o"
538553 " jsonpath='{.spec.template.spec.containers[0].image}'"
@@ -547,12 +562,17 @@ def get_installed_kueue_version(
547562 else ""
548563 ),
549564 )
550- if return_code != 0 :
565+ if return_code != 0 or not val :
551566 return return_code , None
552- version_tag = val .split (":" )
553- if len (version_tag ) == 1 :
554- return 1 , None
555- return return_code , Version (version_tag [- 1 ])
567+
568+ if "@sha256:" in val or ":" not in val :
569+ return return_code , val
570+
571+ version_tag = val .split (":" )[- 1 ]
572+ try :
573+ return return_code , Version (version_tag )
574+ except InvalidVersion :
575+ return return_code , val
556576
557577
558578def has_sub_slicing_enabled () -> tuple [int , bool | None ]:
0 commit comments