def run_compositions(self, args, extra_args, config_path, compositions): return_code = 0 for composition in compositions: logger.info("Running composition: %s", composition) filtered_output_keys = self.kompos_config.filtered_output_keys( composition) excluded_config_keys = self.kompos_config.excluded_config_keys( composition) tf_config_generator = TerraformConfigGenerator( excluded_config_keys, filtered_output_keys) pre_config_generator = PreConfigGenerator(excluded_config_keys, filtered_output_keys) raw_config = pre_config_generator.pre_generate_config( config_path, composition) cloud_type = raw_config["cloud"]["type"] # Use the default local repo (not versioned). terraform_composition_path = os.path.join( self.kompos_config.terraform_local_path(), self.kompos_config.terraform_root_path(), cloud_type, ) # Overwrite with the nix output, if the nix integration is enabled. if is_nix_enabled(args, self.kompos_config.nix()): pname = self.kompos_config.terraform_repo_name() nix_install( pname, self.kompos_config.terraform_repo_url(), get_value_or(raw_config, 'infrastructure/terraform/version', 'master'), get_value_or(raw_config, 'infrastructure/terraform/sha256'), ) # Nix store is read-only, and terraform doesn't work properly outside # of the module directory, so as a workaround we're using a temporary directory # with the contents of the derivation so terraform can create new files. # See: https://github.com/hashicorp/terraform/issues/18030 terraform_composition_path = os.path.join( writeable_nix_out_path(pname), self.kompos_config.terraform_root_path(), cloud_type, ) parser = ConfigRunner.get_parser(argparse.ArgumentParser()) if args.himl_args: himl_args = parser.parse_args(args.himl_args.split()) logger.info("Extra himl arguments: %s", args.himl_args.split()) else: himl_args = parser.parse_args([]) tf_config_generator.generate_files(himl_args, config_path, terraform_composition_path, composition, raw_config) return_code = self.execute( self.run_terraform(args, extra_args, terraform_composition_path, composition, raw_config)) if return_code != 0: logger.error( "Command finished with nonzero exit code for composition '%s'." "Will skip remaining compositions.", composition) return return_code return return_code
def run_compositions(self, args, extra_args, config_path, compositions, custom=False): nix = is_nix_enabled(args, self.kompos_config.nix()) for composition in compositions: logger.info("Running composition: %s", composition) if composition == "custom" and args.skip_custom_composition: logger.info("Custom compositions skipped") break elif composition == "custom" and not args.skip_custom_composition: logger.info("Run custom compositions") if "/composition=custom" not in self.cluster_config_path: custom_path = self.cluster_config_path + "/composition=custom" else: custom_path = self.cluster_config_path custom_compositions = discover_compositions(custom_path, path_type="type") return_code = self.run_compositions(args, extra_args, custom_path, custom_compositions, custom=True) break filtered_output_keys = self.kompos_config.filtered_output_keys( composition) excluded_config_keys = self.kompos_config.excluded_config_keys( composition) pre_config_generator = PreConfigGenerator(excluded_config_keys, filtered_output_keys) raw_config = pre_config_generator.pre_generate_config( config_path, composition) cloud_type = raw_config["cloud"]["type"] # Generate output paths for configs terraform_composition_path = self.get_composition_path( nix, cloud_type, raw_config, custom=custom) parser = ConfigRunner.get_parser(argparse.ArgumentParser()) if args.himl_args: himl_args = parser.parse_args(args.himl_args.split()) logger.info("Extra himl arguments: %s", args.himl_args.split()) else: himl_args = parser.parse_args([]) tf_config_generator = TerraformConfigGenerator( excluded_config_keys, filtered_output_keys) # Generate configs tf_config_generator.generate_files(himl_args, config_path, terraform_composition_path, composition, raw_config) # Run terraform return_code = self.execute( self.run_terraform(args, extra_args, terraform_composition_path, composition)) if return_code != 0: logger.error( "Command finished with nonzero exit code for composition '%s'." "Will skip remaining compositions.", composition) return return_code return return_code