def run_helm_upgrade(self, options: Optional[Dict[str, Optional[str]]] = None): """ Runs 'helm upgrade' on the chart :param options: A dictionary of command line arguments to pass to helm :Example: >>> self.run_helm_upgrade(options={"atomic": None, "version": "2.0"}) """ info(f"Upgrading helm chart {self.chart_info.name}") custom_check_output(self.__get_helm_upgrade_command(options))
def run_helm_install(self, options: Optional[Dict[str, Optional[str]]] = None): """ Runs helm install on the chart :param options: A dictionary of command line arguments to pass to helm :Example: To run an install with updated dependencies and with verbose logging: >>> self.run_helm_install({"dependency_update": None, "v": "info"}) """ custom_check_output(self.__get_helm_install_command(options))
def get_config_map_data(): output = custom_check_output("kubectl describe configmap") match = re.match(r".*Data\n====\n(?P<data>.*)Events:.*", output, re.DOTALL) if not match: raise Exception("Match must exist to get config map data!") data_string = match.group("data").replace("----\n", "").replace(":\n", ": ") data = yaml.safe_load(data_string) return data
def run_helm_uninstall(self, options: Optional[Dict[str, Optional[str]]] = None): """ Runs helm uninstall :param options: A dictionary of command line arguments to pass to helm :Example: >>> self.run_helm_uninstall( >>> {"dry-run": None, >>> "description": "My uninstall description" >>> } >>> ) """ info(f"Uninstalling chart {self.chart_info.name}") custom_check_output(self.__get_helm_uninstall_command(options))
def _helm_list_repos(self) -> List[str]: try: return custom_check_output("helm repo list").split("\n")[1:] except subprocess.CalledProcessError as err: error_message = err.output.decode("utf-8").strip() if error_message == "Error: no repositories to show": return [] error(error_message) raise err
def upgrade_chart(self, options: Optional[Dict[str, Optional[str]]] = None): """ Generates and upgrades the helm chart :param options: A dictionary of command line arguments to pass to helm :Example: >>> self.upgrade_chart(options={"atomic": None, "version": "2.0"}) """ self.__check_if_installed() self.generate_chart() self.add_dependency_repos() update_depenedencies = "dependency-update" if options is not None and update_depenedencies in options: custom_check_output( f"helm dependency update {self.chart_folder_path.resolve()}") del options[update_depenedencies] self.__handle_upgrade(options)
def kubectl_get(resource: str, namespace: Optional[str] = None, wide: bool = False): try: command = f"kubectl get {resource}" if namespace: command += f" -n {namespace}" if wide: command += " -o wide" return parse_output_to_dict(custom_check_output(command)) except CalledProcessError as err: raise KubectlGetException(err.output)
def remove_stable_repo(): custom_check_output("helm repo remove stable")
def get_helm_installations(namespace: Optional[str] = None): command = "helm list" if namespace is not None: command += f" -n {namespace}" output = custom_check_output(command) return parse_output_to_dict(output)
def add_repo(self): custom_check_output( f"helm repo add {self.__local_repo_name} {self.repository}")