Ejemplo n.º 1
0
    def run(self, args, extra_args):
        if not os.path.isdir(self.cluster_config_path):
            raise Exception("Provide a valid composition directory path.")

        config_path = os.path.join(self.cluster_config_path, "")

        composition_order = discover_all_compositions(config_path)
        compositions = CompositionSorter(composition_order).get_sorted_compositions(
            config_path
        )
        if not 0 < len(compositions) < 2:
            raise Exception("Provide the path to a single valid composition directory")
        composition = compositions[0]

        filtered_output_keys = self.kompos_config.filtered_output_keys(composition)
        excluded_config_keys = self.kompos_config.excluded_config_keys(composition)

        self.generate_config(
            config_path=self.cluster_config_path,
            filters=filtered_output_keys,
            exclude_keys=excluded_config_keys,
            enclosing_key=args.enclosing_key,
            remove_enclosing_key=args.remove_enclosing_key,
            output_format=args.output_format,
            output_file=args.output_file,
            print_data=True,
            skip_interpolation_resolving=args.skip_interpolation_resolving,
            skip_interpolation_validation=args.skip_interpolation_validation,
            skip_secrets=args.skip_secrets
        )
Ejemplo n.º 2
0
    def run(self, args, extra_args):
        config_path = os.path.join(self.cluster_config_path, "")

        composition_order = discover_all_compositions(config_path)
        compositions = CompositionSorter(
            composition_order).get_sorted_compositions(config_path)
        if not 0 < len(compositions) < 2:
            raise Exception(
                "Please provide the full path to a single composition")
        composition = compositions[0]

        filtered_output_keys = self.kompos_config.filtered_output_keys(
            composition)
        excluded_config_keys = self.kompos_config.excluded_config_keys(
            composition)

        excluded_config_keys += ["helm", "provider"]

        self.generate_config(
            config_path=self.cluster_config_path,
            filters=filtered_output_keys,
            exclude_keys=excluded_config_keys,
            enclosing_key=args.enclosing_key,
            output_format="yaml",
            output_file=args.output_file,
            print_data=True,
            skip_interpolation_resolving=args.skip_interpolation_resolving,
            skip_interpolation_validation=args.skip_interpolation_validation,
            skip_secrets=args.skip_secrets)
Ejemplo n.º 3
0
    def run(self, args, extra_args):
        if not os.path.isdir(self.cluster_config_path):
            raise Exception("Provide a valid composition directory path.")

        compositions = CompositionSorter(
            self.kompos_config.helmfile_composition_order(
            )).get_sorted_compositions(self.cluster_config_path)

        if not compositions or compositions[0] != HELMFILE_COMPOSITION_NAME:
            raise Exception(
                "No helmfiles compositions where detected in {}".format(
                    self.cluster_config_path))

        # We're assuming local path by default.
        helmfile_path = os.path.join(
            self.kompos_config.helmfile_local_path(),
            self.kompos_config.helmfile_root_path(),
        )

        # Overwrite if CLI flag is set.
        if args.helmfile_path:
            helmfile_path = args.helmfile_path

        # Overwrite if nix is enabled.
        if is_nix_enabled(args, self.kompos_config.nix()):
            pname = self.kompos_config.helmfile_repo_name()

            raw_config = self.generate_config(
                config_path=get_config_path(self.cluster_config_path,
                                            HELMFILE_COMPOSITION_NAME),
                filters=self.kompos_config.filtered_output_keys(
                    HELMFILE_COMPOSITION_NAME),
                exclude_keys=self.kompos_config.excluded_config_keys(
                    HELMFILE_COMPOSITION_NAME))

            nix_install(
                pname,
                self.kompos_config.helmfile_repo_url(),
                get_value_or(raw_config, 'infrastructure/helmfile/version',
                             'master'),
                get_value_or(raw_config, 'infrastructure/helmfile/sha256'),
            )

            # FIXME: Nix store is read-only, and helmfile configuration has a hardcoded path for
            # the generated config, so as a workaround we're using a temporary directory
            # with the contents of the derivation so helmfile can create the config file.

            helmfile_path = os.path.join(
                writeable_nix_out_path(pname),
                self.kompos_config.helmfile_root_path())

        self.setup_kube_config(
            self.generate_helmfile_config(
                get_config_path(self.cluster_config_path, compositions[0]),
                helmfile_path))

        return dict(
            command=self.get_helmfile_command(helmfile_path, extra_args))
Ejemplo n.º 4
0
    def check_compositions(self, args, extra_args):
        logging.basicConfig(level=logging.INFO)
        all_compositions = self.kompos_config.terraform_composition_order()

        compositions = CompositionSorter(all_compositions) \
                           .get_sorted_compositions(
                                self.cluster_config_path, reverse=("destroy" == args.subcommand)
                           )
        if not compositions:
            raise Exception(
                "No terraform compositions were detected in {}.".format(
                    self.cluster_config_path))

        return self.run_compositions(args, extra_args,
                                     self.cluster_config_path, compositions)
Ejemplo n.º 5
0
    def run(self, args, extra_args):
        if not os.path.isdir(self.cluster_config_path):
            raise Exception("Provide a valid composition directory path.")

        config_path = os.path.join(self.cluster_config_path, "")

        composition_order = discover_all_compositions(config_path)
        compositions = CompositionSorter(
            composition_order).get_sorted_compositions(config_path)
        if not 0 < len(compositions) < 2:
            raise Exception(
                "Provide the path to a single valid composition directory")
        composition = compositions[0]

        filtered = self.kompos_config.filtered_output_keys(composition).copy()
        if args.filter:
            filtered = filtered + args.filter

        excluded = self.kompos_config.excluded_config_keys(composition).copy()
        if args.exclude:
            excluded = excluded + args.exclude

        self.generate_config(
            config_path=self.cluster_config_path,
            filters=filtered,
            exclude_keys=excluded,
            enclosing_key=args.enclosing_key,
            remove_enclosing_key=args.remove_enclosing_key,
            output_format=args.output_format,
            output_file=args.output_file,
            print_data=True,
            skip_interpolation_resolving=args.skip_interpolation_resolving,
            skip_interpolation_validation=args.skip_interpolation_validation,
            skip_secrets=args.skip_secrets,
            multi_line_string=True)

        ADDR = os.getenv('VAULT_ADDR')
        USERNAME = os.environ.get('VAULT_USERNAME')
        ROLE = os.environ.get('VAULT_ROLE')
        NAMESPACE = os.environ.get('VAULT_NAMESPACE')
        logger.info("Vault URL %s", ADDR)
        logger.info("Vault username %s", USERNAME)
        logger.info("Vault role %s", ROLE)
        logger.info("Vault namespace %s", NAMESPACE)

        self.setup_ssm_config(USERNAME, ROLE, NAMESPACE)