-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: List only pods for current node #174
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,10 @@ spec: | |
{{- end }} | ||
{{- end }} | ||
env: | ||
- name: KUBERNETES_NODE_NAME | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: spec.nodeName | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This uses the Downward API to set the node name. |
||
{{- if .Values.scaphandre.rustBacktrace }} | ||
- name: RUST_BACKTRACE | ||
value: '{{ .Values.scaphandre.rustBacktrace }}' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,10 @@ use chrono::Utc; | |
use clap::ArgMatches; | ||
use docker_sync::{container::Container, Docker}; | ||
use k8s_sync::kubernetes::Kubernetes; | ||
use k8s_sync::ListOptional; | ||
use k8s_sync::Pod; | ||
use std::collections::HashMap; | ||
use std::env; | ||
use std::fmt; | ||
use std::time::Duration; | ||
use utils::{get_docker_client, get_kubernetes_client, get_scaphandre_version}; | ||
|
@@ -595,7 +597,15 @@ impl MetricGenerator { | |
fn gen_kubernetes_pods_basic_metadata(&mut self) { | ||
if self.watch_kubernetes { | ||
if let Some(kubernetes) = self.kubernetes_client.as_mut() { | ||
if let Ok(pods_result) = kubernetes.list_pods("".to_string()) { | ||
let node_name = env::var("KUBERNETES_NODE_NAME").unwrap_or_default(); | ||
let selector = format!("spec.nodeName={}", node_name); | ||
let mut list_options = ListOptional { | ||
..Default::default() | ||
}; | ||
if !node_name.is_empty() { | ||
list_options.field_selector = Some(&selector); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the cleanest way I could see to set the field selector as it uses a |
||
} | ||
if let Ok(pods_result) = kubernetes.list_pods("".to_string(), list_options) { | ||
self.pods = pods_result; | ||
debug!("Found {} pods", &self.pods.len()); | ||
self.pods_last_check = current_system_time_since_epoch().as_secs().to_string(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs bpetit/rs-k8s-sync#2