2016-10-14 08:16:06 -07:00
|
|
|
// Copyright 2016 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package kubernetes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/prometheus/common/model"
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
"github.com/prometheus/prometheus/discovery/targetgroup"
|
2017-05-11 01:29:10 -07:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-11-24 04:24:13 -08:00
|
|
|
"k8s.io/apimachinery/pkg/types"
|
2017-05-11 01:29:10 -07:00
|
|
|
"k8s.io/client-go/pkg/api/v1"
|
|
|
|
"k8s.io/client-go/tools/cache"
|
2016-10-14 08:16:06 -07:00
|
|
|
)
|
|
|
|
|
2016-10-17 02:05:13 -07:00
|
|
|
func endpointsStoreKeyFunc(obj interface{}) (string, error) {
|
2016-10-14 08:16:06 -07:00
|
|
|
return obj.(*v1.Endpoints).ObjectMeta.Name, nil
|
|
|
|
}
|
|
|
|
|
2016-10-17 02:05:13 -07:00
|
|
|
func newFakeEndpointsInformer() *fakeInformer {
|
|
|
|
return newFakeInformer(endpointsStoreKeyFunc)
|
2016-10-14 08:16:06 -07:00
|
|
|
}
|
|
|
|
|
2016-10-17 02:05:13 -07:00
|
|
|
func makeTestEndpointsDiscovery() (*Endpoints, *fakeInformer, *fakeInformer, *fakeInformer) {
|
2016-10-14 08:16:06 -07:00
|
|
|
svc := newFakeServiceInformer()
|
2016-10-17 02:05:13 -07:00
|
|
|
eps := newFakeEndpointsInformer()
|
2016-10-14 08:16:06 -07:00
|
|
|
pod := newFakePodInformer()
|
2017-08-11 11:45:52 -07:00
|
|
|
return NewEndpoints(nil, svc, eps, pod), svc, eps, pod
|
2016-10-14 08:16:06 -07:00
|
|
|
}
|
|
|
|
|
2016-10-17 02:05:13 -07:00
|
|
|
func makeEndpoints() *v1.Endpoints {
|
2016-10-14 08:16:06 -07:00
|
|
|
return &v1.Endpoints{
|
2017-05-11 01:29:10 -07:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "testendpoints",
|
|
|
|
Namespace: "default",
|
|
|
|
},
|
|
|
|
Subsets: []v1.EndpointSubset{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Addresses: []v1.EndpointAddress{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
IP: "1.2.3.4",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ports: []v1.EndpointPort{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "testport",
|
|
|
|
Port: 9000,
|
|
|
|
Protocol: v1.ProtocolTCP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Addresses: []v1.EndpointAddress{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
IP: "2.3.4.5",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
NotReadyAddresses: []v1.EndpointAddress{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
IP: "2.3.4.5",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ports: []v1.EndpointPort{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "testport",
|
|
|
|
Port: 9001,
|
|
|
|
Protocol: v1.ProtocolTCP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-17 02:05:13 -07:00
|
|
|
func TestEndpointsDiscoveryInitial(t *testing.T) {
|
|
|
|
n, _, eps, _ := makeTestEndpointsDiscovery()
|
|
|
|
eps.GetStore().Add(makeEndpoints())
|
2016-10-14 08:16:06 -07:00
|
|
|
|
|
|
|
k8sDiscoveryTest{
|
|
|
|
discovery: n,
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
expectedInitial: []*targetgroup.Group{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Targets: []model.LabelSet{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
"__address__": "1.2.3.4:9000",
|
|
|
|
"__meta_kubernetes_endpoint_port_name": "testport",
|
|
|
|
"__meta_kubernetes_endpoint_port_protocol": "TCP",
|
|
|
|
"__meta_kubernetes_endpoint_ready": "true",
|
|
|
|
},
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
"__address__": "2.3.4.5:9001",
|
|
|
|
"__meta_kubernetes_endpoint_port_name": "testport",
|
|
|
|
"__meta_kubernetes_endpoint_port_protocol": "TCP",
|
|
|
|
"__meta_kubernetes_endpoint_ready": "true",
|
|
|
|
},
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
"__address__": "2.3.4.5:9001",
|
|
|
|
"__meta_kubernetes_endpoint_port_name": "testport",
|
|
|
|
"__meta_kubernetes_endpoint_port_protocol": "TCP",
|
|
|
|
"__meta_kubernetes_endpoint_ready": "false",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Labels: model.LabelSet{
|
|
|
|
"__meta_kubernetes_namespace": "default",
|
|
|
|
"__meta_kubernetes_endpoints_name": "testendpoints",
|
|
|
|
},
|
|
|
|
Source: "endpoints/default/testendpoints",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Run(t)
|
|
|
|
}
|
|
|
|
|
2016-10-17 02:05:13 -07:00
|
|
|
func TestEndpointsDiscoveryAdd(t *testing.T) {
|
|
|
|
n, _, eps, pods := makeTestEndpointsDiscovery()
|
2016-10-14 08:16:06 -07:00
|
|
|
pods.GetStore().Add(&v1.Pod{
|
2017-05-11 01:29:10 -07:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "testpod",
|
|
|
|
Namespace: "default",
|
2017-11-24 04:24:13 -08:00
|
|
|
UID: types.UID("deadbeef"),
|
2016-10-14 08:16:06 -07:00
|
|
|
},
|
|
|
|
Spec: v1.PodSpec{
|
|
|
|
NodeName: "testnode",
|
|
|
|
Containers: []v1.Container{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "c1",
|
|
|
|
Ports: []v1.ContainerPort{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "mainport",
|
|
|
|
ContainerPort: 9000,
|
|
|
|
Protocol: v1.ProtocolTCP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "c2",
|
|
|
|
Ports: []v1.ContainerPort{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "sideport",
|
|
|
|
ContainerPort: 9001,
|
|
|
|
Protocol: v1.ProtocolTCP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Status: v1.PodStatus{
|
|
|
|
HostIP: "2.3.4.5",
|
|
|
|
PodIP: "1.2.3.4",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
k8sDiscoveryTest{
|
|
|
|
discovery: n,
|
|
|
|
afterStart: func() {
|
|
|
|
go func() {
|
|
|
|
eps.Add(
|
|
|
|
&v1.Endpoints{
|
2017-05-11 01:29:10 -07:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "testendpoints",
|
|
|
|
Namespace: "default",
|
|
|
|
},
|
|
|
|
Subsets: []v1.EndpointSubset{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Addresses: []v1.EndpointAddress{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
IP: "4.3.2.1",
|
|
|
|
TargetRef: &v1.ObjectReference{
|
|
|
|
Kind: "Pod",
|
|
|
|
Name: "testpod",
|
|
|
|
Namespace: "default",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ports: []v1.EndpointPort{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "testport",
|
|
|
|
Port: 9000,
|
|
|
|
Protocol: v1.ProtocolTCP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}()
|
|
|
|
},
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
expectedRes: []*targetgroup.Group{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Targets: []model.LabelSet{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
"__address__": "4.3.2.1:9000",
|
|
|
|
"__meta_kubernetes_endpoint_port_name": "testport",
|
|
|
|
"__meta_kubernetes_endpoint_port_protocol": "TCP",
|
|
|
|
"__meta_kubernetes_endpoint_ready": "true",
|
|
|
|
"__meta_kubernetes_pod_name": "testpod",
|
|
|
|
"__meta_kubernetes_pod_ip": "1.2.3.4",
|
|
|
|
"__meta_kubernetes_pod_ready": "unknown",
|
|
|
|
"__meta_kubernetes_pod_node_name": "testnode",
|
|
|
|
"__meta_kubernetes_pod_host_ip": "2.3.4.5",
|
|
|
|
"__meta_kubernetes_pod_container_name": "c1",
|
2016-10-17 02:05:13 -07:00
|
|
|
"__meta_kubernetes_pod_container_port_name": "mainport",
|
|
|
|
"__meta_kubernetes_pod_container_port_number": "9000",
|
2016-10-14 08:16:06 -07:00
|
|
|
"__meta_kubernetes_pod_container_port_protocol": "TCP",
|
2017-11-24 04:24:13 -08:00
|
|
|
"__meta_kubernetes_pod_uid": "deadbeef",
|
2016-10-14 08:16:06 -07:00
|
|
|
},
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
"__address__": "1.2.3.4:9001",
|
|
|
|
"__meta_kubernetes_pod_name": "testpod",
|
|
|
|
"__meta_kubernetes_pod_ip": "1.2.3.4",
|
|
|
|
"__meta_kubernetes_pod_ready": "unknown",
|
|
|
|
"__meta_kubernetes_pod_node_name": "testnode",
|
|
|
|
"__meta_kubernetes_pod_host_ip": "2.3.4.5",
|
|
|
|
"__meta_kubernetes_pod_container_name": "c2",
|
|
|
|
"__meta_kubernetes_pod_container_port_name": "sideport",
|
2016-10-17 02:05:13 -07:00
|
|
|
"__meta_kubernetes_pod_container_port_number": "9001",
|
2016-10-14 08:16:06 -07:00
|
|
|
"__meta_kubernetes_pod_container_port_protocol": "TCP",
|
2017-11-24 04:24:13 -08:00
|
|
|
"__meta_kubernetes_pod_uid": "deadbeef",
|
2016-10-14 08:16:06 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Labels: model.LabelSet{
|
|
|
|
"__meta_kubernetes_endpoints_name": "testendpoints",
|
|
|
|
"__meta_kubernetes_namespace": "default",
|
|
|
|
},
|
|
|
|
Source: "endpoints/default/testendpoints",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Run(t)
|
|
|
|
}
|
|
|
|
|
2016-10-17 02:05:13 -07:00
|
|
|
func TestEndpointsDiscoveryDelete(t *testing.T) {
|
|
|
|
n, _, eps, _ := makeTestEndpointsDiscovery()
|
|
|
|
eps.GetStore().Add(makeEndpoints())
|
2016-10-14 08:16:06 -07:00
|
|
|
|
|
|
|
k8sDiscoveryTest{
|
|
|
|
discovery: n,
|
2016-10-17 02:05:13 -07:00
|
|
|
afterStart: func() { go func() { eps.Delete(makeEndpoints()) }() },
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
expectedRes: []*targetgroup.Group{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Source: "endpoints/default/testendpoints",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Run(t)
|
|
|
|
}
|
|
|
|
|
2016-11-14 07:21:38 -08:00
|
|
|
func TestEndpointsDiscoveryDeleteUnknownCacheState(t *testing.T) {
|
|
|
|
n, _, eps, _ := makeTestEndpointsDiscovery()
|
|
|
|
eps.GetStore().Add(makeEndpoints())
|
|
|
|
|
|
|
|
k8sDiscoveryTest{
|
|
|
|
discovery: n,
|
|
|
|
afterStart: func() { go func() { eps.Delete(cache.DeletedFinalStateUnknown{Obj: makeEndpoints()}) }() },
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
expectedRes: []*targetgroup.Group{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-11-14 07:21:38 -08:00
|
|
|
Source: "endpoints/default/testendpoints",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Run(t)
|
|
|
|
}
|
|
|
|
|
2016-10-17 02:05:13 -07:00
|
|
|
func TestEndpointsDiscoveryUpdate(t *testing.T) {
|
|
|
|
n, _, eps, _ := makeTestEndpointsDiscovery()
|
|
|
|
eps.GetStore().Add(makeEndpoints())
|
2016-10-14 08:16:06 -07:00
|
|
|
|
|
|
|
k8sDiscoveryTest{
|
|
|
|
discovery: n,
|
|
|
|
afterStart: func() {
|
|
|
|
go func() {
|
|
|
|
eps.Update(&v1.Endpoints{
|
2017-05-11 01:29:10 -07:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "testendpoints",
|
|
|
|
Namespace: "default",
|
|
|
|
},
|
|
|
|
Subsets: []v1.EndpointSubset{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Addresses: []v1.EndpointAddress{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
IP: "1.2.3.4",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ports: []v1.EndpointPort{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "testport",
|
|
|
|
Port: 9000,
|
|
|
|
Protocol: v1.ProtocolTCP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Addresses: []v1.EndpointAddress{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
IP: "2.3.4.5",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Ports: []v1.EndpointPort{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Name: "testport",
|
|
|
|
Port: 9001,
|
|
|
|
Protocol: v1.ProtocolTCP,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
},
|
Refactor SD configuration to remove `config` dependency (#3629)
* refactor: move targetGroup struct and CheckOverflow() to their own package
* refactor: move auth and security related structs to a utility package, fix import error in utility package
* refactor: Azure SD, remove SD struct from config
* refactor: DNS SD, remove SD struct from config into dns package
* refactor: ec2 SD, move SD struct from config into the ec2 package
* refactor: file SD, move SD struct from config to file discovery package
* refactor: gce, move SD struct from config to gce discovery package
* refactor: move HTTPClientConfig and URL into util/config, fix import error in httputil
* refactor: consul, move SD struct from config into consul discovery package
* refactor: marathon, move SD struct from config into marathon discovery package
* refactor: triton, move SD struct from config to triton discovery package, fix test
* refactor: zookeeper, move SD structs from config to zookeeper discovery package
* refactor: openstack, remove SD struct from config, move into openstack discovery package
* refactor: kubernetes, move SD struct from config into kubernetes discovery package
* refactor: notifier, use targetgroup package instead of config
* refactor: tests for file, marathon, triton SD - use targetgroup package instead of config.TargetGroup
* refactor: retrieval, use targetgroup package instead of config.TargetGroup
* refactor: storage, use config util package
* refactor: discovery manager, use targetgroup package instead of config.TargetGroup
* refactor: use HTTPClient and TLS config from configUtil instead of config
* refactor: tests, use targetgroup package instead of config.TargetGroup
* refactor: fix tagetgroup.Group pointers that were removed by mistake
* refactor: openstack, kubernetes: drop prefixes
* refactor: remove import aliases forced due to vscode bug
* refactor: move main SD struct out of config into discovery/config
* refactor: rename configUtil to config_util
* refactor: rename yamlUtil to yaml_config
* refactor: kubernetes, remove prefixes
* refactor: move the TargetGroup package to discovery/
* refactor: fix order of imports
2017-12-29 12:01:34 -08:00
|
|
|
expectedRes: []*targetgroup.Group{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
Targets: []model.LabelSet{
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
"__address__": "1.2.3.4:9000",
|
|
|
|
"__meta_kubernetes_endpoint_port_name": "testport",
|
|
|
|
"__meta_kubernetes_endpoint_port_protocol": "TCP",
|
|
|
|
"__meta_kubernetes_endpoint_ready": "true",
|
|
|
|
},
|
2017-03-16 16:29:47 -07:00
|
|
|
{
|
2016-10-14 08:16:06 -07:00
|
|
|
"__address__": "2.3.4.5:9001",
|
|
|
|
"__meta_kubernetes_endpoint_port_name": "testport",
|
|
|
|
"__meta_kubernetes_endpoint_port_protocol": "TCP",
|
|
|
|
"__meta_kubernetes_endpoint_ready": "true",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Labels: model.LabelSet{
|
|
|
|
"__meta_kubernetes_namespace": "default",
|
|
|
|
"__meta_kubernetes_endpoints_name": "testendpoints",
|
|
|
|
},
|
|
|
|
Source: "endpoints/default/testendpoints",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.Run(t)
|
|
|
|
}
|