def verify_sanity(ctx, namespace): # check if KUBECONFIG is set else find kubeconfig file and set the # environment variable constants = ctx.obj # set kubeconfig kubeconfig = os.environ.get('KUBECONFIG') if not kubeconfig: kubeconfigs = glob.glob(constants['project_dir'] + "/kubeconfig_*") if len(kubeconfigs) != 1: if len(kubeconfigs) == 0: print_success_msg('No kubeconfig found!!!') else: print_error_msg("multiple kubeconfigs found %s!!!" % repr(kubeconfigs)) return kubeconfig = kubeconfigs[0] set_kubeconfig_environ(kubeconfig) # check if we have a valid namespace all_namespaces = get_all_namespaces(kubeconfig) while namespace not in all_namespaces: namespace = click.prompt('Provide orc8r namespace', type=click.Choice(all_namespaces)) rc = run_playbook(verify_cmd(ctx.obj, namespace)) if rc != 0: print_error_msg("Post deployment verification checks failed!!!") sys.exit(1) print_success_msg("Post deployment verification ran successfully")
def precheck(ctx): """ Performs various checks to ensure successful upgrade """ rc = run_playbook(precheck_cmd(ctx.obj)) if rc != 0: print_error_msg("Upgrade prechecks failed!!!") sys.exit(1) print_success_msg("Upgrade prechecks ran successfully")
def tf_install(constants: dict, warn: bool = True, max_retries: int = 2) -> int: """Run through terraform installation Args: constants (dict): config dict warn (bool, optional): require user confirmation. Defaults to True. max_retries (int): Number of times to retry in case of a failure. Returns: int: return code """ tf_init = ["terraform", "init"] tf_orc8r = ["terraform", "apply", "-target=module.orc8r", "-auto-approve"] tf_secrets = [ "terraform", "apply", "-target=module.orc8r-app.null_resource.orc8r_seed_secrets", "-auto-approve"] tf_orc8r_app = ["terraform", "apply", "-auto-approve"] for tf_cmd in [tf_init, tf_orc8r, tf_secrets, tf_orc8r_app]: cmd = " ".join(tf_cmd) if warn and not click.confirm(f'Do you want to continue with {cmd}?'): continue for i in range(max_retries): # terraform fails randomly due to timeouts click.echo(f"Running {tf_cmd}, iteration {i}") rc = execute_command(tf_cmd, cwd=constants['project_dir']) if rc == 0: break print_error_msg(f"Install failed when running {cmd} !!!") if i == (max_retries - 1): print_error_msg(f"Max retries exceeded!!!") return 1 # set the kubectl after bringing up the infra if tf_cmd in (tf_orc8r, tf_orc8r_app): kubeconfigs = glob.glob( constants['project_dir'] + "/kubeconfig_*") if len(kubeconfigs) != 1: print_error_msg( "zero or multiple kubeconfigs found %s!!!" % repr(kubeconfigs)) return kubeconfig = kubeconfigs[0] os.environ['KUBECONFIG'] = kubeconfig print_info_msg( 'For accessing kubernetes cluster, set' f' `export KUBECONFIG={kubeconfig}`') print_success_msg(f"Command {cmd} ran successfully") else: print_warning_msg(f"Skipping Command {cmd}") return 0
def check(self, component: str) -> bool: ''' check if all mandatory options of a specific component is set ''' cfgs = self.configs[component] valid = True missing_cfgs = [] for k, v in self.config_vars[component].items(): if v['Required'] and cfgs.get(k) is None: missing_cfgs.append(k) valid = False if missing_cfgs: print_error_msg( f"Missing {missing_cfgs!r} configs for {component} component") else: print_success_msg( f"All mandatory configs for {component} has been configured") return valid