Beispiel #1
0
    def setUp(self) -> None:
        self.dynamic_mapper = EnforcementDynamicMapper()
        self.enforcement_repository = EnforcementRepository()
        self.enforcement = Enforcement(name='test', repo='somewhere')
        self.cluster_repository = ClusterRepository()
        self.project_repository = ProjectRepository()
        self.cluster = Cluster(name='test',
                               url='test',
                               token='test',
                               id='test')
        self.cluster_group = ClusterGroup(
            clusters=[self.cluster],
            cluster_repository=self.cluster_repository,
            project_repository=self.project_repository)

        self.trigger_function = lambda enf, cluster: None

        self.enforcement_installer = EnforcementInstaller(
            enforcements=[self.enforcement],
            cluster_group=self.cluster_group,
            enforcement_repository=self.enforcement_repository,
            enforcement_dynamic_mapper=self.dynamic_mapper,
            before_install_trigger=self.trigger_function,
            after_install_trigger=self.trigger_function,
        )
Beispiel #2
0
    def setUp(self) -> None:
        self.source_locator = SourceLocator()
        self.source_repository = SourceRepository()
        self.cluster_repository = ClusterRepository()
        self.project_repository = ProjectRepository()
        self.enforcement_repository = EnforcementRepository()
        self.enforcement = Enforcement(name='test', repo='somewhere')

        self.cluster = Cluster(name='test',
                               url='test',
                               token='test',
                               id='test')
        self.cluster_group = ClusterGroup(
            clusters=[self.cluster],
            cluster_repository=self.cluster_repository,
            project_repository=self.project_repository)
        self.cluster_group_builder = ClusterGroupBuilder(
            cluster_repository=self.cluster_repository,
            project_repository=self.project_repository)
        self.cluster_rule = ClusterRule(enforcements=[],
                                        source=EnforcementSource())

        self.enforcement_installer_builder = EnforcementInstallerBuilder(
            enforcement_repository=self.enforcement_repository)

        self.enforcement_installer = EnforcementInstaller(
            enforcements=[self.enforcement],
            cluster_group=self.cluster_group,
            enforcement_repository=self.enforcement_repository)
Beispiel #3
0
 def _build_cluster(self, cluster_map: dict) -> Cluster:
     return Cluster(
         name=cluster_map['name'],
         id=cluster_map['id'],
         token=self.config.rancher_token,
         url=f'{self.config.rancher_url}/k8s/clusters/{cluster_map["id"]}',
     )
Beispiel #4
0
 def _build_cluster(self, cluster_map: dict) -> Cluster:
     return Cluster(
         name=cluster_map['name'],
         id=cluster_map['id'],
         token=self.secret.token,
         url=f'{self.secret.url}/k8s/clusters/{cluster_map["id"]}',
         additional_data=cluster_map,
     )
 def setUp(self) -> None:
     self.cluster_repository = ClusterRepository()
     self.project_repository = ProjectRepository()
     self.cluster = Cluster(name='test',
                            url='test',
                            token='test',
                            id='test')
     self.cluster_group = ClusterGroup(
         clusters=[self.cluster],
         cluster_repository=self.cluster_repository,
         project_repository=self.project_repository)
    def __call__(self, cluster: Cluster,
                 enforcement: Enforcement) -> Enforcement:
        yaml_enforcement = yaml.dump(enforcement.dict())
        yaml_enforcement = yaml_enforcement.replace("$", "", -1)

        t = Template(yaml_enforcement)
        cluster_dict = cluster.dict()
        cluster_dict.pop("additional_data")
        cluster_dict.update(cluster.additional_data)
        cluster_dict["requests"] = requests
        yaml_enforcement = t.render(**cluster_dict)
        enforcement_dict = yaml.load(yaml_enforcement)
        return Enforcement(**enforcement_dict)
Beispiel #7
0
 def setUp(self) -> None:
     self.enforcement_repository = EnforcementRepository()
     self.enforcement = Enforcement(name='test', repo='somewhere')
     self.cluster_repository = ClusterRepository()
     self.project_repository = ProjectRepository()
     self.cluster = Cluster(name='test',
                            url='test',
                            token='test',
                            id='test')
     self.cluster_group = ClusterGroup(
         clusters=[self.cluster],
         cluster_repository=self.cluster_repository,
         project_repository=self.project_repository)
    def setUp(self) -> None:
        self.dynamic_mapper = EnforcementDynamicMapper()
        self.cluster_repository = ClusterRepository()
        self.project_repository = ProjectRepository()
        self.enforcement_repository = EnforcementRepository()
        self.enforcement = Enforcement(name='test', repo='somewhere')
        self.old_enforcement = Enforcement(name='test', repo='somewhere')
        self.new_enforcement = Enforcement(name='test1', repo='anywhere')
        self.cluster = Cluster(name='test',
                               url='test',
                               token='test',
                               id='test')
        self.cluster_group = ClusterGroup(
            clusters=[self.cluster],
            cluster_repository=self.cluster_repository,
            project_repository=self.project_repository)

        self.cluster_group_builder = ClusterGroupBuilder(
            cluster_repository=self.cluster_repository,
            project_repository=self.project_repository)

        self.cluster_rule = ClusterRule(enforcements=[self.enforcement],
                                        source=EnforcementSource())

        trigger_builder = MagicMock()
        trigger_builder.build_before_install = MagicMock(
            return_value=lambda enf, cluster: None)
        trigger_builder.build_after_install = MagicMock(
            return_value=lambda enf, cluster: None)

        self.enforcement_installer_builder = EnforcementInstallerBuilder(
            enforcement_repository=self.enforcement_repository,
            enforcement_dynamic_mapper=EnforcementDynamicMapper(),
            trigger_builder=trigger_builder,
        )

        self.enforcement_installer = EnforcementInstaller(
            enforcements=[self.enforcement],
            cluster_group=self.cluster_group,
            enforcement_repository=self.enforcement_repository,
            enforcement_dynamic_mapper=self.dynamic_mapper,
            before_install_trigger=lambda a1, a2: None,
            after_install_trigger=lambda a1, a2: None,
        )

        self.enforcement_change_detector_builder = EnforcementChangeDetectorBuilder(
        )
        self.enforcement_change_detector = EnforcementChangeDetector(
            old_enforcements_list=[self.old_enforcement],
            new_enforcements_list=[self.new_enforcement])
 def setUp(self) -> None:
     self.enforcement_repository = EnforcementRepository()
     self.enforcement_dynamic_mapper = EnforcementDynamicMapper()
     self.enforcement = Enforcement(name='test',
                                    repo='somewhere',
                                    labels={'cluster_name': 'test'})
     self.cluster_repository = ClusterRepository()
     self.project_repository = ProjectRepository()
     self.cluster = Cluster(name='test',
                            url='test',
                            token='test',
                            id='test')
     self.cluster_group = ClusterGroup(
         clusters=[self.cluster],
         cluster_repository=self.cluster_repository,
         project_repository=self.project_repository)
Beispiel #10
0
    def sync(self, name: str, spec: dict, status: dict, logger, **kwargs):
        logger.debug(f"sync clusters for %s", name)

        current_status = ClusterRuleController._restore_status(status)

        if not current_status:
            return

        current_clusters = [
            Cluster(name=cluster['name'], url=cluster['url'], id='', token='')
            for cluster in current_status.clusters
        ]
        cluster_rule = ClusterRule(**spec)
        response = self._sync_rules_use_case.execute(cluster_rule, current_clusters)
        response.install_errors = [Enforcement(name=name, repo="") for name in current_status.install_errors]

        new_status = ClusterRuleController._make_status(response)

        if new_status != current_status.dict():
            return new_status
Beispiel #11
0
    def update(self, name, old: List[dict], new: List[dict], status: dict,
               logger, **kwargs):
        if not old:
            return

        logger.debug(f"update rules for %s", name)

        old_enforcement_list = ClusterRuleController._make_enforcement_list(
            old)
        new_enforcement_list = ClusterRuleController._make_enforcement_list(
            new)
        current_status = ClusterRuleController._restore_status(status)

        current_clusters = [
            Cluster(name=cluster['name'], url=cluster['url'], id='', token='')
            for cluster in current_status.clusters
        ]

        response = self._update_rules_use_case.execute(
            clusters=current_clusters,
            old_enforcements=old_enforcement_list,
            new_enforcements=new_enforcement_list,
        )

        enforcements_change = [
            enforcement.name for enforcement in response.removed_enforcements +
            response.changed_enforcements
        ]

        response.install_errors = response.install_errors + list(
            map(
                lambda name: Enforcement(name=name, repo=""),
                filter(
                    lambda enforcement_name: enforcement_name not in
                    enforcements_change,
                    current_status.install_errors,
                )))

        response.clusters = current_clusters

        return ClusterRuleController._make_status(response)
 def setUp(self) -> None:
     self.cluster_repository = ClusterRepository()
     self.project_repository = ProjectRepository()
     self.cluster = Cluster(name='test', url='test',
                            token='test', id='test')