Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.
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
22 changes: 15 additions & 7 deletions src/kubernetes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,21 @@ bool ReadServiceAccountSecret(
KubernetesReader::KubernetesReader(const MetadataAgentConfiguration& config)
: config_(config), environment_(config) {}

json::value KubernetesReader::InstanceResource() const {
const std::string resource_type = "gce_instance"; // TODO: detect other resources.
Copy link
Contributor

Choose a reason for hiding this comment

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

Only minor comment, does the comment need to wrap lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically it does, but it's a TODO that will be removed, and there are other lines in this file that are over 80 characters, so maybe overkill? TODOs that aren't line comments tend to get dissociated from the appropriate lines over time.

const std::string instance_id = environment_.InstanceId();
const std::string zone = environment_.InstanceZone();
return json::object({
{"type", json::string(resource_type)},
{"labels", json::object({
{"instance_id", json::string(instance_id)},
{"zone", json::string(zone)},
})},
});
}

MetadataUpdater::ResourceMetadata KubernetesReader::GetNodeMetadata(
json::value raw_node, Timestamp collected_at) const throw(json::Exception) {
const std::string platform = "gce"; // TODO: detect other platforms.
const std::string instance_id = environment_.InstanceId();
const std::string zone = environment_.InstanceZone();
const std::string cluster_name = environment_.KubernetesClusterName();

Expand All @@ -113,8 +124,7 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetNodeMetadata(
{"association", json::object({
{"version", json::string(kRawContentVersion)},
{"raw", json::object({
{"providerPlatform", json::string(platform)},
{"instanceId", json::string(instance_id)},
{"infrastructureResource", std::move(InstanceResource())},
})},
})},
{"api", json::object({
Expand Down Expand Up @@ -145,8 +155,6 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetNodeMetadata(

json::value KubernetesReader::ComputePodAssociations(const json::Object* pod)
const throw(json::Exception) {
const std::string platform = "gce"; // TODO: detect other platforms.

const json::Object* metadata = pod->Get<json::Object>("metadata");
const std::string namespace_name = metadata->Get<json::String>("namespace");
const std::string pod_id = metadata->Get<json::String>("uid");
Expand Down Expand Up @@ -175,7 +183,7 @@ json::value KubernetesReader::ComputePodAssociations(const json::Object* pod)
return json::object({
{"version", json::string(kRawContentVersion)},
{"raw", json::object({
{"providerPlatform", json::string(platform)},
{"infrastructureResource", std::move(InstanceResource())},
{"controllers", json::object({
{"topLevelControllerType", json::string(top_level_kind)},
{"topLevelControllerName", json::string(top_level_name)},
Expand Down
3 changes: 3 additions & 0 deletions src/kubernetes.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class KubernetesReader {
json::value FindTopLevelOwner(const std::string& ns, json::value object) const
throw(QueryException, json::Exception);

// Gets the monitored resource of the instance the agent is running on.
json::value InstanceResource() const;

// Cached data.
mutable std::recursive_mutex mutex_;
mutable std::string current_node_;
Expand Down