11from __future__ import annotations
22
33import logging
4+ import os
45import time
56from typing import Dict , List , Optional
67
1617 helm_template ,
1718 helm_uninstall ,
1819 helm_upgrade ,
20+ oci_chart_info ,
21+ oci_helm_registry_login ,
1922)
2023from tests import test_logger
2124
@@ -43,13 +46,27 @@ def __init__(
4346 namespace : str ,
4447 helm_args : Optional [Dict ] = None ,
4548 helm_options : Optional [List [str ]] = None ,
46- helm_chart_path : Optional [str ] = "helm_chart" ,
49+ helm_chart_path : Optional [str ] = None ,
4750 name : Optional [str ] = "mongodb-kubernetes-operator" ,
4851 api_client : Optional [client .api_client .ApiClient ] = None ,
52+ operator_version : Optional [str ] = None ,
4953 ):
54+ if not helm_chart_path :
55+ # login to the OCI container registry
56+ registry , repository , region = oci_chart_info ()
57+ try :
58+ oci_helm_registry_login (registry , region )
59+ except Exception as e :
60+ raise e
5061
51- # The Operator will be installed from the following repo, so adding it first
52- helm_repo_add ("mongodb" , "https://mongodb.github.io/helm-charts" )
62+ # figure out the registry URI, based on dev/staging scenario
63+ chart_uri = f"oci://{ registry } /{ repository } "
64+ helm_chart_path = chart_uri
65+
66+ if not operator_version :
67+ # most probably we are trying to install current operator which will be installed
68+ # from OCI registry. The version (dev/staging) is set in `OPERATOR_VERSION`
69+ operator_version = os .environ .get ("OPERATOR_VERSION" )
5370
5471 if helm_args is None :
5572 helm_args = {}
@@ -69,6 +86,7 @@ def __init__(
6986 self .helm_chart_path = helm_chart_path
7087 self .name = name
7188 self .api_client = api_client
89+ self .operator_version = operator_version
7290
7391 def install_from_template (self ):
7492 """Uses helm to generate yaml specification and then uses python K8s client to apply them to the cluster
@@ -82,6 +100,9 @@ def install_from_template(self):
82100
83101 def install (self , custom_operator_version : Optional [str ] = None ) -> Operator :
84102 """Installs the Operator to Kubernetes cluster using 'helm install', waits until it's running"""
103+ if not custom_operator_version :
104+ custom_operator_version = self .operator_version
105+
85106 helm_install (
86107 self .name ,
87108 self .namespace ,
@@ -99,6 +120,9 @@ def upgrade(
99120 self , multi_cluster : bool = False , custom_operator_version : Optional [str ] = None , apply_crds_first : bool = False
100121 ) -> Operator :
101122 """Upgrades the Operator in Kubernetes cluster using 'helm upgrade', waits until it's running"""
123+ if not custom_operator_version :
124+ custom_operator_version = self .operator_version
125+
102126 helm_upgrade (
103127 self .name ,
104128 self .namespace ,
0 commit comments