Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.
Merged
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
42 changes: 26 additions & 16 deletions src/kubernetes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetPodMetadata(
const std::string created_str =
metadata->Get<json::String>("creationTimestamp");
Timestamp created_at = rfc3339::FromString(created_str);
const json::Object* labels = metadata->Get<json::Object>("labels");

const json::Object* status = pod->Get<json::Object>("status");
const std::string started_str = status->Get<json::String>("startTime");
Expand Down Expand Up @@ -263,7 +262,12 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetContainerMetadata(
const std::string created_str =
metadata->Get<json::String>("creationTimestamp");
Timestamp created_at = rfc3339::FromString(created_str);
const json::Object* labels = metadata->Get<json::Object>("labels");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well also delete this from line 199...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

const json::Object* labels;
if (!metadata->Has("labels")) {
labels = nullptr;
} else {
labels = metadata->Get<json::Object>("labels");
}

const json::Object* spec = pod->Get<json::Object>("spec");
const std::string node_name = spec->Get<json::String>("nodeName");
Expand Down Expand Up @@ -293,22 +297,28 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetContainerMetadata(
{"location", zone},
});

json::value container_raw_metadata = json::object({
{"blobs", json::object({
{"association", std::move(associations)},
{"spec", json::object({
{"version", json::string(kKubernetesApiVersion)},
{"raw", container_spec->Clone()},
})},
{"status", json::object({
{"version", json::string(kKubernetesApiVersion)},
{"raw", container_status->Clone()},
})},
{"labels", json::object({
std::unique_ptr<json::Object> blobs(new json::Object({
{"association", std::move(associations)},
{"spec", json::object({
{"version", json::string(kKubernetesApiVersion)},
{"raw", container_spec->Clone()},
})},
{"status", json::object({
{"version", json::string(kKubernetesApiVersion)},
{"raw", container_status->Clone()},
})},
}));
if (labels) {
blobs->emplace(std::make_pair(
"labels",
json::object({
{"version", json::string(kKubernetesApiVersion)},
{"raw", labels->Clone()},
})},
})},
})
));
}
json::value container_raw_metadata = json::object({
{"blobs", json::value(std::move(blobs))},
});
if (config_.VerboseLogging()) {
LOG(INFO) << "Raw container metadata: " << *container_raw_metadata;
Expand Down