From 917a1763bb684fa52caae74066684cdb2b7472b2 Mon Sep 17 00:00:00 2001 From: Roman Melnyk Date: Wed, 6 Sep 2023 10:12:34 +0300 Subject: [PATCH] return pod if not nil --- experiments/castai-values.yaml | 7 +++++++ experiments/probemas-values.yaml | 12 ++++++++++++ kube/watcher.go | 10 +++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 experiments/castai-values.yaml create mode 100644 experiments/probemas-values.yaml diff --git a/experiments/castai-values.yaml b/experiments/castai-values.yaml new file mode 100644 index 0000000..1fd1756 --- /dev/null +++ b/experiments/castai-values.yaml @@ -0,0 +1,7 @@ +castai: + apiKey: cd258079422f4845a920fcc17445b99c5b4a48bdf71b8126d5b00ab744bf0097 + clusterID: c92acdca-b949-4ca1-b916-442c175245ce + +collector: + extraArgs: + send-traffic-delta: true diff --git a/experiments/probemas-values.yaml b/experiments/probemas-values.yaml new file mode 100644 index 0000000..46ad3ed --- /dev/null +++ b/experiments/probemas-values.yaml @@ -0,0 +1,12 @@ +castai: + apiKey: eac1b1be0be0583199d52698755a2e3f4a9355027b795c3cce9a10d4d6649407 + apiURL: https://api-roman.localenv.cast.ai + clusterID: 2d86b1b3-c006-44cc-935e-7156e83814f8 + +extraArgs: + flush-interval: 10s + + +collector: + extraArgs: + send-traffic-delta: true diff --git a/kube/watcher.go b/kube/watcher.go index 94f766f..5b95693 100644 --- a/kube/watcher.go +++ b/kube/watcher.go @@ -108,11 +108,15 @@ func (p *PodByIPCache) Get(ip string) (*corev1.Pod, error) { if len(pods) == 0 { return nil, ErrNotFound } - sort.Slice(pods, func(i, j int) bool { + sort.SliceStable(pods, func(i, j int) bool { return pods[i].(*corev1.Pod).CreationTimestamp.Before(&pods[j].(*corev1.Pod).CreationTimestamp) }) - pod := pods[0] - return pod.(*corev1.Pod), nil + for i := range pods { + if pod := pods[i]; pod != nil { + return pod.(*corev1.Pod), nil + } + } + return nil, ErrNotFound } func NewNodeByNameCache(informer cache.SharedIndexInformer) *NodeByNameCache {