Esempio n. 1
0
 def add_policies_from_calico_cluster(self):
     self._add_policies(CmdlineRunner.get_calico_resources('profile'),
                        'calicoctl', True)
     self._add_policies(CmdlineRunner.get_calico_resources('networkPolicy'),
                        'calicoctl', True)
     self._add_policies(
         CmdlineRunner.get_calico_resources('globalNetworkPolicy'),
         'calicoctl', True)
 def load_services_from_live_cluster(self):
     """
     Loads and parses service resources from live cluster
     :return: The list of parsed services in K8sService format
     """
     yaml_file = CmdlineRunner.get_k8s_resources('service')
     srv_resources = yaml.load(yaml_file, Loader=yaml.SafeLoader)
     if not isinstance(srv_resources, dict):
         return
     parser = K8sServiceYamlParser('k8s')
     for srv_code in srv_resources.get('items', []):
         service = parser.parse_service(srv_code)
         if service:
             service.namespace = self.namespaces_finder.get_or_update_namespace(
                 service.namespace.name)
             self.services_list.append(service)
    def _set_peer_list(self, peer_resources_list, config_name):
        """
        Populates the set of peers in the container from one of the following resources:
         - git path of yaml file or a directory with yamls
         - local file (yaml or json) or a local directory containing yamls
         - query of the cluster
        :param list peer_resources_list: list of peer resources to use.
        If set to 'k8s'/'calico'  query cluster using kubectl/calicoctl
        :param srt config_name: The config name
        :return: None
        """

        if not peer_resources_list:
            self.load_peer_from_k8s_live_cluster()

        for peer_resources in peer_resources_list:
            # load from live cluster
            if peer_resources == 'calico':
                for peer_type in [
                        'wep', 'hep', 'networkset', 'globalnetworkset'
                ]:
                    peer_code = yaml.load(
                        CmdlineRunner.get_calico_resources(peer_type),
                        Loader=yaml.SafeLoader)
                    self.add_eps_from_list(peer_code)
            elif peer_resources == 'k8s':
                self.load_peer_from_k8s_live_cluster()
            else:
                resource_scanner = TreeScannerFactory.get_scanner(
                    peer_resources)
                if resource_scanner is None:
                    continue
                yaml_files = resource_scanner.get_yamls()
                for yaml_file in yaml_files:
                    for peer_code in yaml_file.data:
                        self.add_eps_from_list(peer_code)

        print(
            f'{config_name}: cluster has {self.get_num_peers()} unique endpoints, '
            f'{self.get_num_namespaces()} namespaces')
Esempio n. 4
0
 def add_istio_policies_from_k8s_cluster(self):
     PeerContainer.locate_kube_config_file()
     self._add_policies(
         CmdlineRunner.get_k8s_resources('authorizationPolicy'), 'kubectl',
         True)
 def load_peer_from_k8s_live_cluster(self):
     self.locate_kube_config_file()
     peer_code = yaml.load(CmdlineRunner.get_k8s_resources('pod'),
                           Loader=yaml.SafeLoader)
     self.add_eps_from_list(peer_code)
 def load_ns_from_live_cluster(self):
     self.locate_kube_config_file()
     yaml_file = CmdlineRunner.get_k8s_resources('namespace')
     ns_code = yaml.load(yaml_file, Loader=yaml.SafeLoader)
     self.set_namespaces(ns_code)
 def load_istio_policies_from_k8s_cluster(self):
     self._add_policies(CmdlineRunner.get_k8s_resources('authorizationPolicy'), 'kubectl')
 def load_policies_from_k8s_cluster(self):
     self._add_policies(CmdlineRunner.get_k8s_resources('networkPolicy'), 'kubectl')
     self._add_policies(CmdlineRunner.get_k8s_resources('ingress'), 'kubectl')
 def load_peer_from_k8s_live_cluster(self):
     peer_code = yaml.load(CmdlineRunner.get_k8s_resources('pod'),
                           Loader=yaml.SafeLoader)
     self.add_eps_from_yaml(peer_code)
 def load_peer_from_calico_resource(self):
     for peer_type in ['wep', 'hep', 'networkset', 'globalnetworkset']:
         peer_code = yaml.load(
             CmdlineRunner.get_calico_resources(peer_type),
             Loader=yaml.SafeLoader)
         self.add_eps_from_yaml(peer_code)
 def k8s_apply_resources(yaml_file):
     if yaml_file:
         cmdline_list = ['kubectl', 'apply', f'-f{yaml_file}']
         CmdlineRunner.run_and_get_output(cmdline_list)