Browse Source

discovery/kubernetes: fix broken tests

Signed-off-by: Robert Fratto <robertfratto@gmail.com>
pull/11034/head
Robert Fratto 2 years ago
parent
commit
97be65387d
  1. 7
      discovery/kubernetes/endpoints_test.go
  2. 7
      discovery/kubernetes/endpointslice_test.go
  3. 11
      discovery/kubernetes/pod_test.go

7
discovery/kubernetes/endpoints_test.go

@ -129,6 +129,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) {
Containers: []v1.Container{
{
Name: "c1",
Image: "c1:latest",
Ports: []v1.ContainerPort{
{
Name: "mainport",
@ -139,6 +140,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) {
},
{
Name: "c2",
Image: "c2:latest",
Ports: []v1.ContainerPort{
{
Name: "sideport",
@ -206,6 +208,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) {
"__meta_kubernetes_pod_node_name": "testnode",
"__meta_kubernetes_pod_host_ip": "2.3.4.5",
"__meta_kubernetes_pod_container_name": "c1",
"__meta_kubernetes_pod_container_image": "c1:latest",
"__meta_kubernetes_pod_container_port_name": "mainport",
"__meta_kubernetes_pod_container_port_number": "9000",
"__meta_kubernetes_pod_container_port_protocol": "TCP",
@ -220,6 +223,7 @@ func TestEndpointsDiscoveryAdd(t *testing.T) {
"__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_image": "c2:latest",
"__meta_kubernetes_pod_container_port_name": "sideport",
"__meta_kubernetes_pod_container_port_number": "9001",
"__meta_kubernetes_pod_container_port_protocol": "TCP",
@ -650,6 +654,7 @@ func TestEndpointsDiscoveryNamespaces(t *testing.T) {
Containers: []v1.Container{
{
Name: "c1",
Image: "c1:latest",
Ports: []v1.ContainerPort{
{
Name: "mainport",
@ -720,6 +725,7 @@ func TestEndpointsDiscoveryNamespaces(t *testing.T) {
"__meta_kubernetes_pod_node_name": "testnode",
"__meta_kubernetes_pod_host_ip": "2.3.4.5",
"__meta_kubernetes_pod_container_name": "c1",
"__meta_kubernetes_pod_container_image": "c1:latest",
"__meta_kubernetes_pod_container_port_name": "mainport",
"__meta_kubernetes_pod_container_port_number": "9000",
"__meta_kubernetes_pod_container_port_protocol": "TCP",
@ -754,6 +760,7 @@ func TestEndpointsDiscoveryOwnNamespace(t *testing.T) {
Containers: []v1.Container{
{
Name: "p1",
Image: "p1:latest",
Ports: []v1.ContainerPort{
{
Name: "mainport",

7
discovery/kubernetes/endpointslice_test.go

@ -235,6 +235,7 @@ func TestEndpointSliceDiscoveryAdd(t *testing.T) {
Containers: []corev1.Container{
{
Name: "c1",
Image: "c1:latest",
Ports: []corev1.ContainerPort{
{
Name: "mainport",
@ -245,6 +246,7 @@ func TestEndpointSliceDiscoveryAdd(t *testing.T) {
},
{
Name: "c2",
Image: "c2:latest",
Ports: []corev1.ContainerPort{
{
Name: "sideport",
@ -307,6 +309,7 @@ func TestEndpointSliceDiscoveryAdd(t *testing.T) {
"__meta_kubernetes_endpointslice_port_name": "testport",
"__meta_kubernetes_endpointslice_port_protocol": "TCP",
"__meta_kubernetes_pod_container_name": "c1",
"__meta_kubernetes_pod_container_image": "c1:latest",
"__meta_kubernetes_pod_container_port_name": "mainport",
"__meta_kubernetes_pod_container_port_number": "9000",
"__meta_kubernetes_pod_container_port_protocol": "TCP",
@ -321,6 +324,7 @@ func TestEndpointSliceDiscoveryAdd(t *testing.T) {
{
"__address__": "1.2.3.4:9001",
"__meta_kubernetes_pod_container_name": "c2",
"__meta_kubernetes_pod_container_image": "c2:latest",
"__meta_kubernetes_pod_container_port_name": "sideport",
"__meta_kubernetes_pod_container_port_number": "9001",
"__meta_kubernetes_pod_container_port_protocol": "TCP",
@ -879,6 +883,7 @@ func TestEndpointSliceDiscoveryNamespaces(t *testing.T) {
Containers: []corev1.Container{
{
Name: "c1",
Image: "c1:latest",
Ports: []corev1.ContainerPort{
{
Name: "mainport",
@ -953,6 +958,7 @@ func TestEndpointSliceDiscoveryNamespaces(t *testing.T) {
"__meta_kubernetes_endpointslice_port_name": "testport",
"__meta_kubernetes_endpointslice_port_protocol": "TCP",
"__meta_kubernetes_pod_container_name": "c1",
"__meta_kubernetes_pod_container_image": "c1:latest",
"__meta_kubernetes_pod_container_port_name": "mainport",
"__meta_kubernetes_pod_container_port_number": "9000",
"__meta_kubernetes_pod_container_port_protocol": "TCP",
@ -994,6 +1000,7 @@ func TestEndpointSliceDiscoveryOwnNamespace(t *testing.T) {
Containers: []corev1.Container{
{
Name: "p1",
Image: "p1:latest",
Ports: []corev1.ContainerPort{
{
Name: "mainport",

11
discovery/kubernetes/pod_test.go

@ -51,6 +51,7 @@ func makeMultiPortPods() *v1.Pod {
Containers: []v1.Container{
{
Name: "testcontainer0",
Image: "testcontainer0:latest",
Ports: []v1.ContainerPort{
{
Name: "testport0",
@ -66,6 +67,7 @@ func makeMultiPortPods() *v1.Pod {
},
{
Name: "testcontainer1",
Image: "testcontainer1:latest",
},
},
},
@ -95,6 +97,7 @@ func makePods() *v1.Pod {
Containers: []v1.Container{
{
Name: "testcontainer",
Image: "testcontainer:latest",
Ports: []v1.ContainerPort{
{
Name: "testport",
@ -131,6 +134,7 @@ func makeInitContainerPods() *v1.Pod {
Containers: []v1.Container{
{
Name: "testcontainer",
Image: "testcontainer:latest",
Ports: []v1.ContainerPort{
{
Name: "testport",
@ -144,6 +148,7 @@ func makeInitContainerPods() *v1.Pod {
InitContainers: []v1.Container{
{
Name: "initcontainer",
Image: "initcontainer:latest",
},
},
},
@ -169,6 +174,7 @@ func expectedPodTargetGroups(ns string) map[string]*targetgroup.Group {
{
"__address__": "1.2.3.4:9000",
"__meta_kubernetes_pod_container_name": "testcontainer",
"__meta_kubernetes_pod_container_image": "testcontainer:latest",
"__meta_kubernetes_pod_container_port_name": "testport",
"__meta_kubernetes_pod_container_port_number": "9000",
"__meta_kubernetes_pod_container_port_protocol": "TCP",
@ -219,6 +225,7 @@ func TestPodDiscoveryBeforeRun(t *testing.T) {
{
"__address__": "1.2.3.4:9000",
"__meta_kubernetes_pod_container_name": "testcontainer0",
"__meta_kubernetes_pod_container_image": "testcontainer0:latest",
"__meta_kubernetes_pod_container_port_name": "testport0",
"__meta_kubernetes_pod_container_port_number": "9000",
"__meta_kubernetes_pod_container_port_protocol": "TCP",
@ -227,6 +234,7 @@ func TestPodDiscoveryBeforeRun(t *testing.T) {
{
"__address__": "1.2.3.4:9001",
"__meta_kubernetes_pod_container_name": "testcontainer0",
"__meta_kubernetes_pod_container_image": "testcontainer0:latest",
"__meta_kubernetes_pod_container_port_name": "testport1",
"__meta_kubernetes_pod_container_port_number": "9001",
"__meta_kubernetes_pod_container_port_protocol": "UDP",
@ -235,6 +243,7 @@ func TestPodDiscoveryBeforeRun(t *testing.T) {
{
"__address__": "1.2.3.4",
"__meta_kubernetes_pod_container_name": "testcontainer1",
"__meta_kubernetes_pod_container_image": "testcontainer1:latest",
"__meta_kubernetes_pod_container_init": "false",
},
},
@ -269,6 +278,7 @@ func TestPodDiscoveryInitContainer(t *testing.T) {
expected[key].Targets = append(expected[key].Targets, model.LabelSet{
"__address__": "1.2.3.4",
"__meta_kubernetes_pod_container_name": "initcontainer",
"__meta_kubernetes_pod_container_image": "initcontainer:latest",
"__meta_kubernetes_pod_container_init": "true",
})
expected[key].Labels["__meta_kubernetes_pod_phase"] = "Pending"
@ -330,6 +340,7 @@ func TestPodDiscoveryUpdate(t *testing.T) {
Containers: []v1.Container{
{
Name: "testcontainer",
Image: "testcontainer:latest",
Ports: []v1.ContainerPort{
{
Name: "testport",

Loading…
Cancel
Save