aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/object/endpoint.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/kubernetes/object/endpoint.go')
-rw-r--r--plugin/kubernetes/object/endpoint.go49
1 files changed, 16 insertions, 33 deletions
diff --git a/plugin/kubernetes/object/endpoint.go b/plugin/kubernetes/object/endpoint.go
index 304aaa861..09429e0b2 100644
--- a/plugin/kubernetes/object/endpoint.go
+++ b/plugin/kubernetes/object/endpoint.go
@@ -5,6 +5,7 @@ import (
api "k8s.io/api/core/v1"
discovery "k8s.io/api/discovery/v1beta1"
+ meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
@@ -46,30 +47,12 @@ type EndpointPort struct {
// EndpointsKey returns a string using for the index.
func EndpointsKey(name, namespace string) string { return name + "." + namespace }
-// 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
- }
-}
-
-// EndpointSliceToEndpoints returns a function that converts an *discovery.EndpointSlice to a *Endpoints.
-func EndpointSliceToEndpoints(skipCleanup bool) ToFunc {
- return func(obj interface{}) (interface{}, error) {
- eps, ok := obj.(*discovery.EndpointSlice)
- if !ok {
- return nil, fmt.Errorf("unexpected object %v", obj)
- }
- return endpointSliceToEndpoints(skipCleanup, eps), nil
- }
-}
-
// toEndpoints converts an *api.Endpoints to a *Endpoints.
-func toEndpoints(skipCleanup bool, end *api.Endpoints) *Endpoints {
+func ToEndpoints(obj meta.Object) (meta.Object, error) {
+ end, ok := obj.(*api.Endpoints)
+ if !ok {
+ return nil, fmt.Errorf("unexpected object %v", obj)
+ }
e := &Endpoints{
Version: end.GetResourceVersion(),
Name: end.GetName(),
@@ -113,15 +96,17 @@ func toEndpoints(skipCleanup bool, end *api.Endpoints) *Endpoints {
}
}
- if !skipCleanup {
- *end = api.Endpoints{}
- }
+ *end = api.Endpoints{}
- return e
+ return e, nil
}
-// endpointSliceToEndpoints converts a *discovery.EndpointSlice to a *Endpoints.
-func endpointSliceToEndpoints(skipCleanup bool, ends *discovery.EndpointSlice) *Endpoints {
+// EndpointSliceToEndpoints converts a *discovery.EndpointSlice to a *Endpoints.
+func EndpointSliceToEndpoints(obj meta.Object) (meta.Object, error) {
+ ends, ok := obj.(*discovery.EndpointSlice)
+ if !ok {
+ return nil, fmt.Errorf("unexpected object %v", obj)
+ }
e := &Endpoints{
Version: ends.GetResourceVersion(),
Name: ends.GetName(),
@@ -156,11 +141,9 @@ func endpointSliceToEndpoints(skipCleanup bool, ends *discovery.EndpointSlice) *
}
}
- if !skipCleanup {
- *ends = discovery.EndpointSlice{}
- }
+ *ends = discovery.EndpointSlice{}
- return e
+ return e, nil
}
// CopyWithoutSubsets copies e, without the subsets.