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/docker.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DockerUpdater : public PollingMetadataUpdater {
: reader_(server->config()), PollingMetadataUpdater(
server, "DockerUpdater",
server->config().DockerUpdaterIntervalSeconds(),
std::bind(&google::DockerReader::MetadataQuery, &reader_)) { }
[=]() { return reader_.MetadataQuery(); }) { }

protected:
bool ValidateConfiguration() const;
Expand Down
2 changes: 1 addition & 1 deletion src/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InstanceUpdater : public PollingMetadataUpdater {
: reader_(server->config()), PollingMetadataUpdater(
server, "InstanceUpdater",
server->config().InstanceUpdaterIntervalSeconds(),
std::bind(&google::InstanceReader::MetadataQuery, &reader_)) { }
[=]() { return reader_.MetadataQuery(); }) { }
private:
InstanceReader reader_;
};
Expand Down
43 changes: 24 additions & 19 deletions src/kubernetes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,9 @@ void KubernetesReader::WatchMaster(
std::mutex completion_mutex;
std::unique_lock<std::mutex> watch_completion(completion_mutex);
Watcher watcher(endpoint,
std::bind(&EventCallback, callback, std::placeholders::_1),
[=](json::value raw_watch) {
EventCallback(callback, std::move(raw_watch));
},
std::move(watch_completion), config_.VerboseLogging());
http::client::response response = client.get(request, boost::ref(watcher));
if (config_.VerboseLogging()) {
Expand Down Expand Up @@ -1085,11 +1087,12 @@ void KubernetesReader::WatchPods(
? "" : "&" + config_.KubernetesPodLabelSelector());

try {
WatchMaster(std::string(kKubernetesEndpointPath) + "/pods"
+ node_selector + pod_label_selector,
std::bind(&KubernetesReader::PodCallback,
this, callback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
WatchMaster(
std::string(kKubernetesEndpointPath) + "/pods" + node_selector
+ pod_label_selector,
[=](const json::Object* pod, Timestamp collected_at, bool is_deleted) {
PodCallback(callback, pod, collected_at, is_deleted);
});
} catch (const json::Exception& e) {
LOG(ERROR) << e.what();
LOG(ERROR) << "No more pod metadata will be collected";
Expand Down Expand Up @@ -1117,11 +1120,11 @@ void KubernetesReader::WatchNodes(

try {
// TODO: There seems to be a Kubernetes API bug with watch=true.
WatchMaster(std::string(kKubernetesEndpointPath) + "/watch/nodes/"
+ node_name,
std::bind(&KubernetesReader::NodeCallback,
this, callback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
WatchMaster(
std::string(kKubernetesEndpointPath) + "/watch/nodes/" + node_name,
[=](const json::Object* node, Timestamp collected_at, bool is_deleted) {
NodeCallback(callback, node, collected_at, is_deleted);
});
} catch (const json::Exception& e) {
LOG(ERROR) << e.what();
LOG(ERROR) << "No more node metadata will be collected";
Expand All @@ -1135,7 +1138,7 @@ KubernetesUpdater::KubernetesUpdater(MetadataAgent* server)
: reader_(server->config()), PollingMetadataUpdater(
server, "KubernetesUpdater",
server->config().KubernetesUpdaterIntervalSeconds(),
std::bind(&google::KubernetesReader::MetadataQuery, &reader_)) { }
[=]() { return reader_.MetadataQuery(); }) { }

bool KubernetesUpdater::ValidateConfiguration() const {
if (!PollingMetadataUpdater::ValidateConfiguration()) {
Expand All @@ -1156,13 +1159,15 @@ void KubernetesUpdater::StartUpdater() {
const std::string watched_node(
config().KubernetesClusterLevelMetadata() ? "" : current_node);

// Wrap the bind expression into a function to use as a bind argument.
UpdateCallback cb = std::bind(&KubernetesUpdater::MetadataCallback, this,
std::placeholders::_1);
node_watch_thread_ =
std::thread(&KubernetesReader::WatchNodes, &reader_, watched_node, cb);
pod_watch_thread_ =
std::thread(&KubernetesReader::WatchPods, &reader_, watched_node, cb);
auto cb = [=](std::vector<MetadataUpdater::ResourceMetadata>&& results) {
MetadataCallback(std::move(results));
};
node_watch_thread_ = std::thread([=]() {
reader_.WatchNodes(watched_node, cb);
});
pod_watch_thread_ = std::thread([=]() {
reader_.WatchPods(watched_node, cb);
});
} else {
// Only try to poll if watch is disabled.
PollingMetadataUpdater::StartUpdater();
Expand Down
2 changes: 0 additions & 2 deletions src/metadatad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

//#include "config.h"

#include <functional>

#include "api_server.h"
#include "configuration.h"
#include "docker.h"
Expand Down
3 changes: 1 addition & 2 deletions src/updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ void PollingMetadataUpdater::StartUpdater() {
LOG(INFO) << "Timer locked";
}
if (period_ > seconds::zero()) {
reporter_thread_ =
std::thread(&PollingMetadataUpdater::PollForMetadata, this);
reporter_thread_ = std::thread([=]() { PollForMetadata(); });
}
}

Expand Down