aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/object/pod.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/kubernetes/object/pod.go')
-rw-r--r--plugin/kubernetes/object/pod.go46
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{}