diff --git a/oper8/reconcile.py b/oper8/reconcile.py index 6ed2b29..1cf619a 100644 --- a/oper8/reconcile.py +++ b/oper8/reconcile.py @@ -131,6 +131,8 @@ def __init__( else: self.home_dir = os.getcwd() + # Create an empty variable for VCS creation. This will be initialized + # during reconcile self.vcs = None # If enable_vcs is not provided than default to @@ -138,6 +140,7 @@ def __init__( if enable_vcs is None: enable_vcs = config.vcs.enabled + self.enable_vcs = enable_vcs if enable_vcs: assert_config( config.vcs.repo, @@ -153,8 +156,6 @@ def __init__( f"VCS checkout method must be one of the following {vcs_checkout_methods}", ) - self.vcs = VCS(self.home_dir) - # Ensure config is setup correctly for strict_versioning if config.strict_versioning: assert_config( @@ -219,6 +220,10 @@ def reconcile( result = ReconciliationResult(requeue=False, requeue_params=RequeueParams()) return result + # If vcs is enabled then configure the repo + if self.enable_vcs: + self.vcs = VCS(self.home_dir) + # Check strict versioning before continuing if config.strict_versioning: self._check_strict_versioning(cr_manifest) @@ -403,6 +408,11 @@ def setup_vcs(self, cr_manifest: aconfig.Config): cr_manifest: aconfig.Config The cr manifest to pull the requested version from. """ + # If vcs still has not created then create it here. This + # is mainly used by tests + if not self.vcs: + self.vcs = VCS(self.home_dir) + version = get_manifest_version(cr_manifest) if not version: raise ValueError("CR Manifest has no version") @@ -625,7 +635,11 @@ def _check_strict_versioning(self, cr_manifest: aconfig.Config): ) # If VCS is enabled ensure the branch or tag exists - if self.vcs: + if self.enable_vcs: + # If vcs is not created then create it here + if not self.vcs: + self.vcs = VCS(self.home_dir) + repo_versions = self.vcs.list_refs() assert_config( version in repo_versions,