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>
This commit is contained in:
parent
56eea6e609
commit
9121e78496
9 changed files with 166 additions and 196 deletions
|
@ -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(),
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
if !skipCleanup {
|
||||
*pod = api.Pod{}
|
||||
}
|
||||
*apiPod = api.Pod{}
|
||||
|
||||
return p
|
||||
return pod, nil
|
||||
}
|
||||
|
||||
var _ runtime.Object = &Pod{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue