Reverted k8s-client-go

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
pull/7162/head
Bartlomiej Plotka 5 years ago
parent 8e247ba0ba
commit ee72599e5d

@ -109,19 +109,16 @@ func (noopMetric) Set(float64) {}
type clientGoRequestMetricAdapter struct{}
func (f *clientGoRequestMetricAdapter) Register(registerer prometheus.Registerer) {
metrics.Register(metrics.RegisterOpts{
RequestLatency: f,
RequestResult: f,
})
metrics.Register(f, f)
registerer.MustRegister(
clientGoRequestResultMetricVec,
clientGoRequestLatencyMetricVec,
)
}
func (clientGoRequestMetricAdapter) Increment(code string, _ string, _ string) {
func (clientGoRequestMetricAdapter) Increment(code string, method string, host string) {
clientGoRequestResultMetricVec.WithLabelValues(code).Inc()
}
func (clientGoRequestMetricAdapter) Observe(_ string, u url.URL, latency time.Duration) {
func (clientGoRequestMetricAdapter) Observe(verb string, u url.URL, latency time.Duration) {
clientGoRequestLatencyMetricVec.WithLabelValues(u.EscapedPath()).Observe(latency.Seconds())
}

@ -14,7 +14,6 @@
package kubernetes
import (
"context"
"testing"
"github.com/prometheus/common/model"
@ -80,7 +79,7 @@ func TestEndpointsDiscoveryBeforeRun(t *testing.T) {
discovery: n,
beforeRun: func() {
obj := makeEndpoints()
c.CoreV1().Endpoints(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Endpoints(obj.Namespace).Create(obj)
},
expectedMaxItems: 1,
expectedRes: map[string]*targetgroup.Group{
@ -186,7 +185,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) {
},
},
}
c.CoreV1().Endpoints(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Endpoints(obj.Namespace).Create(obj)
},
expectedMaxItems: 1,
expectedRes: map[string]*targetgroup.Group{
@ -243,7 +242,7 @@ func TestEndpointsDiscoveryDelete(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeEndpoints()
c.CoreV1().Endpoints(obj.Namespace).Delete(context.Background(), obj.Name, metav1.DeleteOptions{})
c.CoreV1().Endpoints(obj.Namespace).Delete(obj.Name, &metav1.DeleteOptions{})
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
@ -296,7 +295,7 @@ func TestEndpointsDiscoveryUpdate(t *testing.T) {
},
},
}
c.CoreV1().Endpoints(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{})
c.CoreV1().Endpoints(obj.Namespace).Update(obj)
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
@ -338,7 +337,7 @@ func TestEndpointsDiscoveryEmptySubsets(t *testing.T) {
},
Subsets: []v1.EndpointSubset{},
}
c.CoreV1().Endpoints(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{})
c.CoreV1().Endpoints(obj.Namespace).Update(obj)
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
@ -368,7 +367,7 @@ func TestEndpointsDiscoveryWithService(t *testing.T) {
},
},
}
c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Services(obj.Namespace).Create(obj)
},
expectedMaxItems: 1,
expectedRes: map[string]*targetgroup.Group{
@ -423,7 +422,7 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) {
},
},
}
c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Services(obj.Namespace).Create(obj)
},
afterStart: func() {
obj := &v1.Service{
@ -436,7 +435,7 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) {
},
},
}
c.CoreV1().Services(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{})
c.CoreV1().Services(obj.Namespace).Update(obj)
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{

@ -14,7 +14,6 @@
package kubernetes
import (
"context"
"fmt"
"testing"
@ -139,7 +138,7 @@ func TestIngressDiscoveryAdd(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeIngress(TLSNo)
c.ExtensionsV1beta1().Ingresses("default").Create(context.Background(), obj, metav1.CreateOptions{})
c.ExtensionsV1beta1().Ingresses("default").Create(obj)
},
expectedMaxItems: 1,
expectedRes: expectedTargetGroups("default", TLSNo),
@ -153,7 +152,7 @@ func TestIngressDiscoveryAddTLS(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeIngress(TLSYes)
c.ExtensionsV1beta1().Ingresses("default").Create(context.Background(), obj, metav1.CreateOptions{})
c.ExtensionsV1beta1().Ingresses("default").Create(obj)
},
expectedMaxItems: 1,
expectedRes: expectedTargetGroups("default", TLSYes),
@ -167,7 +166,7 @@ func TestIngressDiscoveryAddMixed(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeIngress(TLSMixed)
c.ExtensionsV1beta1().Ingresses("default").Create(context.Background(), obj, metav1.CreateOptions{})
c.ExtensionsV1beta1().Ingresses("default").Create(obj)
},
expectedMaxItems: 1,
expectedRes: expectedTargetGroups("default", TLSMixed),
@ -187,7 +186,7 @@ func TestIngressDiscoveryNamespaces(t *testing.T) {
for _, ns := range []string{"ns1", "ns2"} {
obj := makeIngress(TLSNo)
obj.Namespace = ns
c.ExtensionsV1beta1().Ingresses(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.ExtensionsV1beta1().Ingresses(obj.Namespace).Create(obj)
}
},
expectedMaxItems: 2,

@ -317,12 +317,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = d.selectors.endpoints.field
options.LabelSelector = d.selectors.endpoints.label
return e.List(ctx, options)
return e.List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.endpoints.field
options.LabelSelector = d.selectors.endpoints.label
return e.Watch(ctx, options)
return e.Watch(options)
},
}
s := d.client.CoreV1().Services(namespace)
@ -330,12 +330,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = d.selectors.service.field
options.LabelSelector = d.selectors.service.label
return s.List(ctx, options)
return s.List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.service.field
options.LabelSelector = d.selectors.service.label
return s.Watch(ctx, options)
return s.Watch(options)
},
}
p := d.client.CoreV1().Pods(namespace)
@ -343,12 +343,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = d.selectors.pod.field
options.LabelSelector = d.selectors.pod.label
return p.List(ctx, options)
return p.List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.pod.field
options.LabelSelector = d.selectors.pod.label
return p.Watch(ctx, options)
return p.Watch(options)
},
}
eps := NewEndpoints(
@ -369,12 +369,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = d.selectors.pod.field
options.LabelSelector = d.selectors.pod.label
return p.List(ctx, options)
return p.List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.pod.field
options.LabelSelector = d.selectors.pod.label
return p.Watch(ctx, options)
return p.Watch(options)
},
}
pod := NewPod(
@ -391,12 +391,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = d.selectors.service.field
options.LabelSelector = d.selectors.service.label
return s.List(ctx, options)
return s.List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.service.field
options.LabelSelector = d.selectors.service.label
return s.Watch(ctx, options)
return s.Watch(options)
},
}
svc := NewService(
@ -413,12 +413,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = d.selectors.ingress.field
options.LabelSelector = d.selectors.ingress.label
return i.List(ctx, options)
return i.List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.ingress.field
options.LabelSelector = d.selectors.ingress.label
return i.Watch(ctx, options)
return i.Watch(options)
},
}
ingress := NewIngress(
@ -433,12 +433,12 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = d.selectors.node.field
options.LabelSelector = d.selectors.node.label
return d.client.CoreV1().Nodes().List(ctx, options)
return d.client.CoreV1().Nodes().List(options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.node.field
options.LabelSelector = d.selectors.node.label
return d.client.CoreV1().Nodes().Watch(ctx, options)
return d.client.CoreV1().Nodes().Watch(options)
},
}
node := NewNode(

@ -14,7 +14,6 @@
package kubernetes
import (
"context"
"fmt"
"testing"
@ -64,7 +63,7 @@ func TestNodeDiscoveryBeforeStart(t *testing.T) {
map[string]string{"test-label": "testvalue"},
map[string]string{"test-annotation": "testannotationvalue"},
)
c.CoreV1().Nodes().Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Nodes().Create(obj)
},
expectedMaxItems: 1,
expectedRes: map[string]*targetgroup.Group{
@ -96,7 +95,7 @@ func TestNodeDiscoveryAdd(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeEnumeratedNode(1)
c.CoreV1().Nodes().Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Nodes().Create(obj)
},
expectedMaxItems: 1,
expectedRes: map[string]*targetgroup.Group{
@ -124,7 +123,7 @@ func TestNodeDiscoveryDelete(t *testing.T) {
k8sDiscoveryTest{
discovery: n,
afterStart: func() {
c.CoreV1().Nodes().Delete(context.Background(), obj.Name, metav1.DeleteOptions{})
c.CoreV1().Nodes().Delete(obj.Name, &metav1.DeleteOptions{})
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
@ -142,14 +141,14 @@ func TestNodeDiscoveryUpdate(t *testing.T) {
discovery: n,
afterStart: func() {
obj1 := makeEnumeratedNode(0)
c.CoreV1().Nodes().Create(context.Background(), obj1, metav1.CreateOptions{})
c.CoreV1().Nodes().Create(obj1)
obj2 := makeNode(
"test0",
"1.2.3.4",
map[string]string{"Unschedulable": "true"},
map[string]string{},
)
c.CoreV1().Nodes().Update(context.Background(), obj2, metav1.UpdateOptions{})
c.CoreV1().Nodes().Update(obj2)
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{

@ -14,7 +14,6 @@
package kubernetes
import (
"context"
"fmt"
"testing"
@ -197,7 +196,7 @@ func TestPodDiscoveryBeforeRun(t *testing.T) {
discovery: n,
beforeRun: func() {
obj := makeMultiPortPods()
c.CoreV1().Pods(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Pods(obj.Namespace).Create(obj)
},
expectedMaxItems: 1,
expectedRes: map[string]*targetgroup.Group{
@ -265,7 +264,7 @@ func TestPodDiscoveryInitContainer(t *testing.T) {
discovery: n,
beforeRun: func() {
obj := makeInitContainerPods()
c.CoreV1().Pods(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Pods(obj.Namespace).Create(obj)
},
expectedMaxItems: 1,
expectedRes: expected,
@ -279,7 +278,7 @@ func TestPodDiscoveryAdd(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makePods()
c.CoreV1().Pods(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Pods(obj.Namespace).Create(obj)
},
expectedMaxItems: 1,
expectedRes: expectedPodTargetGroups("default"),
@ -294,7 +293,7 @@ func TestPodDiscoveryDelete(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makePods()
c.CoreV1().Pods(obj.Namespace).Delete(context.Background(), obj.Name, metav1.DeleteOptions{})
c.CoreV1().Pods(obj.Namespace).Delete(obj.Name, &metav1.DeleteOptions{})
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
@ -338,7 +337,7 @@ func TestPodDiscoveryUpdate(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makePods()
c.CoreV1().Pods(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{})
c.CoreV1().Pods(obj.Namespace).Update(obj)
},
expectedMaxItems: 2,
expectedRes: expectedPodTargetGroups("default"),
@ -355,10 +354,10 @@ func TestPodDiscoveryUpdateEmptyPodIP(t *testing.T) {
k8sDiscoveryTest{
discovery: n,
beforeRun: func() {
c.CoreV1().Pods(initialPod.Namespace).Create(context.Background(), initialPod, metav1.CreateOptions{})
c.CoreV1().Pods(initialPod.Namespace).Create(initialPod)
},
afterStart: func() {
c.CoreV1().Pods(updatedPod.Namespace).Update(context.Background(), updatedPod, metav1.UpdateOptions{})
c.CoreV1().Pods(updatedPod.Namespace).Update(updatedPod)
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
@ -382,7 +381,7 @@ func TestPodDiscoveryNamespaces(t *testing.T) {
for _, ns := range []string{"ns1", "ns2"} {
pod := makePods()
pod.Namespace = ns
c.CoreV1().Pods(pod.Namespace).Create(context.Background(), pod, metav1.CreateOptions{})
c.CoreV1().Pods(pod.Namespace).Create(pod)
}
},
expectedMaxItems: 2,

@ -14,7 +14,6 @@
package kubernetes
import (
"context"
"fmt"
"testing"
@ -103,9 +102,9 @@ func TestServiceDiscoveryAdd(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeService()
c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Services(obj.Namespace).Create(obj)
obj = makeExternalService()
c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Services(obj.Namespace).Create(obj)
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
@ -152,7 +151,7 @@ func TestServiceDiscoveryDelete(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeService()
c.CoreV1().Services(obj.Namespace).Delete(context.Background(), obj.Name, metav1.DeleteOptions{})
c.CoreV1().Services(obj.Namespace).Delete(obj.Name, &metav1.DeleteOptions{})
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
@ -170,7 +169,7 @@ func TestServiceDiscoveryUpdate(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeMultiPortService()
c.CoreV1().Services(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{})
c.CoreV1().Services(obj.Namespace).Update(obj)
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
@ -214,7 +213,7 @@ func TestServiceDiscoveryNamespaces(t *testing.T) {
for _, ns := range []string{"ns1", "ns2"} {
obj := makeService()
obj.Namespace = ns
c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
c.CoreV1().Services(obj.Namespace).Create(obj)
}
},
expectedMaxItems: 2,

Loading…
Cancel
Save