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
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ install: metadatad

export DISTRO
PKG_NAME=stackdriver-metadata
PKG_VERSION=0.0.15
PKG_VERSION=0.0.16
PKG_RELEASE=1
PKG_MAINTAINER=Stackdriver Engineering <engineering@stackdriver.com>

Expand Down
15 changes: 5 additions & 10 deletions src/kubernetes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ constexpr const char kK8sContainerResourcePrefix[] = "k8s_container";
constexpr const char kK8sContainerNameResourcePrefix[] = "k8s_containerName";
constexpr const char kK8sPodResourcePrefix[] = "k8s_pod";
constexpr const char kK8sPodNameResourcePrefix[] = "k8s_podName";
constexpr const char kK8sNodeResourcePrefix[] = "k8s_node";
constexpr const char kK8sNodeNameResourcePrefix[] = "k8s_nodeName";

constexpr const char kNodeSelectorPrefix[] = "?fieldSelector=spec.nodeName%3D";
Expand Down Expand Up @@ -167,6 +166,10 @@ json::value KubernetesReader::ComputePodAssociations(const json::Object* pod)
? top_level_controller->Get<json::String>("kind")
: "Pod";

// TODO: What about pods that are not scheduled yet?
const json::Object* spec = pod->Get<json::Object>("spec");
const std::string node_name = spec->Get<json::String>("nodeName");

return json::object({
{"version", json::string(kRawContentVersion)},
{"raw", json::object({
Expand All @@ -175,6 +178,7 @@ json::value KubernetesReader::ComputePodAssociations(const json::Object* pod)
{"topLevelControllerType", json::string(top_level_kind)},
{"topLevelControllerName", json::string(top_level_name)},
})},
{"nodeName", json::string(node_name)},
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a common convention to use camel casing for metadata labels vs underscores for resource labels? Is there any value in trying to push for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The monitored resource labels use snake_case. Since the associations are part of the metadata blobs, we've tried to be consistent with the source of the metadata -- in this case, the Kubernetes API. Kubernetes uses camelCase, so we stuck with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

})},
});
}
Expand All @@ -199,13 +203,9 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetPodMetadata(
const std::string started_str = status->Get<json::String>("startTime");
Timestamp started_at = rfc3339::FromString(started_str);

const json::Object* spec = pod->Get<json::Object>("spec");
const std::string node_name = spec->Get<json::String>("nodeName");

const MonitoredResource k8s_pod("k8s_pod", {
{"cluster_name", cluster_name},
{"namespace_name", namespace_name},
{"node_name", node_name},
{"pod_name", pod_name},
{"location", zone},
});
Expand Down Expand Up @@ -267,9 +267,6 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetContainerMetadata(
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");

const std::string container_name = container_spec->Get<json::String>("name");
// TODO: find is_deleted.
//const json::Object* state = container_status->Get<json::Object>("state");
Expand All @@ -278,7 +275,6 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetContainerMetadata(
const MonitoredResource k8s_container("k8s_container", {
{"cluster_name", cluster_name},
{"namespace_name", namespace_name},
{"node_name", node_name},
{"pod_name", pod_name},
{"container_name", container_name},
{"location", zone},
Expand Down Expand Up @@ -381,7 +377,6 @@ KubernetesReader::GetPodAndContainerMetadata(
const std::string pod_id = metadata->Get<json::String>("uid");

const json::Object* spec = pod->Get<json::Object>("spec");
const std::string node_name = spec->Get<json::String>("nodeName");

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

Expand Down