Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cri-o container metadata caching #1399

Merged
merged 1 commit into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions userspace/libsinsp/k8s_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ limitations under the License.
const std::string k8s_state_t::m_docker_prefix = "docker://";
const std::string k8s_state_t::m_rkt_prefix = "rkt://";
const std::string k8s_state_t::m_containerd_prefix = "containerd://";
const std::string k8s_state_t::m_crio_prefix = "cri-o://";
const unsigned k8s_state_t::m_id_length = 12u;

k8s_state_t::k8s_state_t(bool is_captured, int capture_version):
Expand All @@ -60,26 +61,32 @@ void k8s_state_t::cache_pod(container_pod_map& map, const std::string& id, const
ASSERT(pod);
ASSERT(!pod->get_name().empty());
std::string::size_type pos = id.find(m_docker_prefix);
if (pos == 0)
if(pos == 0)
{
map[id.substr(m_docker_prefix.size(), m_id_length)] = pod;
return;
}
pos = id.find(m_rkt_prefix);
if( pos == 0)
if(pos == 0)
{
map[id.substr(m_rkt_prefix.size())] = pod;
return;
}
pos = id.find(m_containerd_prefix);
if( pos == 0)
if(pos == 0)
{
map[id.substr(m_containerd_prefix.size(), m_id_length)] = pod;
return;
}
pos = id.find(m_crio_prefix);
if(pos == 0)
{
map[id.substr(m_crio_prefix.size(), m_id_length)] = pod;
return;
}
throw sinsp_exception("Invalid container ID (expected one of: '" + m_docker_prefix +
"{ID}', '" + m_rkt_prefix + "{ID}', '" + m_containerd_prefix +
"{ID}'): " + id);
"{ID}', '" + m_crio_prefix + "{ID}'): " + id);
}

bool k8s_state_t::has_pod(k8s_pod_t& pod)
Expand Down
1 change: 1 addition & 0 deletions userspace/libsinsp/k8s_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ class k8s_state_t
static const std::string m_docker_prefix; // "docker://"
static const std::string m_rkt_prefix; // "rkt://"
static const std::string m_containerd_prefix; // "containerd://"
static const std::string m_crio_prefix; // "cri-o://"
static const unsigned m_id_length; // portion of the ID to be cached (=12)

#ifndef HAS_ANALYZER
Expand Down