diff options
author | 2020-12-01 15:29:05 -0500 | |
---|---|---|
committer | 2020-12-01 15:29:05 -0500 | |
commit | 9121e784966d52bb93696d83d9ab394ac2efd77d (patch) | |
tree | c9d6c6ac28f712116eaec06a72119fc709d8e849 /plugin/kubernetes/object/pod.go | |
parent | 56eea6e6099c41e8913b6c24fbbc156133f22c62 (diff) | |
download | coredns-9121e784966d52bb93696d83d9ab394ac2efd77d.tar.gz coredns-9121e784966d52bb93696d83d9ab394ac2efd77d.tar.zst coredns-9121e784966d52bb93696d83d9ab394ac2efd77d.zip |
plugin/kubernetes: Fix dns programming duration metric (#4255)
* get data reqd to record latency before calling toFuncs
* refactor out unnecessary toFunc wrappers
* remove latency metric unit tests per PR feedback
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/kubernetes/object/pod.go')
-rw-r--r-- | plugin/kubernetes/object/pod.go | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/plugin/kubernetes/object/pod.go b/plugin/kubernetes/object/pod.go index 04cbe1ad2..9b9d5641c 100644 --- a/plugin/kubernetes/object/pod.go +++ b/plugin/kubernetes/object/pod.go @@ -5,6 +5,7 @@ import ( "fmt" api "k8s.io/api/core/v1" + meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -21,37 +22,28 @@ type Pod struct { var errPodTerminating = errors.New("pod terminating") -// ToPod returns a function that converts an api.Pod to a *Pod. -func ToPod(skipCleanup bool) ToFunc { - return func(obj interface{}) (interface{}, error) { - apiPod, ok := obj.(*api.Pod) - if !ok { - return nil, fmt.Errorf("unexpected object %v", obj) - } - pod := toPod(skipCleanup, apiPod) - t := apiPod.ObjectMeta.DeletionTimestamp - if t != nil && !(*t).Time.IsZero() { - // if the pod is in the process of termination, return an error so it can be ignored - // during add/update event processing - return pod, errPodTerminating - } - return pod, nil +// ToPod converts an api.Pod to a *Pod. +func ToPod(obj meta.Object) (meta.Object, error) { + apiPod, ok := obj.(*api.Pod) + if !ok { + return nil, fmt.Errorf("unexpected object %v", obj) } -} - -func toPod(skipCleanup bool, pod *api.Pod) *Pod { - p := &Pod{ - Version: pod.GetResourceVersion(), - PodIP: pod.Status.PodIP, - Namespace: pod.GetNamespace(), - Name: pod.GetName(), + pod := &Pod{ + Version: apiPod.GetResourceVersion(), + PodIP: apiPod.Status.PodIP, + Namespace: apiPod.GetNamespace(), + Name: apiPod.GetName(), } - - if !skipCleanup { - *pod = api.Pod{} + t := apiPod.ObjectMeta.DeletionTimestamp + if t != nil && !(*t).Time.IsZero() { + // if the pod is in the process of termination, return an error so it can be ignored + // during add/update event processing + return pod, errPodTerminating } - return p + *apiPod = api.Pod{} + + return pod, nil } var _ runtime.Object = &Pod{} |