From b123ca90de5c4abe5014bd32196bed657added1d Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 28 Aug 2024 18:40:46 +0100 Subject: [PATCH] Make gke login optional (#24) * Make GKE configuration and context setup optional * Improve variable with prefix and make conditional explicit --------- Co-authored-by: Oliver Hookins --- fycli/kubernetes/cli.py | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/fycli/kubernetes/cli.py b/fycli/kubernetes/cli.py index 6e9703f..9517e02 100644 --- a/fycli/kubernetes/cli.py +++ b/fycli/kubernetes/cli.py @@ -15,7 +15,7 @@ from ..environment.environment import Environment, EnvironmentError try: - from sh import kubectl, kube_score, kapp + from sh import kapp, kube_score, kubectl except ImportError as error: for command in ["gcloud", "kube-score", "kubectl", "kapp"]: if re.search(r".*'" + command + "'.*", str(error)): @@ -77,7 +77,8 @@ def _setup(self, args, disable_gcloud_sandbox=False): except KeyError: pass - self.environment.activate_container_cluster_context() + if not os.environ.get("FY_KUBECTL_CONFIGURE") == "false": + self.environment.activate_container_cluster_context() def _detect_manifest_dir_type(self): fy_deployment_config_file = Path( @@ -116,7 +117,10 @@ def _detect_manifest_dir_type(self): def use(self): parser = ExtendedHelpArgumentParser(usage="\n fy k8s use [-h|--help]") parser.add_argument( - "-s", "--skip-version-check", help="skip dependency version check", action="store_true" + "-s", + "--skip-version-check", + help="skip dependency version check", + action="store_true", ) parser.add_argument( "--skip-environment", help="skip environment", action="store_true" @@ -131,7 +135,10 @@ def use(self): def diff(self): parser = ExtendedHelpArgumentParser(usage="\n fy k8s diff [-h|--help]") parser.add_argument( - "-s", "--skip-version-check", help="skip dependency version check", action="store_true" + "-s", + "--skip-version-check", + help="skip dependency version check", + action="store_true", ) parser.add_argument( "--skip-environment", help="skip environment", action="store_true" @@ -148,11 +155,12 @@ def diff(self): def apply(self): parser = ExtendedHelpArgumentParser(usage="\n fy k8s apply [-h|--help]") parser.add_argument( - "-s", "--skip-version-check", help="skip dependency version check", action="store_true" - ) - parser.add_argument( - "--skip-diff", help="skip diff", action="store_true" + "-s", + "--skip-version-check", + help="skip dependency version check", + action="store_true", ) + parser.add_argument("--skip-diff", help="skip diff", action="store_true") parser.add_argument( "--skip-environment", help="skip environment", action="store_true" ) @@ -257,14 +265,15 @@ def apply(self): def plan(self): parser = ExtendedHelpArgumentParser(usage="\n fy k8s plan [-h|--help]") parser.add_argument( - "-s", "--skip-version-check", help="skip dependency version check", action="store_true" + "-s", + "--skip-version-check", + help="skip dependency version check", + action="store_true", ) parser.add_argument( "--skip-environment", help="skip environment", action="store_true" ) - parser.add_argument( - "--skip-diff", help="skip diff", action="store_true" - ) + parser.add_argument("--skip-diff", help="skip diff", action="store_true") parser.add_argument( "--skip-kube-score", help="skip kube-score", action="store_true" ) @@ -369,7 +378,10 @@ def plan(self): def delete(self): parser = ExtendedHelpArgumentParser(usage="\n fy k8s delete [-h|--help]") parser.add_argument( - "-s", "--skip-version-check", help="skip dependency version check", action="store_true" + "-s", + "--skip-version-check", + help="skip dependency version check", + action="store_true", ) parser.add_argument( "--skip-environment", help="skip environment", action="store_true" @@ -591,4 +603,3 @@ def _handle_error(self, error): print("\n==> exception caught!") print("\n==> stack trace\n") raise -