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 (
|
|||
|
||||
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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue