From 4de48ad2b494cebbc9745238b9d6693954dfaf08 Mon Sep 17 00:00:00 2001 From: jewee Date: Fri, 18 Oct 2019 21:21:07 +0300 Subject: [PATCH] added exception when cluster.fqdn missing (#85) * added exception when cluster.fqdn missing * [RELEASE] - Release version 1.11.8 * added option to continue with current context * added exception error msg * Revert "[RELEASE] - Release version 1.11.8" This reverts commit 29a5c578db14da2101ad356e2a6eebcf98c7a0c0. --- src/ops/cli/helmfile.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/ops/cli/helmfile.py b/src/ops/cli/helmfile.py index e2799771..77737698 100644 --- a/src/ops/cli/helmfile.py +++ b/src/ops/cli/helmfile.py @@ -11,7 +11,10 @@ import logging import os +import six +import sys +from kubernetes import config from ops.cli.parser import SubParserConfig from ops.hierarchical.composition_config_generator import CompositionConfigGenerator @@ -87,6 +90,25 @@ def setup_kube_config(self, data): file_location = self.generate_eks_kube_config( cluster_name, aws_profile, region) os.environ['KUBECONFIG'] = file_location + else: + logger.info('cluster.fqdn key missing in cluster definition' + '\n unable to generate EKS kubeconfig\n ' + 'looking for system kubernetes context') + + try: + contexts, active_context = config.list_kube_config_contexts() + except Exception as ex: + logger.error('could not find system kubeconfig context') + logger.error(ex) + sys.exit() + + logger.info('current default context is:\n %s ' + '\n do you want to proceed with this context?', + active_context) + answer = six.moves.input("Only 'yes' will be accepted to approve.\n Enter a value:") + if answer != "yes": + sys.exit() + def generate_eks_kube_config(self, cluster_name, aws_profile, region): file_location = self.get_tmp_file()