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

Handle deletion events from watch and purge deleted entries. #62

Merged
merged 4 commits into from
Feb 26, 2018

Conversation

igorpeshansky
Copy link
Member

Also a minor refactoring of the watch code.

@@ -33,6 +33,7 @@ constexpr const int kMetadataApiDefaultNumThreads = 3;
constexpr const int kMetadataApiDefaultPort = 8000;
constexpr const char kMetadataApiDefaultResourceTypeSeparator[] = ".";
constexpr const int kMetadataReporterDefaultIntervalSeconds = 60;
constexpr const int kMetadataReporterDefaultPurgeDeleted = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be defaulting to true?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather put this through a few more tests. It can be overridden in the config map if necessary.

@@ -322,7 +316,7 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetContainerMetadata(
k8s_container_name,
};

if (container_status) {
if (container_status && container_status->Has("containerID")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this added? Do we directly depend on this property anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, right below. The deletion events apparently had a status without a container id.

@@ -737,8 +754,8 @@ void KubernetesReader::WatchMaster(
// A notification for watch completion.
std::mutex completion_mutex;
std::unique_lock<std::mutex> watch_completion(completion_mutex);
Watcher watcher(callback, std::move(watch_completion),
config_.VerboseLogging());
Watcher watcher(std::bind(&EventCallback, callback, std::placeholders::_1),
Copy link
Contributor

Choose a reason for hiding this comment

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

std::placeholders::_N leaves me a bit puzzled. Is there a way of doing these methods without using unbound arguments?

Copy link
Member Author

Choose a reason for hiding this comment

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

They confuse me too. Unfortunately, there is no better way.
If it helps, think about std::bind as: you have to list all of the arguments to the bound function, but some of those can represent the arguments to the function being called -- that's what placeholders are (std::placeholders::_1 is the first argument to the resulting function).

Copy link
Member Author

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

Thanks for the review. PTAL.

@@ -33,6 +33,7 @@ constexpr const int kMetadataApiDefaultNumThreads = 3;
constexpr const int kMetadataApiDefaultPort = 8000;
constexpr const char kMetadataApiDefaultResourceTypeSeparator[] = ".";
constexpr const int kMetadataReporterDefaultIntervalSeconds = 60;
constexpr const int kMetadataReporterDefaultPurgeDeleted = false;
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather put this through a few more tests. It can be overridden in the config map if necessary.

@@ -322,7 +316,7 @@ MetadataUpdater::ResourceMetadata KubernetesReader::GetContainerMetadata(
k8s_container_name,
};

if (container_status) {
if (container_status && container_status->Has("containerID")) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, right below. The deletion events apparently had a status without a container id.

@@ -737,8 +754,8 @@ void KubernetesReader::WatchMaster(
// A notification for watch completion.
std::mutex completion_mutex;
std::unique_lock<std::mutex> watch_completion(completion_mutex);
Watcher watcher(callback, std::move(watch_completion),
config_.VerboseLogging());
Watcher watcher(std::bind(&EventCallback, callback, std::placeholders::_1),
Copy link
Member Author

Choose a reason for hiding this comment

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

They confuse me too. Unfortunately, there is no better way.
If it helps, think about std::bind as: you have to list all of the arguments to the bound function, but some of those can represent the arguments to the function being called -- that's what placeholders are (std::placeholders::_1 is the first argument to the resulting function).

Copy link
Contributor

@supriyagarg supriyagarg left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@bmoyles0117 bmoyles0117 left a comment

Choose a reason for hiding this comment

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

LGTM

@igorpeshansky igorpeshansky force-pushed the igorp-kubernetes-deletion-events branch from 4d3eadd to 9c46711 Compare February 26, 2018 17:31
@igorpeshansky
Copy link
Member Author

Rebased off master.

Copy link
Contributor

@bmoyles0117 bmoyles0117 left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

@igorpeshansky igorpeshansky merged commit 7880c04 into master Feb 26, 2018
@igorpeshansky igorpeshansky deleted the igorp-kubernetes-deletion-events branch February 26, 2018 17:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants