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
13 changes: 10 additions & 3 deletions src/kubernetes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ constexpr const char kDockerIdPrefix[] = "docker://";
constexpr const char kServiceAccountDirectory[] =
"/var/run/secrets/kubernetes.io/serviceaccount";

// Returns the full path to the secret filename.
std::string SecretPath(const std::string& secret) {
return std::string(kServiceAccountDirectory) + "/" + secret;
}

// Reads a Kubernetes service account secret file into the provided string.
// Returns true if the file was read successfully.
bool ReadServiceAccountSecret(
const std::string& secret, std::string& destination, bool verbose) {
std::string filename(std::string(kServiceAccountDirectory) + "/" + secret);
std::string filename(SecretPath(secret));
std::ifstream input(filename);
if (!input.good()) {
if (verbose) {
Expand Down Expand Up @@ -541,7 +546,8 @@ std::vector<MetadataUpdater::ResourceMetadata>
json::value KubernetesReader::QueryMaster(const std::string& path) const
throw(QueryException, json::Exception) {
const std::string endpoint(config_.KubernetesEndpointHost() + path);
http::client client;
http::client client(
http::client::options().openssl_certificate(SecretPath("ca.crt")));
http::client::request request(endpoint);
request << boost::network::header(
"Authorization", "Bearer " + KubernetesApiToken());
Expand Down Expand Up @@ -799,7 +805,8 @@ void KubernetesReader::WatchMaster(
const std::string watch_param(prefix + kWatchParam);
const std::string endpoint(
config_.KubernetesEndpointHost() + path + watch_param);
http::client client;
http::client client(
http::client::options().openssl_certificate(SecretPath("ca.crt")));
http::client::request request(endpoint);
request << boost::network::header(
"Authorization", "Bearer " + KubernetesApiToken());
Expand Down