mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
add label and labelpresent for endpointslice role in k8s discovery
Signed-off-by: renzheng.wang <wangrzneu@gmail.com>
This commit is contained in:
parent
92d6980360
commit
866fa25b20
|
@ -29,7 +29,6 @@ import (
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/discovery/targetgroup"
|
"github.com/prometheus/prometheus/discovery/targetgroup"
|
||||||
"github.com/prometheus/prometheus/util/strutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -248,9 +247,6 @@ func endpointsSourceFromNamespaceAndName(namespace, name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
endpointsLabelPrefix = metaLabelPrefix + "endpoints_label_"
|
|
||||||
endpointsLabelPresentPrefix = metaLabelPrefix + "endpoints_labelpresent_"
|
|
||||||
endpointsNameLabel = metaLabelPrefix + "endpoints_name"
|
|
||||||
endpointNodeName = metaLabelPrefix + "endpoint_node_name"
|
endpointNodeName = metaLabelPrefix + "endpoint_node_name"
|
||||||
endpointHostname = metaLabelPrefix + "endpoint_hostname"
|
endpointHostname = metaLabelPrefix + "endpoint_hostname"
|
||||||
endpointReadyLabel = metaLabelPrefix + "endpoint_ready"
|
endpointReadyLabel = metaLabelPrefix + "endpoint_ready"
|
||||||
|
@ -266,15 +262,10 @@ func (e *Endpoints) buildEndpoints(eps *apiv1.Endpoints) *targetgroup.Group {
|
||||||
}
|
}
|
||||||
tg.Labels = model.LabelSet{
|
tg.Labels = model.LabelSet{
|
||||||
namespaceLabel: lv(eps.Namespace),
|
namespaceLabel: lv(eps.Namespace),
|
||||||
endpointsNameLabel: lv(eps.Name),
|
|
||||||
}
|
}
|
||||||
e.addServiceLabels(eps.Namespace, eps.Name, tg)
|
e.addServiceLabels(eps.Namespace, eps.Name, tg)
|
||||||
// Add endpoints labels metadata.
|
// Add endpoints labels metadata.
|
||||||
for k, v := range eps.Labels {
|
addObjectMetaLabels(tg.Labels, eps.ObjectMeta, RoleEndpoint)
|
||||||
ln := strutil.SanitizeLabelName(k)
|
|
||||||
tg.Labels[model.LabelName(endpointsLabelPrefix+ln)] = lv(v)
|
|
||||||
tg.Labels[model.LabelName(endpointsLabelPresentPrefix+ln)] = presentValue
|
|
||||||
}
|
|
||||||
|
|
||||||
type podEntry struct {
|
type podEntry struct {
|
||||||
pod *apiv1.Pod
|
pod *apiv1.Pod
|
||||||
|
@ -462,14 +453,7 @@ func addNodeLabels(tg model.LabelSet, nodeInf cache.SharedInformer, logger log.L
|
||||||
|
|
||||||
node := obj.(*apiv1.Node)
|
node := obj.(*apiv1.Node)
|
||||||
// Allocate one target label for the node name,
|
// Allocate one target label for the node name,
|
||||||
// and two target labels for each node label.
|
nodeLabelset := make(model.LabelSet)
|
||||||
nodeLabelset := make(model.LabelSet, 1+2*len(node.GetLabels()))
|
addObjectMetaLabels(nodeLabelset, node.ObjectMeta, RoleNode)
|
||||||
nodeLabelset[nodeNameLabel] = lv(*nodeName)
|
|
||||||
for k, v := range node.GetLabels() {
|
|
||||||
ln := strutil.SanitizeLabelName(k)
|
|
||||||
nodeLabelset[model.LabelName(nodeLabelPrefix+ln)] = lv(v)
|
|
||||||
nodeLabelset[model.LabelName(nodeLabelPresentPrefix+ln)] = presentValue
|
|
||||||
}
|
|
||||||
|
|
||||||
return tg.Merge(nodeLabelset)
|
return tg.Merge(nodeLabelset)
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,9 +274,11 @@ func (e *EndpointSlice) buildEndpointSlice(eps endpointSliceAdaptor) *targetgrou
|
||||||
}
|
}
|
||||||
tg.Labels = model.LabelSet{
|
tg.Labels = model.LabelSet{
|
||||||
namespaceLabel: lv(eps.namespace()),
|
namespaceLabel: lv(eps.namespace()),
|
||||||
endpointSliceNameLabel: lv(eps.name()),
|
|
||||||
endpointSliceAddressTypeLabel: lv(eps.addressType()),
|
endpointSliceAddressTypeLabel: lv(eps.addressType()),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addObjectMetaLabels(tg.Labels, eps.getObjectMeta(), RoleEndpointSlice)
|
||||||
|
|
||||||
e.addServiceLabels(eps, tg)
|
e.addServiceLabels(eps, tg)
|
||||||
|
|
||||||
type podEntry struct {
|
type podEntry struct {
|
||||||
|
|
|
@ -17,11 +17,13 @@ import (
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
v1 "k8s.io/api/discovery/v1"
|
v1 "k8s.io/api/discovery/v1"
|
||||||
"k8s.io/api/discovery/v1beta1"
|
"k8s.io/api/discovery/v1beta1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// endpointSliceAdaptor is an adaptor for the different EndpointSlice versions
|
// endpointSliceAdaptor is an adaptor for the different EndpointSlice versions
|
||||||
type endpointSliceAdaptor interface {
|
type endpointSliceAdaptor interface {
|
||||||
get() interface{}
|
get() interface{}
|
||||||
|
getObjectMeta() metav1.ObjectMeta
|
||||||
name() string
|
name() string
|
||||||
namespace() string
|
namespace() string
|
||||||
addressType() string
|
addressType() string
|
||||||
|
@ -66,6 +68,10 @@ func (e *endpointSliceAdaptorV1) get() interface{} {
|
||||||
return e.endpointSlice
|
return e.endpointSlice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *endpointSliceAdaptorV1) getObjectMeta() metav1.ObjectMeta {
|
||||||
|
return e.endpointSlice.ObjectMeta
|
||||||
|
}
|
||||||
|
|
||||||
func (e *endpointSliceAdaptorV1) name() string {
|
func (e *endpointSliceAdaptorV1) name() string {
|
||||||
return e.endpointSlice.ObjectMeta.Name
|
return e.endpointSlice.ObjectMeta.Name
|
||||||
}
|
}
|
||||||
|
@ -115,6 +121,10 @@ func (e *endpointSliceAdaptorV1Beta1) get() interface{} {
|
||||||
return e.endpointSlice
|
return e.endpointSlice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *endpointSliceAdaptorV1Beta1) getObjectMeta() metav1.ObjectMeta {
|
||||||
|
return e.endpointSlice.ObjectMeta
|
||||||
|
}
|
||||||
|
|
||||||
func (e *endpointSliceAdaptorV1Beta1) name() string {
|
func (e *endpointSliceAdaptorV1Beta1) name() string {
|
||||||
return e.endpointSlice.Name
|
return e.endpointSlice.Name
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,6 +222,8 @@ func TestEndpointSliceDiscoveryBeforeRun(t *testing.T) {
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_namespace": "default",
|
"__meta_kubernetes_namespace": "default",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
},
|
},
|
||||||
Source: "endpointslice/default/testendpoints",
|
Source: "endpointslice/default/testendpoints",
|
||||||
},
|
},
|
||||||
|
@ -283,6 +285,8 @@ func TestEndpointSliceDiscoveryBeforeRunV1beta1(t *testing.T) {
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_namespace": "default",
|
"__meta_kubernetes_namespace": "default",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
},
|
},
|
||||||
Source: "endpointslice/default/testendpoints",
|
Source: "endpointslice/default/testendpoints",
|
||||||
},
|
},
|
||||||
|
@ -480,6 +484,8 @@ func TestEndpointSliceDiscoveryDelete(t *testing.T) {
|
||||||
Labels: map[model.LabelName]model.LabelValue{
|
Labels: map[model.LabelName]model.LabelValue{
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
"__meta_kubernetes_namespace": "default",
|
"__meta_kubernetes_namespace": "default",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -576,6 +582,8 @@ func TestEndpointSliceDiscoveryUpdate(t *testing.T) {
|
||||||
Labels: model.LabelSet{
|
Labels: model.LabelSet{
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
"__meta_kubernetes_namespace": "default",
|
"__meta_kubernetes_namespace": "default",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -661,6 +669,8 @@ func TestEndpointSliceDiscoveryEmptyEndpoints(t *testing.T) {
|
||||||
Labels: model.LabelSet{
|
Labels: model.LabelSet{
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
"__meta_kubernetes_namespace": "default",
|
"__meta_kubernetes_namespace": "default",
|
||||||
},
|
},
|
||||||
Source: "endpointslice/default/testendpoints",
|
Source: "endpointslice/default/testendpoints",
|
||||||
|
@ -741,6 +751,8 @@ func TestEndpointSliceDiscoveryWithService(t *testing.T) {
|
||||||
Labels: model.LabelSet{
|
Labels: model.LabelSet{
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
"__meta_kubernetes_namespace": "default",
|
"__meta_kubernetes_namespace": "default",
|
||||||
"__meta_kubernetes_service_label_app_name": "test",
|
"__meta_kubernetes_service_label_app_name": "test",
|
||||||
"__meta_kubernetes_service_labelpresent_app_name": "true",
|
"__meta_kubernetes_service_labelpresent_app_name": "true",
|
||||||
|
@ -837,6 +849,8 @@ func TestEndpointSliceDiscoveryWithServiceUpdate(t *testing.T) {
|
||||||
Labels: model.LabelSet{
|
Labels: model.LabelSet{
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
"__meta_kubernetes_namespace": "default",
|
"__meta_kubernetes_namespace": "default",
|
||||||
"__meta_kubernetes_service_label_app_name": "svc",
|
"__meta_kubernetes_service_label_app_name": "svc",
|
||||||
"__meta_kubernetes_service_label_component": "testing",
|
"__meta_kubernetes_service_label_component": "testing",
|
||||||
|
@ -929,6 +943,8 @@ func TestEndpointsSlicesDiscoveryWithNodeMetadata(t *testing.T) {
|
||||||
Labels: model.LabelSet{
|
Labels: model.LabelSet{
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
"__meta_kubernetes_namespace": "default",
|
"__meta_kubernetes_namespace": "default",
|
||||||
"__meta_kubernetes_service_label_app_name": "test",
|
"__meta_kubernetes_service_label_app_name": "test",
|
||||||
"__meta_kubernetes_service_labelpresent_app_name": "true",
|
"__meta_kubernetes_service_labelpresent_app_name": "true",
|
||||||
|
@ -1025,6 +1041,8 @@ func TestEndpointsSlicesDiscoveryWithUpdatedNodeMetadata(t *testing.T) {
|
||||||
Labels: model.LabelSet{
|
Labels: model.LabelSet{
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
"__meta_kubernetes_namespace": "default",
|
"__meta_kubernetes_namespace": "default",
|
||||||
"__meta_kubernetes_service_label_app_name": "test",
|
"__meta_kubernetes_service_label_app_name": "test",
|
||||||
"__meta_kubernetes_service_labelpresent_app_name": "true",
|
"__meta_kubernetes_service_labelpresent_app_name": "true",
|
||||||
|
@ -1161,6 +1179,8 @@ func TestEndpointSliceDiscoveryNamespaces(t *testing.T) {
|
||||||
Labels: model.LabelSet{
|
Labels: model.LabelSet{
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
"__meta_kubernetes_namespace": "ns1",
|
"__meta_kubernetes_namespace": "ns1",
|
||||||
"__meta_kubernetes_service_label_app": "app1",
|
"__meta_kubernetes_service_label_app": "app1",
|
||||||
"__meta_kubernetes_service_labelpresent_app": "true",
|
"__meta_kubernetes_service_labelpresent_app": "true",
|
||||||
|
@ -1306,6 +1326,8 @@ func TestEndpointSliceDiscoveryOwnNamespace(t *testing.T) {
|
||||||
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
"__meta_kubernetes_endpointslice_address_type": "IPv4",
|
||||||
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
"__meta_kubernetes_endpointslice_name": "testendpoints",
|
||||||
"__meta_kubernetes_namespace": "own-ns",
|
"__meta_kubernetes_namespace": "own-ns",
|
||||||
|
"__meta_kubernetes_endpointslice_label_kubernetes_io_service_name": "testendpoints",
|
||||||
|
"__meta_kubernetes_endpointslice_labelpresent_kubernetes_io_service_name": "true",
|
||||||
},
|
},
|
||||||
Source: "endpointslice/own-ns/testendpoints",
|
Source: "endpointslice/own-ns/testendpoints",
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/discovery/targetgroup"
|
"github.com/prometheus/prometheus/discovery/targetgroup"
|
||||||
"github.com/prometheus/prometheus/util/strutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -143,11 +142,6 @@ func ingressSourceFromNamespaceAndName(namespace, name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ingressNameLabel = metaLabelPrefix + "ingress_name"
|
|
||||||
ingressLabelPrefix = metaLabelPrefix + "ingress_label_"
|
|
||||||
ingressLabelPresentPrefix = metaLabelPrefix + "ingress_labelpresent_"
|
|
||||||
ingressAnnotationPrefix = metaLabelPrefix + "ingress_annotation_"
|
|
||||||
ingressAnnotationPresentPrefix = metaLabelPrefix + "ingress_annotationpresent_"
|
|
||||||
ingressSchemeLabel = metaLabelPrefix + "ingress_scheme"
|
ingressSchemeLabel = metaLabelPrefix + "ingress_scheme"
|
||||||
ingressHostLabel = metaLabelPrefix + "ingress_host"
|
ingressHostLabel = metaLabelPrefix + "ingress_host"
|
||||||
ingressPathLabel = metaLabelPrefix + "ingress_path"
|
ingressPathLabel = metaLabelPrefix + "ingress_path"
|
||||||
|
@ -156,24 +150,14 @@ const (
|
||||||
|
|
||||||
func ingressLabels(ingress ingressAdaptor) model.LabelSet {
|
func ingressLabels(ingress ingressAdaptor) model.LabelSet {
|
||||||
// Each label and annotation will create two key-value pairs in the map.
|
// Each label and annotation will create two key-value pairs in the map.
|
||||||
ls := make(model.LabelSet, 2*(len(ingress.labels())+len(ingress.annotations()))+2)
|
ls := make(model.LabelSet)
|
||||||
ls[ingressNameLabel] = lv(ingress.name())
|
|
||||||
ls[namespaceLabel] = lv(ingress.namespace())
|
ls[namespaceLabel] = lv(ingress.namespace())
|
||||||
if cls := ingress.ingressClassName(); cls != nil {
|
if cls := ingress.ingressClassName(); cls != nil {
|
||||||
ls[ingressClassNameLabel] = lv(*cls)
|
ls[ingressClassNameLabel] = lv(*cls)
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range ingress.labels() {
|
addObjectMetaLabels(ls, ingress.getObjectMeta(), RoleIngress)
|
||||||
ln := strutil.SanitizeLabelName(k)
|
|
||||||
ls[model.LabelName(ingressLabelPrefix+ln)] = lv(v)
|
|
||||||
ls[model.LabelName(ingressLabelPresentPrefix+ln)] = presentValue
|
|
||||||
}
|
|
||||||
|
|
||||||
for k, v := range ingress.annotations() {
|
|
||||||
ln := strutil.SanitizeLabelName(k)
|
|
||||||
ls[model.LabelName(ingressAnnotationPrefix+ln)] = lv(v)
|
|
||||||
ls[model.LabelName(ingressAnnotationPresentPrefix+ln)] = presentValue
|
|
||||||
}
|
|
||||||
return ls
|
return ls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,12 @@ package kubernetes
|
||||||
import (
|
import (
|
||||||
v1 "k8s.io/api/networking/v1"
|
v1 "k8s.io/api/networking/v1"
|
||||||
"k8s.io/api/networking/v1beta1"
|
"k8s.io/api/networking/v1beta1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ingressAdaptor is an adaptor for the different Ingress versions
|
// ingressAdaptor is an adaptor for the different Ingress versions
|
||||||
type ingressAdaptor interface {
|
type ingressAdaptor interface {
|
||||||
|
getObjectMeta() metav1.ObjectMeta
|
||||||
name() string
|
name() string
|
||||||
namespace() string
|
namespace() string
|
||||||
labels() map[string]string
|
labels() map[string]string
|
||||||
|
@ -43,6 +45,7 @@ func newIngressAdaptorFromV1(ingress *v1.Ingress) ingressAdaptor {
|
||||||
return &ingressAdaptorV1{ingress: ingress}
|
return &ingressAdaptorV1{ingress: ingress}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *ingressAdaptorV1) getObjectMeta() metav1.ObjectMeta { return i.ingress.ObjectMeta }
|
||||||
func (i *ingressAdaptorV1) name() string { return i.ingress.Name }
|
func (i *ingressAdaptorV1) name() string { return i.ingress.Name }
|
||||||
func (i *ingressAdaptorV1) namespace() string { return i.ingress.Namespace }
|
func (i *ingressAdaptorV1) namespace() string { return i.ingress.Namespace }
|
||||||
func (i *ingressAdaptorV1) labels() map[string]string { return i.ingress.Labels }
|
func (i *ingressAdaptorV1) labels() map[string]string { return i.ingress.Labels }
|
||||||
|
@ -95,7 +98,7 @@ type ingressAdaptorV1Beta1 struct {
|
||||||
func newIngressAdaptorFromV1beta1(ingress *v1beta1.Ingress) ingressAdaptor {
|
func newIngressAdaptorFromV1beta1(ingress *v1beta1.Ingress) ingressAdaptor {
|
||||||
return &ingressAdaptorV1Beta1{ingress: ingress}
|
return &ingressAdaptorV1Beta1{ingress: ingress}
|
||||||
}
|
}
|
||||||
|
func (i *ingressAdaptorV1Beta1) getObjectMeta() metav1.ObjectMeta { return i.ingress.ObjectMeta }
|
||||||
func (i *ingressAdaptorV1Beta1) name() string { return i.ingress.Name }
|
func (i *ingressAdaptorV1Beta1) name() string { return i.ingress.Name }
|
||||||
func (i *ingressAdaptorV1Beta1) namespace() string { return i.ingress.Namespace }
|
func (i *ingressAdaptorV1Beta1) namespace() string { return i.ingress.Namespace }
|
||||||
func (i *ingressAdaptorV1Beta1) labels() map[string]string { return i.ingress.Labels }
|
func (i *ingressAdaptorV1Beta1) labels() map[string]string { return i.ingress.Labels }
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/prometheus/prometheus/util/strutil"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -843,3 +844,19 @@ func checkDiscoveryV1Supported(client kubernetes.Interface) (bool, error) {
|
||||||
// https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25
|
// https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-25
|
||||||
return semVer.Major() >= 1 && semVer.Minor() >= 21, nil
|
return semVer.Major() >= 1 && semVer.Minor() >= 21, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addObjectMetaLabels(labelSet model.LabelSet, objectMeta metav1.ObjectMeta, role Role) {
|
||||||
|
labelSet[model.LabelName(metaLabelPrefix+string(role)+"_name")] = lv(objectMeta.Name)
|
||||||
|
|
||||||
|
for k, v := range objectMeta.Labels {
|
||||||
|
ln := strutil.SanitizeLabelName(k)
|
||||||
|
labelSet[model.LabelName(metaLabelPrefix+string(role)+"_label_"+ln)] = lv(v)
|
||||||
|
labelSet[model.LabelName(metaLabelPrefix+string(role)+"_labelpresent_"+ln)] = presentValue
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range objectMeta.Annotations {
|
||||||
|
ln := strutil.SanitizeLabelName(k)
|
||||||
|
labelSet[model.LabelName(metaLabelPrefix+string(role)+"_annotation_"+ln)] = lv(v)
|
||||||
|
labelSet[model.LabelName(metaLabelPrefix+string(role)+"_annotationpresent_"+ln)] = presentValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -152,33 +152,18 @@ func nodeSourceFromName(name string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
nodeNameLabel = metaLabelPrefix + "node_name"
|
|
||||||
nodeProviderIDLabel = metaLabelPrefix + "node_provider_id"
|
nodeProviderIDLabel = metaLabelPrefix + "node_provider_id"
|
||||||
nodeLabelPrefix = metaLabelPrefix + "node_label_"
|
|
||||||
nodeLabelPresentPrefix = metaLabelPrefix + "node_labelpresent_"
|
|
||||||
nodeAnnotationPrefix = metaLabelPrefix + "node_annotation_"
|
|
||||||
nodeAnnotationPresentPrefix = metaLabelPrefix + "node_annotationpresent_"
|
|
||||||
nodeAddressPrefix = metaLabelPrefix + "node_address_"
|
nodeAddressPrefix = metaLabelPrefix + "node_address_"
|
||||||
)
|
)
|
||||||
|
|
||||||
func nodeLabels(n *apiv1.Node) model.LabelSet {
|
func nodeLabels(n *apiv1.Node) model.LabelSet {
|
||||||
// Each label and annotation will create two key-value pairs in the map.
|
// Each label and annotation will create two key-value pairs in the map.
|
||||||
ls := make(model.LabelSet, 2*(len(n.Labels)+len(n.Annotations))+1)
|
ls := make(model.LabelSet)
|
||||||
|
|
||||||
ls[nodeNameLabel] = lv(n.Name)
|
|
||||||
ls[nodeProviderIDLabel] = lv(n.Spec.ProviderID)
|
ls[nodeProviderIDLabel] = lv(n.Spec.ProviderID)
|
||||||
|
|
||||||
for k, v := range n.Labels {
|
addObjectMetaLabels(ls, n.ObjectMeta, RoleNode)
|
||||||
ln := strutil.SanitizeLabelName(k)
|
|
||||||
ls[model.LabelName(nodeLabelPrefix+ln)] = lv(v)
|
|
||||||
ls[model.LabelName(nodeLabelPresentPrefix+ln)] = presentValue
|
|
||||||
}
|
|
||||||
|
|
||||||
for k, v := range n.Annotations {
|
|
||||||
ln := strutil.SanitizeLabelName(k)
|
|
||||||
ls[model.LabelName(nodeAnnotationPrefix+ln)] = lv(v)
|
|
||||||
ls[model.LabelName(nodeAnnotationPresentPrefix+ln)] = presentValue
|
|
||||||
}
|
|
||||||
return ls
|
return ls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ import (
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/discovery/targetgroup"
|
"github.com/prometheus/prometheus/discovery/targetgroup"
|
||||||
"github.com/prometheus/prometheus/util/strutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const nodeIndex = "node"
|
const nodeIndex = "node"
|
||||||
|
@ -180,7 +179,6 @@ func convertToPod(o interface{}) (*apiv1.Pod, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
podNameLabel = metaLabelPrefix + "pod_name"
|
|
||||||
podIPLabel = metaLabelPrefix + "pod_ip"
|
podIPLabel = metaLabelPrefix + "pod_ip"
|
||||||
podContainerNameLabel = metaLabelPrefix + "pod_container_name"
|
podContainerNameLabel = metaLabelPrefix + "pod_container_name"
|
||||||
podContainerIDLabel = metaLabelPrefix + "pod_container_id"
|
podContainerIDLabel = metaLabelPrefix + "pod_container_id"
|
||||||
|
@ -191,10 +189,6 @@ const (
|
||||||
podContainerIsInit = metaLabelPrefix + "pod_container_init"
|
podContainerIsInit = metaLabelPrefix + "pod_container_init"
|
||||||
podReadyLabel = metaLabelPrefix + "pod_ready"
|
podReadyLabel = metaLabelPrefix + "pod_ready"
|
||||||
podPhaseLabel = metaLabelPrefix + "pod_phase"
|
podPhaseLabel = metaLabelPrefix + "pod_phase"
|
||||||
podLabelPrefix = metaLabelPrefix + "pod_label_"
|
|
||||||
podLabelPresentPrefix = metaLabelPrefix + "pod_labelpresent_"
|
|
||||||
podAnnotationPrefix = metaLabelPrefix + "pod_annotation_"
|
|
||||||
podAnnotationPresentPrefix = metaLabelPrefix + "pod_annotationpresent_"
|
|
||||||
podNodeNameLabel = metaLabelPrefix + "pod_node_name"
|
podNodeNameLabel = metaLabelPrefix + "pod_node_name"
|
||||||
podHostIPLabel = metaLabelPrefix + "pod_host_ip"
|
podHostIPLabel = metaLabelPrefix + "pod_host_ip"
|
||||||
podUID = metaLabelPrefix + "pod_uid"
|
podUID = metaLabelPrefix + "pod_uid"
|
||||||
|
@ -215,7 +209,6 @@ func GetControllerOf(controllee metav1.Object) *metav1.OwnerReference {
|
||||||
|
|
||||||
func podLabels(pod *apiv1.Pod) model.LabelSet {
|
func podLabels(pod *apiv1.Pod) model.LabelSet {
|
||||||
ls := model.LabelSet{
|
ls := model.LabelSet{
|
||||||
podNameLabel: lv(pod.ObjectMeta.Name),
|
|
||||||
podIPLabel: lv(pod.Status.PodIP),
|
podIPLabel: lv(pod.Status.PodIP),
|
||||||
podReadyLabel: podReady(pod),
|
podReadyLabel: podReady(pod),
|
||||||
podPhaseLabel: lv(string(pod.Status.Phase)),
|
podPhaseLabel: lv(string(pod.Status.Phase)),
|
||||||
|
@ -224,6 +217,8 @@ func podLabels(pod *apiv1.Pod) model.LabelSet {
|
||||||
podUID: lv(string(pod.ObjectMeta.UID)),
|
podUID: lv(string(pod.ObjectMeta.UID)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addObjectMetaLabels(ls, pod.ObjectMeta, RolePod)
|
||||||
|
|
||||||
createdBy := GetControllerOf(pod)
|
createdBy := GetControllerOf(pod)
|
||||||
if createdBy != nil {
|
if createdBy != nil {
|
||||||
if createdBy.Kind != "" {
|
if createdBy.Kind != "" {
|
||||||
|
@ -234,18 +229,6 @@ func podLabels(pod *apiv1.Pod) model.LabelSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range pod.Labels {
|
|
||||||
ln := strutil.SanitizeLabelName(k)
|
|
||||||
ls[model.LabelName(podLabelPrefix+ln)] = lv(v)
|
|
||||||
ls[model.LabelName(podLabelPresentPrefix+ln)] = presentValue
|
|
||||||
}
|
|
||||||
|
|
||||||
for k, v := range pod.Annotations {
|
|
||||||
ln := strutil.SanitizeLabelName(k)
|
|
||||||
ls[model.LabelName(podAnnotationPrefix+ln)] = lv(v)
|
|
||||||
ls[model.LabelName(podAnnotationPresentPrefix+ln)] = presentValue
|
|
||||||
}
|
|
||||||
|
|
||||||
return ls
|
return ls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/discovery/targetgroup"
|
"github.com/prometheus/prometheus/discovery/targetgroup"
|
||||||
"github.com/prometheus/prometheus/util/strutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -162,23 +161,10 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func serviceLabels(svc *apiv1.Service) model.LabelSet {
|
func serviceLabels(svc *apiv1.Service) model.LabelSet {
|
||||||
// Each label and annotation will create two key-value pairs in the map.
|
ls := make(model.LabelSet)
|
||||||
ls := make(model.LabelSet, 2*(len(svc.Labels)+len(svc.Annotations))+2)
|
|
||||||
|
|
||||||
ls[serviceNameLabel] = lv(svc.Name)
|
|
||||||
ls[namespaceLabel] = lv(svc.Namespace)
|
ls[namespaceLabel] = lv(svc.Namespace)
|
||||||
|
addObjectMetaLabels(ls, svc.ObjectMeta, RoleService)
|
||||||
|
|
||||||
for k, v := range svc.Labels {
|
|
||||||
ln := strutil.SanitizeLabelName(k)
|
|
||||||
ls[model.LabelName(serviceLabelPrefix+ln)] = lv(v)
|
|
||||||
ls[model.LabelName(serviceLabelPresentPrefix+ln)] = presentValue
|
|
||||||
}
|
|
||||||
|
|
||||||
for k, v := range svc.Annotations {
|
|
||||||
ln := strutil.SanitizeLabelName(k)
|
|
||||||
ls[model.LabelName(serviceAnnotationPrefix+ln)] = lv(v)
|
|
||||||
ls[model.LabelName(serviceAnnotationPresentPrefix+ln)] = presentValue
|
|
||||||
}
|
|
||||||
return ls
|
return ls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue