|
|
|
|
@ -18,7 +18,7 @@ import ( |
|
|
|
|
|
|
|
|
|
"github.com/prometheus/common/model" |
|
|
|
|
"github.com/prometheus/prometheus/discovery/targetgroup" |
|
|
|
|
"k8s.io/api/core/v1" |
|
|
|
|
v1 "k8s.io/api/core/v1" |
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
|
|
|
|
"k8s.io/apimachinery/pkg/runtime" |
|
|
|
|
"k8s.io/apimachinery/pkg/types" |
|
|
|
|
@ -69,14 +69,13 @@ func makeEndpoints() *v1.Endpoints { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestEndpointsDiscoveryBeforeRun(t *testing.T) { |
|
|
|
|
n, c, w := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}) |
|
|
|
|
n, c := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}) |
|
|
|
|
|
|
|
|
|
k8sDiscoveryTest{ |
|
|
|
|
discovery: n, |
|
|
|
|
beforeRun: func() { |
|
|
|
|
obj := makeEndpoints() |
|
|
|
|
c.CoreV1().Endpoints(obj.Namespace).Create(obj) |
|
|
|
|
w.Endpoints().Add(obj) |
|
|
|
|
}, |
|
|
|
|
expectedMaxItems: 1, |
|
|
|
|
expectedRes: map[string]*targetgroup.Group{ |
|
|
|
|
@ -148,7 +147,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) { |
|
|
|
|
PodIP: "1.2.3.4", |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
n, c, w := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, obj) |
|
|
|
|
n, c := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, obj) |
|
|
|
|
|
|
|
|
|
k8sDiscoveryTest{ |
|
|
|
|
discovery: n, |
|
|
|
|
@ -181,7 +180,6 @@ func TestEndpointsDiscoveryAdd(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
c.CoreV1().Endpoints(obj.Namespace).Create(obj) |
|
|
|
|
w.Endpoints().Add(obj) |
|
|
|
|
}, |
|
|
|
|
expectedMaxItems: 1, |
|
|
|
|
expectedRes: map[string]*targetgroup.Group{ |
|
|
|
|
@ -232,14 +230,13 @@ func TestEndpointsDiscoveryAdd(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestEndpointsDiscoveryDelete(t *testing.T) { |
|
|
|
|
n, c, w := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, makeEndpoints()) |
|
|
|
|
n, c := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, makeEndpoints()) |
|
|
|
|
|
|
|
|
|
k8sDiscoveryTest{ |
|
|
|
|
discovery: n, |
|
|
|
|
afterStart: func() { |
|
|
|
|
obj := makeEndpoints() |
|
|
|
|
c.CoreV1().Endpoints(obj.Namespace).Delete(obj.Name, &metav1.DeleteOptions{}) |
|
|
|
|
w.Endpoints().Delete(obj) |
|
|
|
|
}, |
|
|
|
|
expectedMaxItems: 2, |
|
|
|
|
expectedRes: map[string]*targetgroup.Group{ |
|
|
|
|
@ -251,7 +248,7 @@ func TestEndpointsDiscoveryDelete(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestEndpointsDiscoveryUpdate(t *testing.T) { |
|
|
|
|
n, c, w := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, makeEndpoints()) |
|
|
|
|
n, c := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, makeEndpoints()) |
|
|
|
|
|
|
|
|
|
k8sDiscoveryTest{ |
|
|
|
|
discovery: n, |
|
|
|
|
@ -293,7 +290,6 @@ func TestEndpointsDiscoveryUpdate(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
c.CoreV1().Endpoints(obj.Namespace).Update(obj) |
|
|
|
|
w.Endpoints().Modify(obj) |
|
|
|
|
}, |
|
|
|
|
expectedMaxItems: 2, |
|
|
|
|
expectedRes: map[string]*targetgroup.Group{ |
|
|
|
|
@ -323,7 +319,7 @@ func TestEndpointsDiscoveryUpdate(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestEndpointsDiscoveryEmptySubsets(t *testing.T) { |
|
|
|
|
n, c, w := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, makeEndpoints()) |
|
|
|
|
n, c := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, makeEndpoints()) |
|
|
|
|
|
|
|
|
|
k8sDiscoveryTest{ |
|
|
|
|
discovery: n, |
|
|
|
|
@ -336,7 +332,6 @@ func TestEndpointsDiscoveryEmptySubsets(t *testing.T) { |
|
|
|
|
Subsets: []v1.EndpointSubset{}, |
|
|
|
|
} |
|
|
|
|
c.CoreV1().Endpoints(obj.Namespace).Update(obj) |
|
|
|
|
w.Endpoints().Modify(obj) |
|
|
|
|
}, |
|
|
|
|
expectedMaxItems: 2, |
|
|
|
|
expectedRes: map[string]*targetgroup.Group{ |
|
|
|
|
@ -352,7 +347,7 @@ func TestEndpointsDiscoveryEmptySubsets(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestEndpointsDiscoveryWithService(t *testing.T) { |
|
|
|
|
n, c, w := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, makeEndpoints()) |
|
|
|
|
n, c := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, makeEndpoints()) |
|
|
|
|
|
|
|
|
|
k8sDiscoveryTest{ |
|
|
|
|
discovery: n, |
|
|
|
|
@ -367,7 +362,6 @@ func TestEndpointsDiscoveryWithService(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
c.CoreV1().Services(obj.Namespace).Create(obj) |
|
|
|
|
w.Services().Add(obj) |
|
|
|
|
}, |
|
|
|
|
expectedMaxItems: 1, |
|
|
|
|
expectedRes: map[string]*targetgroup.Group{ |
|
|
|
|
@ -405,7 +399,7 @@ func TestEndpointsDiscoveryWithService(t *testing.T) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) { |
|
|
|
|
n, c, w := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, makeEndpoints()) |
|
|
|
|
n, c := makeDiscovery(RoleEndpoint, NamespaceDiscovery{}, makeEndpoints()) |
|
|
|
|
|
|
|
|
|
k8sDiscoveryTest{ |
|
|
|
|
discovery: n, |
|
|
|
|
@ -420,7 +414,6 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
c.CoreV1().Services(obj.Namespace).Create(obj) |
|
|
|
|
w.Services().Add(obj) |
|
|
|
|
}, |
|
|
|
|
afterStart: func() { |
|
|
|
|
obj := &v1.Service{ |
|
|
|
|
@ -434,7 +427,6 @@ func TestEndpointsDiscoveryWithServiceUpdate(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
c.CoreV1().Services(obj.Namespace).Update(obj) |
|
|
|
|
w.Services().Modify(obj) |
|
|
|
|
}, |
|
|
|
|
expectedMaxItems: 2, |
|
|
|
|
expectedRes: map[string]*targetgroup.Group{ |
|
|
|
|
@ -540,7 +532,7 @@ func TestEndpointsDiscoveryNamespaces(t *testing.T) { |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
n, _, _ := makeDiscovery(RoleEndpoint, NamespaceDiscovery{Names: []string{"ns1", "ns2"}}, objs...) |
|
|
|
|
n, _ := makeDiscovery(RoleEndpoint, NamespaceDiscovery{Names: []string{"ns1", "ns2"}}, objs...) |
|
|
|
|
|
|
|
|
|
k8sDiscoveryTest{ |
|
|
|
|
discovery: n, |
|
|
|
|
|