Skip to content
This repository has been archived by the owner on Aug 19, 2019. It is now read-only.

Commit

Permalink
Address feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpeshansky committed Dec 19, 2017
1 parent a3258f5 commit 38d3db0
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions src/kubernetes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetNodeMetadata(

const json::Object* node = raw_node->As<json::Object>();
const json::Object* metadata = node->Get<json::Object>("metadata");
const std::string node_id = metadata->Get<json::String>("uid");
const std::string node_name = metadata->Get<json::String>("name");
const std::string created_str =
metadata->Get<json::String>("creationTimestamp");
Expand Down Expand Up @@ -125,12 +124,6 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetNodeMetadata(
LOG(INFO) << "Raw node metadata: " << *node_raw_metadata;
}

#if 0
// TODO: do we need this?
const std::string k8s_node_id = boost::algorithm::join(
std::vector<std::string>{kK8sNodeResourcePrefix, node_id},
kResourceTypeSeparator);
#endif
const std::string k8s_node_name = boost::algorithm::join(
std::vector<std::string>{kK8sNodeNameResourcePrefix, node_name},
kResourceTypeSeparator);
Expand Down Expand Up @@ -216,9 +209,9 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetPodMetadata(
{"location", zone},
});

// TODO: find pod_deleted.
// TODO: find is_deleted.
//const json::Object* status = pod->Get<json::Object>("status");
bool pod_deleted = false;
bool is_deleted = false;

json::value pod_raw_metadata = json::object({
{"blobs", json::object({
Expand All @@ -244,7 +237,7 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetPodMetadata(
k8s_pod,
#ifdef ENABLE_KUBERNETES_METADATA
MetadataAgent::Metadata(kRawContentVersion,
pod_deleted, created_at, collected_at,
is_deleted, created_at, collected_at,
std::move(pod_raw_metadata))
#else
MetadataAgent::Metadata::IGNORED()
Expand Down Expand Up @@ -273,15 +266,15 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetContainerMetadata(
const json::Object* status = pod->Get<json::Object>("status");

const json::Array* container_specs = spec->Get<json::Array>("containers");
const json::Array* container_list =
const json::Array* container_statuses =
status->Get<json::Array>("containerStatuses");

const json::value& c_element = (*container_list)[container_index];
const json::value& c_status = (*container_statuses)[container_index];
const json::value& c_spec = (*container_specs)[container_index];
if (config_.VerboseLogging()) {
LOG(INFO) << "Container: " << *c_element;
LOG(INFO) << "Container: " << *c_status;
}
const json::Object* container = c_element->As<json::Object>();
const json::Object* container = c_status->As<json::Object>();
const json::Object* container_spec = c_spec->As<json::Object>();
const std::string container_name = container->Get<json::String>("name");
std::size_t docker_prefix_end = sizeof(kDockerIdPrefix) - 1;
Expand Down Expand Up @@ -366,14 +359,14 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetLegacyResource(

const json::Object* status = pod->Get<json::Object>("status");

const json::Array* container_list =
const json::Array* container_statuses =
status->Get<json::Array>("containerStatuses");

const json::value& c_element = (*container_list)[container_index];
const json::value& c_status = (*container_statuses)[container_index];
if (config_.VerboseLogging()) {
LOG(INFO) << "Container: " << *c_element;
LOG(INFO) << "Container: " << *c_status;
}
const json::Object* container = c_element->As<json::Object>();
const json::Object* container = c_status->As<json::Object>();
const std::string container_name = container->Get<json::String>("name");

const MonitoredResource gke_container("gke_container", {
Expand Down Expand Up @@ -415,18 +408,18 @@ KubernetesReader::GetPodAndContainerMetadata(
const json::Object* status = pod->Get<json::Object>("status");

const json::Array* container_specs = spec->Get<json::Array>("containers");
const json::Array* container_list =
const json::Array* container_statuses =
status->Get<json::Array>("containerStatuses");
std::size_t num_containers = std::min(
container_list->size(), container_specs->size());
container_statuses->size(), container_specs->size());

for (int i = 0; i < num_containers; ++i) {
const json::value& c_element = (*container_list)[i];
const json::value& c_status = (*container_statuses)[i];
const json::value& c_spec = (*container_specs)[i];
if (config_.VerboseLogging()) {
LOG(INFO) << "Container: " << *c_element;
LOG(INFO) << "Container: " << *c_status;
}
const json::Object* container = c_element->As<json::Object>();
const json::Object* container = c_status->As<json::Object>();
const json::Object* container_spec = c_spec->As<json::Object>();
const std::string container_name = container->Get<json::String>("name");
const std::string spec_name = container_spec->Get<json::String>("name");
Expand Down Expand Up @@ -508,13 +501,13 @@ std::vector<MetadataUpdater::ResourceMetadata>
const json::Object* status = pod->Get<json::Object>("status");

const json::Array* container_specs = spec->Get<json::Array>("containers");
const json::Array* container_list =
const json::Array* container_statuses =
status->Get<json::Array>("containerStatuses");
if (container_specs->size() != container_list->size()) {
if (container_specs->size() != container_statuses->size()) {
LOG(ERROR) << "Container specs and statuses arrays "
<< "have different sizes: "
<< container_specs->size() << " vs "
<< container_list->size() << " for pod "
<< container_statuses->size() << " for pod "
<< pod_id << "(" << pod_name << ")";
}

Expand Down

0 comments on commit 38d3db0

Please sign in to comment.