mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-20 19:29:10 +00:00
replace ObjectMeta with custom PodMeta type
Recent updates to the CRD generation caused pod labels and annotations to be lost due to no longer recursing into the ObjectMeta type to gather all the fields. This change allows labels and annotations to be preserved in the custom Promtheus, Alertmanager, and ThanosRuler custom resources. Fixes #3041
This commit is contained in:
parent
bff40041b8
commit
9d2d9e7ed0
14 changed files with 141 additions and 39 deletions
Documentation
example/prometheus-operator-crd
monitoring.coreos.com_alertmanagers.yamlmonitoring.coreos.com_prometheuses.yamlmonitoring.coreos.com_thanosrulers.yaml
jsonnet/prometheus-operator
pkg
alertmanager
apis/monitoring/v1
prometheus
thanos
|
@ -21,6 +21,7 @@ This Document documents the types introduced by the Prometheus Operator to be co
|
|||
* [BasicAuth](#basicauth)
|
||||
* [Endpoint](#endpoint)
|
||||
* [NamespaceSelector](#namespaceselector)
|
||||
* [PodMeta](#podmeta)
|
||||
* [PodMetricsEndpoint](#podmetricsendpoint)
|
||||
* [PodMonitor](#podmonitor)
|
||||
* [PodMonitorList](#podmonitorlist)
|
||||
|
@ -123,7 +124,7 @@ AlertmanagerSpec is a specification of the desired behavior of the Alertmanager
|
|||
|
||||
| Field | Description | Scheme | Required |
|
||||
| ----- | ----------- | ------ | -------- |
|
||||
| podMetadata | Standard object’s metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata Metadata Labels and Annotations gets propagated to the prometheus pods. | *[metav1.ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#objectmeta-v1-meta) | false |
|
||||
| podMetadata | PodMetadata configures Labels and Annotations which are propagated to the alertmanager pods. | *[PodMeta](#podmeta) | false |
|
||||
| image | Image if specified has precedence over baseImage, tag and sha combinations. Specifying the version is still necessary to ensure the Prometheus Operator knows what version of Alertmanager is being configured. | *string | false |
|
||||
| version | Version the cluster should be on. | string | false |
|
||||
| tag | Tag of Alertmanager container image to be deployed. Defaults to the value of `version`. Version is ignored if Tag is set. | string | false |
|
||||
|
@ -229,6 +230,17 @@ NamespaceSelector is a selector for selecting either all namespaces or a list of
|
|||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
## PodMeta
|
||||
|
||||
PodMeta is a subset of k8s.io/apimachinery/pkg/apis/meta/v1/ObjectMeta which only includes fields applicable to the generated stateful set pod template of the custom resource types.
|
||||
|
||||
| Field | Description | Scheme | Required |
|
||||
| ----- | ----------- | ------ | -------- |
|
||||
| labels | Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels | map[string]string | false |
|
||||
| annotations | Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. They are not queryable and should be preserved when modifying objects. More info: http://kubernetes.io/docs/user-guide/annotations | map[string]string | false |
|
||||
|
||||
[Back to TOC](#table-of-contents)
|
||||
|
||||
## PodMetricsEndpoint
|
||||
|
||||
PodMetricsEndpoint defines a scrapeable endpoint of a Kubernetes Pod serving Prometheus metrics.
|
||||
|
@ -348,7 +360,7 @@ PrometheusSpec is a specification of the desired behavior of the Prometheus clus
|
|||
|
||||
| Field | Description | Scheme | Required |
|
||||
| ----- | ----------- | ------ | -------- |
|
||||
| podMetadata | Standard object’s metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata Metadata Labels and Annotations gets propagated to the prometheus pods. | *[metav1.ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#objectmeta-v1-meta) | false |
|
||||
| podMetadata | PodMetadata configures Labels and Annotations which are propagated to the prometheus pods. | *[PodMeta](#podmeta) | false |
|
||||
| serviceMonitorSelector | ServiceMonitors to be selected for target discovery. | *[metav1.LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#labelselector-v1-meta) | false |
|
||||
| serviceMonitorNamespaceSelector | Namespaces to be selected for ServiceMonitor discovery. If nil, only check own namespace. | *[metav1.LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#labelselector-v1-meta) | false |
|
||||
| podMonitorSelector | *Experimental* PodMonitors to be selected for target discovery. | *[metav1.LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#labelselector-v1-meta) | false |
|
||||
|
@ -680,7 +692,7 @@ ThanosRulerSpec is a specification of the desired behavior of the ThanosRuler. M
|
|||
|
||||
| Field | Description | Scheme | Required |
|
||||
| ----- | ----------- | ------ | -------- |
|
||||
| podMetadata | Standard object’s metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata Metadata Labels and Annotations gets propagated to the prometheus pods. | *[metav1.ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#objectmeta-v1-meta) | false |
|
||||
| podMetadata | PodMetadata contains Labels and Annotations gets propagated to the thanos ruler pods. | *[PodMeta](#podmeta) | false |
|
||||
| image | Thanos container image URL. | string | false |
|
||||
| imagePullSecrets | An optional list of references to secrets in the same namespace to use for pulling thanos images from registries see http://kubernetes.io/docs/user-guide/images#specifying-imagepullsecrets-on-a-pod | [][v1.LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#localobjectreference-v1-core) | false |
|
||||
| paused | When a ThanosRuler deployment is paused, no actions except for deletion will be performed on the underlying objects. | bool | false |
|
||||
|
|
|
@ -2767,9 +2767,25 @@ spec:
|
|||
are not goint to be performed, except for delete actions.
|
||||
type: boolean
|
||||
podMetadata:
|
||||
description: 'Standard object’s metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
|
||||
Metadata Labels and Annotations gets propagated to the prometheus
|
||||
pods.'
|
||||
description: PodMetadata configures Labels and Annotations which are
|
||||
propagated to the alertmanager pods.
|
||||
properties:
|
||||
annotations:
|
||||
additionalProperties:
|
||||
type: string
|
||||
description: 'Annotations is an unstructured key value map stored
|
||||
with a resource that may be set by external tools to store and
|
||||
retrieve arbitrary metadata. They are not queryable and should
|
||||
be preserved when modifying objects. More info: http://kubernetes.io/docs/user-guide/annotations'
|
||||
type: object
|
||||
labels:
|
||||
additionalProperties:
|
||||
type: string
|
||||
description: 'Map of string keys and values that can be used to
|
||||
organize and categorize (scope and select) objects. May match
|
||||
selectors of replication controllers and services. More info:
|
||||
http://kubernetes.io/docs/user-guide/labels'
|
||||
type: object
|
||||
type: object
|
||||
portName:
|
||||
description: Port name used for the pods and governing service. This
|
||||
|
|
|
@ -3250,9 +3250,25 @@ spec:
|
|||
for deletion will be performed on the underlying objects.
|
||||
type: boolean
|
||||
podMetadata:
|
||||
description: 'Standard object’s metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
|
||||
Metadata Labels and Annotations gets propagated to the prometheus
|
||||
pods.'
|
||||
description: PodMetadata configures Labels and Annotations which are
|
||||
propagated to the prometheus pods.
|
||||
properties:
|
||||
annotations:
|
||||
additionalProperties:
|
||||
type: string
|
||||
description: 'Annotations is an unstructured key value map stored
|
||||
with a resource that may be set by external tools to store and
|
||||
retrieve arbitrary metadata. They are not queryable and should
|
||||
be preserved when modifying objects. More info: http://kubernetes.io/docs/user-guide/annotations'
|
||||
type: object
|
||||
labels:
|
||||
additionalProperties:
|
||||
type: string
|
||||
description: 'Map of string keys and values that can be used to
|
||||
organize and categorize (scope and select) objects. May match
|
||||
selectors of replication controllers and services. More info:
|
||||
http://kubernetes.io/docs/user-guide/labels'
|
||||
type: object
|
||||
type: object
|
||||
podMonitorNamespaceSelector:
|
||||
description: Namespaces to be selected for PodMonitor discovery. If
|
||||
|
|
|
@ -2792,9 +2792,25 @@ spec:
|
|||
for deletion will be performed on the underlying objects.
|
||||
type: boolean
|
||||
podMetadata:
|
||||
description: 'Standard object’s metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
|
||||
Metadata Labels and Annotations gets propagated to the prometheus
|
||||
pods.'
|
||||
description: PodMetadata contains Labels and Annotations gets propagated
|
||||
to the thanos ruler pods.
|
||||
properties:
|
||||
annotations:
|
||||
additionalProperties:
|
||||
type: string
|
||||
description: 'Annotations is an unstructured key value map stored
|
||||
with a resource that may be set by external tools to store and
|
||||
retrieve arbitrary metadata. They are not queryable and should
|
||||
be preserved when modifying objects. More info: http://kubernetes.io/docs/user-guide/annotations'
|
||||
type: object
|
||||
labels:
|
||||
additionalProperties:
|
||||
type: string
|
||||
description: 'Map of string keys and values that can be used to
|
||||
organize and categorize (scope and select) objects. May match
|
||||
selectors of replication controllers and services. More info:
|
||||
http://kubernetes.io/docs/user-guide/labels'
|
||||
type: object
|
||||
type: object
|
||||
portName:
|
||||
description: Port name used for the pods and governing service. This
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -113,7 +113,7 @@ func TestPodLabelsAnnotations(t *testing.T) {
|
|||
sset, err := makeStatefulSet(&monitoringv1.Alertmanager{
|
||||
ObjectMeta: metav1.ObjectMeta{},
|
||||
Spec: monitoringv1.AlertmanagerSpec{
|
||||
PodMetadata: &metav1.ObjectMeta{
|
||||
PodMetadata: &monitoringv1.PodMeta{
|
||||
Annotations: annotations,
|
||||
Labels: labels,
|
||||
},
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -57,10 +57,8 @@ type ThanosRulerList struct {
|
|||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
|
||||
// +k8s:openapi-gen=true
|
||||
type ThanosRulerSpec struct {
|
||||
// Standard object’s metadata. More info:
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
|
||||
// Metadata Labels and Annotations gets propagated to the prometheus pods.
|
||||
PodMetadata *metav1.ObjectMeta `json:"podMetadata,omitempty"`
|
||||
// PodMetadata contains Labels and Annotations gets propagated to the thanos ruler pods.
|
||||
PodMetadata *PodMeta `json:"podMetadata,omitempty"`
|
||||
// Thanos container image URL.
|
||||
Image string `json:"image,omitempty"`
|
||||
// An optional list of references to secrets in the same namespace
|
||||
|
|
|
@ -45,6 +45,25 @@ const (
|
|||
PrometheusRuleKindKey = "prometheusrule"
|
||||
)
|
||||
|
||||
// PodMeta is a subset of k8s.io/apimachinery/pkg/apis/meta/v1/ObjectMeta which only
|
||||
// includes fields applicable to the generated stateful set pod template of the
|
||||
// custom resource types.
|
||||
type PodMeta struct {
|
||||
// Map of string keys and values that can be used to organize and categorize
|
||||
// (scope and select) objects. May match selectors of replication controllers
|
||||
// and services.
|
||||
// More info: http://kubernetes.io/docs/user-guide/labels
|
||||
// +optional
|
||||
Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,11,rep,name=labels"`
|
||||
|
||||
// Annotations is an unstructured key value map stored with a resource that may be
|
||||
// set by external tools to store and retrieve arbitrary metadata. They are not
|
||||
// queryable and should be preserved when modifying objects.
|
||||
// More info: http://kubernetes.io/docs/user-guide/annotations
|
||||
// +optional
|
||||
Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,12,rep,name=annotations"`
|
||||
}
|
||||
|
||||
// Prometheus defines a Prometheus deployment.
|
||||
// +genclient
|
||||
// +k8s:openapi-gen=true
|
||||
|
@ -79,10 +98,8 @@ type PrometheusList struct {
|
|||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
|
||||
// +k8s:openapi-gen=true
|
||||
type PrometheusSpec struct {
|
||||
// Standard object’s metadata. More info:
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
|
||||
// Metadata Labels and Annotations gets propagated to the prometheus pods.
|
||||
PodMetadata *metav1.ObjectMeta `json:"podMetadata,omitempty"`
|
||||
// PodMetadata configures Labels and Annotations which are propagated to the prometheus pods.
|
||||
PodMetadata *PodMeta `json:"podMetadata,omitempty"`
|
||||
// ServiceMonitors to be selected for target discovery.
|
||||
ServiceMonitorSelector *metav1.LabelSelector `json:"serviceMonitorSelector,omitempty"`
|
||||
// Namespaces to be selected for ServiceMonitor discovery. If nil, only
|
||||
|
@ -863,10 +880,8 @@ type Alertmanager struct {
|
|||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
|
||||
// +k8s:openapi-gen=true
|
||||
type AlertmanagerSpec struct {
|
||||
// Standard object’s metadata. More info:
|
||||
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata
|
||||
// Metadata Labels and Annotations gets propagated to the prometheus pods.
|
||||
PodMetadata *metav1.ObjectMeta `json:"podMetadata,omitempty"`
|
||||
// PodMetadata configures Labels and Annotations which are propagated to the alertmanager pods.
|
||||
PodMetadata *PodMeta `json:"podMetadata,omitempty"`
|
||||
// Image if specified has precedence over baseImage, tag and sha
|
||||
// combinations. Specifying the version is still necessary to ensure the
|
||||
// Prometheus Operator knows what version of Alertmanager is being
|
||||
|
|
|
@ -144,7 +144,7 @@ func (in *AlertmanagerSpec) DeepCopyInto(out *AlertmanagerSpec) {
|
|||
*out = *in
|
||||
if in.PodMetadata != nil {
|
||||
in, out := &in.PodMetadata, &out.PodMetadata
|
||||
*out = new(metav1.ObjectMeta)
|
||||
*out = new(PodMeta)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.Image != nil {
|
||||
|
@ -428,6 +428,35 @@ func (in *NamespaceSelector) DeepCopy() *NamespaceSelector {
|
|||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PodMeta) DeepCopyInto(out *PodMeta) {
|
||||
*out = *in
|
||||
if in.Labels != nil {
|
||||
in, out := &in.Labels, &out.Labels
|
||||
*out = make(map[string]string, len(*in))
|
||||
for key, val := range *in {
|
||||
(*out)[key] = val
|
||||
}
|
||||
}
|
||||
if in.Annotations != nil {
|
||||
in, out := &in.Annotations, &out.Annotations
|
||||
*out = make(map[string]string, len(*in))
|
||||
for key, val := range *in {
|
||||
(*out)[key] = val
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMeta.
|
||||
func (in *PodMeta) DeepCopy() *PodMeta {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(PodMeta)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *PodMetricsEndpoint) DeepCopyInto(out *PodMetricsEndpoint) {
|
||||
*out = *in
|
||||
|
@ -694,7 +723,7 @@ func (in *PrometheusSpec) DeepCopyInto(out *PrometheusSpec) {
|
|||
*out = *in
|
||||
if in.PodMetadata != nil {
|
||||
in, out := &in.PodMetadata, &out.PodMetadata
|
||||
*out = new(metav1.ObjectMeta)
|
||||
*out = new(PodMeta)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.ServiceMonitorSelector != nil {
|
||||
|
@ -1359,7 +1388,7 @@ func (in *ThanosRulerSpec) DeepCopyInto(out *ThanosRulerSpec) {
|
|||
*out = *in
|
||||
if in.PodMetadata != nil {
|
||||
in, out := &in.PodMetadata, &out.PodMetadata
|
||||
*out = new(metav1.ObjectMeta)
|
||||
*out = new(PodMeta)
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
if in.ImagePullSecrets != nil {
|
||||
|
|
|
@ -87,7 +87,7 @@ func TestPodLabelsAnnotations(t *testing.T) {
|
|||
sset, err := makeStatefulSet(monitoringv1.Prometheus{
|
||||
ObjectMeta: metav1.ObjectMeta{},
|
||||
Spec: monitoringv1.PrometheusSpec{
|
||||
PodMetadata: &metav1.ObjectMeta{
|
||||
PodMetadata: &monitoringv1.PodMeta{
|
||||
Annotations: annotations,
|
||||
Labels: labels,
|
||||
},
|
||||
|
|
|
@ -89,7 +89,7 @@ func TestPodLabelsAnnotations(t *testing.T) {
|
|||
ObjectMeta: metav1.ObjectMeta{},
|
||||
Spec: monitoringv1.ThanosRulerSpec{
|
||||
QueryEndpoints: emptyQueryEndpoints,
|
||||
PodMetadata: &metav1.ObjectMeta{
|
||||
PodMetadata: &monitoringv1.PodMeta{
|
||||
Annotations: annotations,
|
||||
Labels: labels,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue