plugin/kubernetes: fix tombstone unwrapping (#3924)

* fix tombstone unwrapping

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver 2020-06-15 10:15:41 -04:00 committed by GitHub
parent d35c8e9eda
commit d902e85919
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 163 additions and 83 deletions

View file

@ -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
}