From 62112b015f3bf80f18a3c30f73bddd478edaeadd Mon Sep 17 00:00:00 2001 From: biubiubiu-ljd <45007501+biubiubiu-ljd@users.noreply.github.com> Date: Wed, 2 Jun 2021 20:54:02 +0800 Subject: [PATCH] get k8s pod (#2173) --- plugins/registry/kubernetes/client/kubernetes.go | 1 + plugins/registry/kubernetes/kubernetes.go | 4 ++-- plugins/registry/kubernetes/watcher.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/registry/kubernetes/client/kubernetes.go b/plugins/registry/kubernetes/client/kubernetes.go index c75c2735..f35212cb 100644 --- a/plugins/registry/kubernetes/client/kubernetes.go +++ b/plugins/registry/kubernetes/client/kubernetes.go @@ -25,6 +25,7 @@ type Meta struct { Name string `json:"name,omitempty"` Labels map[string]*string `json:"labels,omitempty"` Annotations map[string]*string `json:"annotations,omitempty"` + DeletionTimestamp string `json:"deletionTimestamp,omitempty"` } // Status ... diff --git a/plugins/registry/kubernetes/kubernetes.go b/plugins/registry/kubernetes/kubernetes.go index df0e7411..dd9d36b8 100644 --- a/plugins/registry/kubernetes/kubernetes.go +++ b/plugins/registry/kubernetes/kubernetes.go @@ -191,7 +191,7 @@ func (c *kregistry) GetService(name string, opts ...registry.GetOption) ([]*regi // loop through items for _, pod := range pods.Items { - if pod.Status.Phase != podRunning { + if pod.Status.Phase != podRunning || pod.Meta.DeletionTimestamp != "" { continue } // get serialised service from annotation @@ -235,7 +235,7 @@ func (c *kregistry) ListServices(opts ...registry.ListOption) ([]*registry.Servi svcs := make(map[string]bool) for _, pod := range pods.Items { - if pod.Status.Phase != podRunning { + if pod.Status.Phase != podRunning || pod.Meta.DeletionTimestamp != "" { continue } for k, v := range pod.Metadata.Annotations { diff --git a/plugins/registry/kubernetes/watcher.go b/plugins/registry/kubernetes/watcher.go index 884b6730..4fc9b361 100644 --- a/plugins/registry/kubernetes/watcher.go +++ b/plugins/registry/kubernetes/watcher.go @@ -155,7 +155,7 @@ func (k *k8sWatcher) handleEvent(event watch.Event) { for _, result := range results { // pod isnt running - if pod.Status.Phase != podRunning { + if pod.Status.Phase != podRunning || pod.Meta.DeletionTimestamp != "" { result.Action = "delete" } k.next <- result