diff options
Diffstat (limited to 'plugin/kubernetes/object/endpoint.go')
-rw-r--r-- | plugin/kubernetes/object/endpoint.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/plugin/kubernetes/object/endpoint.go b/plugin/kubernetes/object/endpoint.go index 2a7d69acf..f3ce9c2d6 100644 --- a/plugin/kubernetes/object/endpoint.go +++ b/plugin/kubernetes/object/endpoint.go @@ -1,6 +1,8 @@ package object import ( + "fmt" + api "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -43,8 +45,19 @@ type EndpointPort struct { // EndpointsKey return a string using for the index. func EndpointsKey(name, namespace string) string { return name + "." + namespace } -// ToEndpoints converts an api.Endpoints to a *Endpoints. -func ToEndpoints(end *api.Endpoints) *Endpoints { +// ToEndpoints returns a function that converts an *api.Endpoints to a *Endpoints. +func ToEndpoints(skipCleanup bool) ToFunc { + return func(obj interface{}) (interface{}, error) { + eps, ok := obj.(*api.Endpoints) + if !ok { + return nil, fmt.Errorf("unexpected object %v", obj) + } + return toEndpoints(skipCleanup, eps), nil + } +} + +// toEndpoints converts an *api.Endpoints to a *Endpoints. +func toEndpoints(skipCleanup bool, end *api.Endpoints) *Endpoints { e := &Endpoints{ Version: end.GetResourceVersion(), Name: end.GetName(), @@ -88,6 +101,10 @@ func ToEndpoints(end *api.Endpoints) *Endpoints { } } + if !skipCleanup { + *end = api.Endpoints{} + } + return e } |