Skip to content

Commit

Permalink
update kubernetes to v1.18.x and update ingress apiVersion
Browse files Browse the repository at this point in the history
Signed-off-by: Tariq Ibrahim <tariq181290@gmail.com>
  • Loading branch information
tariq1890 committed Jun 1, 2020
1 parent 3268eac commit 06a6621
Show file tree
Hide file tree
Showing 421 changed files with 16,890 additions and 9,482 deletions.
7 changes: 6 additions & 1 deletion discovery/kubernetes/client_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ func (noopMetric) Set(float64) {}
type clientGoRequestMetricAdapter struct{}

func (f *clientGoRequestMetricAdapter) Register(registerer prometheus.Registerer) {
metrics.Register(f, f)
metrics.Register(
metrics.RegisterOpts{
RequestLatency: f,
RequestResult: f,
},
)
registerer.MustRegister(
clientGoRequestResultMetricVec,
clientGoRequestLatencyMetricVec,
Expand Down
17 changes: 9 additions & 8 deletions discovery/kubernetes/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package kubernetes

import (
"context"
"testing"

"github.com/prometheus/common/model"
Expand Down Expand Up @@ -79,7 +80,7 @@ func TestEndpointsDiscoveryBeforeRun(t *testing.T) {
discovery: n,
beforeRun: func() {
obj := makeEndpoints()
c.CoreV1().Endpoints(obj.Namespace).Create(obj)
c.CoreV1().Endpoints(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
},
expectedMaxItems: 1,
expectedRes: map[string]*targetgroup.Group{
Expand Down Expand Up @@ -185,7 +186,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) {
},
},
}
c.CoreV1().Endpoints(obj.Namespace).Create(obj)
c.CoreV1().Endpoints(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
},
expectedMaxItems: 1,
expectedRes: map[string]*targetgroup.Group{
Expand Down Expand Up @@ -242,7 +243,7 @@ func TestEndpointsDiscoveryDelete(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeEndpoints()
c.CoreV1().Endpoints(obj.Namespace).Delete(obj.Name, &metav1.DeleteOptions{})
c.CoreV1().Endpoints(obj.Namespace).Delete(context.Background(), obj.Name, metav1.DeleteOptions{})
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
Expand Down Expand Up @@ -295,7 +296,7 @@ func TestEndpointsDiscoveryUpdate(t *testing.T) {
},
},
}
c.CoreV1().Endpoints(obj.Namespace).Update(obj)
c.CoreV1().Endpoints(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{})
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
Expand Down Expand Up @@ -337,7 +338,7 @@ func TestEndpointsDiscoveryEmptySubsets(t *testing.T) {
},
Subsets: []v1.EndpointSubset{},
}
c.CoreV1().Endpoints(obj.Namespace).Update(obj)
c.CoreV1().Endpoints(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{})
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
Expand Down Expand Up @@ -367,7 +368,7 @@ func TestEndpointsDiscoveryWithService(t *testing.T) {
},
},
}
c.CoreV1().Services(obj.Namespace).Create(obj)
c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
},
expectedMaxItems: 1,
expectedRes: map[string]*targetgroup.Group{
Expand Down Expand Up @@ -422,7 +423,7 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) {
},
},
}
c.CoreV1().Services(obj.Namespace).Create(obj)
c.CoreV1().Services(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
},
afterStart: func() {
obj := &v1.Service{
Expand All @@ -435,7 +436,7 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) {
},
},
}
c.CoreV1().Services(obj.Namespace).Update(obj)
c.CoreV1().Services(obj.Namespace).Update(context.Background(), obj, metav1.UpdateOptions{})
},
expectedMaxItems: 2,
expectedRes: map[string]*targetgroup.Group{
Expand Down
2 changes: 1 addition & 1 deletion discovery/kubernetes/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/go-kit/kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"k8s.io/api/extensions/v1beta1"
"k8s.io/api/networking/v1beta1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"

Expand Down
11 changes: 6 additions & 5 deletions discovery/kubernetes/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
package kubernetes

import (
"context"
"fmt"
"testing"

"github.com/prometheus/common/model"
"k8s.io/api/extensions/v1beta1"
"k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/prometheus/prometheus/discovery/targetgroup"
Expand Down Expand Up @@ -138,7 +139,7 @@ func TestIngressDiscoveryAdd(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeIngress(TLSNo)
c.ExtensionsV1beta1().Ingresses("default").Create(obj)
c.NetworkingV1beta1().Ingresses("default").Create(context.Background(), obj, metav1.CreateOptions{})
},
expectedMaxItems: 1,
expectedRes: expectedTargetGroups("default", TLSNo),
Expand All @@ -152,7 +153,7 @@ func TestIngressDiscoveryAddTLS(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeIngress(TLSYes)
c.ExtensionsV1beta1().Ingresses("default").Create(obj)
c.NetworkingV1beta1().Ingresses("default").Create(context.Background(), obj, metav1.CreateOptions{})
},
expectedMaxItems: 1,
expectedRes: expectedTargetGroups("default", TLSYes),
Expand All @@ -166,7 +167,7 @@ func TestIngressDiscoveryAddMixed(t *testing.T) {
discovery: n,
afterStart: func() {
obj := makeIngress(TLSMixed)
c.ExtensionsV1beta1().Ingresses("default").Create(obj)
c.NetworkingV1beta1().Ingresses("default").Create(context.Background(), obj, metav1.CreateOptions{})
},
expectedMaxItems: 1,
expectedRes: expectedTargetGroups("default", TLSMixed),
Expand All @@ -186,7 +187,7 @@ func TestIngressDiscoveryNamespaces(t *testing.T) {
for _, ns := range []string{"ns1", "ns2"} {
obj := makeIngress(TLSNo)
obj.Namespace = ns
c.ExtensionsV1beta1().Ingresses(obj.Namespace).Create(obj)
c.NetworkingV1beta1().Ingresses(obj.Namespace).Create(context.Background(), obj, metav1.CreateOptions{})
}
},
expectedMaxItems: 2,
Expand Down
34 changes: 17 additions & 17 deletions discovery/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
config_util "github.com/prometheus/common/config"
"github.com/prometheus/common/model"
apiv1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
"k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -317,38 +317,38 @@ 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(options)
return e.List(ctx, options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.endpoints.field
options.LabelSelector = d.selectors.endpoints.label
return e.Watch(options)
return e.Watch(ctx, options)
},
}
s := d.client.CoreV1().Services(namespace)
slw := &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = d.selectors.service.field
options.LabelSelector = d.selectors.service.label
return s.List(options)
return s.List(ctx, options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.service.field
options.LabelSelector = d.selectors.service.label
return s.Watch(options)
return s.Watch(ctx, options)
},
}
p := d.client.CoreV1().Pods(namespace)
plw := &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = d.selectors.pod.field
options.LabelSelector = d.selectors.pod.label
return p.List(options)
return p.List(ctx, options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.pod.field
options.LabelSelector = d.selectors.pod.label
return p.Watch(options)
return p.Watch(ctx, options)
},
}
eps := NewEndpoints(
Expand All @@ -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(options)
return p.List(ctx, options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.pod.field
options.LabelSelector = d.selectors.pod.label
return p.Watch(options)
return p.Watch(ctx, options)
},
}
pod := NewPod(
Expand All @@ -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(options)
return s.List(ctx, options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.service.field
options.LabelSelector = d.selectors.service.label
return s.Watch(options)
return s.Watch(ctx, options)
},
}
svc := NewService(
Expand All @@ -408,22 +408,22 @@ func (d *Discovery) Run(ctx context.Context, ch chan<- []*targetgroup.Group) {
}
case RoleIngress:
for _, namespace := range namespaces {
i := d.client.ExtensionsV1beta1().Ingresses(namespace)
i := d.client.NetworkingV1beta1().Ingresses(namespace)
ilw := &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = d.selectors.ingress.field
options.LabelSelector = d.selectors.ingress.label
return i.List(options)
return i.List(ctx, options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = d.selectors.ingress.field
options.LabelSelector = d.selectors.ingress.label
return i.Watch(options)
return i.Watch(ctx, options)
},
}
ingress := NewIngress(
log.With(d.logger, "role", "ingress"),
cache.NewSharedInformer(ilw, &extensionsv1beta1.Ingress{}, resyncPeriod),
cache.NewSharedInformer(ilw, &v1beta1.Ingress{}, resyncPeriod),
)
d.discoverers = append(d.discoverers, ingress)
go ingress.informer.Run(ctx.Done())
Expand All @@ -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(options)
return d.client.CoreV1().Nodes().List(ctx, 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(options)
return d.client.CoreV1().Nodes().Watch(ctx, options)
},
}
node := NewNode(
Expand Down
11 changes: 6 additions & 5 deletions discovery/kubernetes/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package kubernetes

import (
"context"
"fmt"
"testing"

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

0 comments on commit 06a6621

Please sign in to comment.