json serialize_decl(name const & d, environment const & env, options const & o) { // using namespace override resolution rule list<name> const & ns_list = get_namespaces(env); for (name const & ns : ns_list) { name new_d = d.replace_prefix(ns, name()); if (new_d != d && !new_d.is_anonymous() && (!new_d.is_atomic() || !is_protected(env, d))) { return serialize_decl(new_d, d, env, o); } } // if the alias is unique use it if (auto it = is_uniquely_aliased(env, d)) { return serialize_decl(*it, d, env, o); } else { return serialize_decl(d, d, env, o); } }
TEST_F(NvmfSubsystemAddNsTest, AddingListener) { spdk::model::Namespace ns{}; ns.set_bdev_name("lvol-bdev"); std::uint32_t nsid{}; ASSERT_NO_THROW(nsid = spdk_api->nvmf_subsystem_add_ns(spdk::NvmfSubsystemAddNsConnector::SUBSYSTEM_NQN, ns)); ASSERT_NE(nsid, 0); auto nvmf_subsystems = spdk_api->get_nvmf_subsystems(); auto nvmf_subsystem = nvmf_subsystems.front(); ASSERT_EQ(nvmf_subsystem.get_nqn(), spdk::NvmfSubsystemAddNsConnector::SUBSYSTEM_NQN); ASSERT_FALSE(nvmf_subsystem.get_namespaces().empty()); ASSERT_EQ(nvmf_subsystem.get_namespaces().front().get_bdev_name(), "lvol-bdev"); ASSERT_EQ(nvmf_subsystem.get_namespaces().front().get_namespace_id(), nsid); ASSERT_FALSE(nvmf_subsystem.get_namespaces().front().get_uuid().value_or_default().empty()); ASSERT_FALSE(nvmf_subsystem.get_namespaces().front().get_eui_64().value_or_default().empty()); ASSERT_FALSE(nvmf_subsystem.get_namespaces().front().get_nguid().value_or_default().empty()); }
void k8s_state_t::update_cache(const k8s_component::component_map::key_type& component) { #ifdef K8S_DISABLE_THREAD switch (component) { case k8s_component::K8S_NAMESPACES: { const k8s_namespaces& nspaces = get_namespaces(); k8s_state_t::namespace_map& ns_map = get_namespace_map(); ns_map.clear(); for(const auto& ns : nspaces) { std::string ns_name = ns.get_name(); if(!is_component_cached(ns_map, ns_name, &ns)) { cache_component(ns_map, ns_name, &ns); } else { g_logger.log("Attempt to cache already cached NAMESPACE: " + ns_name, sinsp_logger::SEV_ERROR); } } } break; case k8s_component::K8S_PODS: { const k8s_pods& pods = get_pods(); k8s_state_t::container_pod_map& container_pod_map = get_container_pod_map(); container_pod_map.clear(); for(const auto& pod : pods) { const k8s_pod_t::container_id_list& c_ids = pod.get_container_ids(); for(const auto& c_id : c_ids) { if(!is_component_cached(container_pod_map, c_id, &pod)) { cache_pod(container_pod_map, c_id, &pod); } else { g_logger.log("Attempt to cache already cached POD: " + c_id, sinsp_logger::SEV_ERROR); } } } } break; case k8s_component::K8S_REPLICATIONCONTROLLERS: { const k8s_controllers& rcs = get_rcs(); const k8s_pods& pods = get_pods(); k8s_state_t::pod_rc_map& pod_ctrl_map = get_pod_rc_map(); pod_ctrl_map.clear(); for(const auto& rc : rcs) { std::vector<const k8s_pod_t*> pod_subset = rc.get_selected_pods(pods); for(auto& pod : pod_subset) { const std::string& pod_uid = pod->get_uid(); if(!is_component_cached(pod_ctrl_map, pod_uid, &rc)) { cache_component(pod_ctrl_map, pod_uid, &rc); } else { g_logger.log("Attempt to cache already cached REPLICATION CONTROLLER: " + pod_uid, sinsp_logger::SEV_ERROR); } } } } break; case k8s_component::K8S_SERVICES: { const k8s_services& services = get_services(); const k8s_pods& pods = get_pods(); k8s_state_t::pod_service_map& pod_svc_map = get_pod_service_map(); pod_svc_map.clear(); for(const auto& service : services) { std::vector<const k8s_pod_t*> pod_subset = service.get_selected_pods(pods); for(auto& pod : pod_subset) { const std::string& pod_uid = pod->get_uid(); if(!is_component_cached(pod_svc_map, pod_uid, &service)) { cache_component(pod_svc_map, pod_uid, &service); } else { g_logger.log("Attempt to cache already cached SERVICE: " + pod_uid, sinsp_logger::SEV_ERROR); } } } } break; default: return; } #endif // K8S_DISABLE_THREAD }