Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TargetAllocator): allow configuration of PrometheusCR namespaceSelectors #3573

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .chloggen/feat-add-prometheuscr-namespaceselectors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: 'operator'

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add Prometheus CR namespace selectors"

# One or more tracking issues related to the change
issues:
- 3086

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,15 @@ spec:
serviceAccount: everything-prometheus-operator-needs
prometheusCR:
enabled: true
scrapeInterval: 30s
serviceMonitorSelector: {}
serviceMonitorNamespaceSelector: {}
podMonitorSelector: {}
podMonitorNamespaceSelector: {}
scrapeConfigSelector: {}
scrapeConfigNamespaceSelector: {}
probeSelector: {}
probeNamespaceSelector: {}
config:
receivers:
prometheus:
Expand Down
28 changes: 28 additions & 0 deletions apis/v1beta1/targetallocator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,52 @@ type TargetAllocatorPrometheusCR struct {
// label selector matches no objects.
// +optional
PodMonitorSelector *metav1.LabelSelector `json:"podMonitorSelector,omitempty"`
// Namespaces to be selected to look for PodMonitors for target discovery.
// A label selector is a label query over a set of resources. The result of matchLabels and
// matchExpressions are ANDed. An empty label selector matches all objects. A null
// label selector matches no objects.
// +optional
// +kubebuilder:default:={}
PodMonitorNamespaceSelector *metav1.LabelSelector `json:"podMonitorNamespaceSelector,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should also do some defaulting here to prevent an upgrade from breaking existing installations? As the doc string states, a null selector matches nothing, upgrading with this on will mean that existing installations (who do not set this currently) would not have it, resulting in a null selector, aka 💥

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point 👍 , should we implement that for the PodMonitorNamespaceSelector or for all the selectors (including the already existing ones) ? What do you recommend ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should set the default to the empty selector for all selectors you're adding here. The end result will be that resource selectors target nothing by default, while namespace selectors target everything, which is also what prometheus-operator does.

I'm not sure if you can set these defaults via a kubebuilder marker. If not, then you'll have to do it in the webhook.

Copy link
Contributor Author

@dexter0195 dexter0195 Dec 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @swiatekm , thank you for the heads up for the kubebuilder 😃 I indeed found a way to set a default and I added it to the new fields like so

// +kubebuilder:default:={}

which resulted in a generated crd like this:

...
                      podMonitorNamespaceSelector:
                        default: {}
                        properties:
                          matchExpressions:
...

Let me know if that looks good for you 🙏

// ServiceMonitors to be selected for target discovery.
// A label selector is a label query over a set of resources. The result of matchLabels and
// matchExpressions are ANDed. An empty label selector matches all objects. A null
// label selector matches no objects.
// +optional
ServiceMonitorSelector *metav1.LabelSelector `json:"serviceMonitorSelector,omitempty"`
// Namespaces to be selected to look for ServiceMonitors for target discovery.
// A label selector is a label query over a set of resources. The result of matchLabels and
// matchExpressions are ANDed. An empty label selector matches all objects. A null
// label selector matches no objects.
// +optional
// +kubebuilder:default:={}
ServiceMonitorNamespaceSelector *metav1.LabelSelector `json:"serviceMonitorNamespaceSelector,omitempty"`
// ScrapeConfigs to be selected for target discovery.
// A label selector is a label query over a set of resources. The result of matchLabels and
// matchExpressions are ANDed. An empty label selector matches all objects. A null
// label selector matches no objects.
// +optional
ScrapeConfigSelector *metav1.LabelSelector `json:"scrapeConfigSelector,omitempty"`
// Namespaces to be selected to look for ScrapeConfigs for target discovery.
// A label selector is a label query over a set of resources. The result of matchLabels and
// matchExpressions are ANDed. An empty label selector matches all objects. A null
// label selector matches no objects.
// +optional
// +kubebuilder:default:={}
ScrapeConfigNamespaceSelector *metav1.LabelSelector `json:"scrapeConfigNamespaceSelector,omitempty"`
// Probes to be selected for target discovery.
// A label selector is a label query over a set of resources. The result of matchLabels and
// matchExpressions are ANDed. An empty label selector matches all objects. A null
// label selector matches no objects.
// +optional
ProbeSelector *metav1.LabelSelector `json:"probeSelector,omitempty"`
// Namespaces to be selected to look for Probes for target discovery.
// A label selector is a label query over a set of resources. The result of matchLabels and
// matchExpressions are ANDed. An empty label selector matches all objects. A null
// label selector matches no objects.
// +optional
// +kubebuilder:default:={}
ProbeNamespaceSelector *metav1.LabelSelector `json:"probeNamespaceSelector,omitempty"`
}

type (
Expand Down
20 changes: 20 additions & 0 deletions apis/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-12-19T16:56:26Z"
createdAt: "2024-12-28T16:14:39Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7883,6 +7883,33 @@ spec:
properties:
enabled:
type: boolean
podMonitorNamespaceSelector:
default: {}
properties:
matchExpressions:
items:
properties:
key:
type: string
operator:
type: string
values:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
type: object
type: object
x-kubernetes-map-type: atomic
podMonitorSelector:
properties:
matchExpressions:
Expand All @@ -7909,6 +7936,33 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
probeNamespaceSelector:
default: {}
properties:
matchExpressions:
items:
properties:
key:
type: string
operator:
type: string
values:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
type: object
type: object
x-kubernetes-map-type: atomic
probeSelector:
properties:
matchExpressions:
Expand All @@ -7935,6 +7989,33 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
scrapeConfigNamespaceSelector:
default: {}
properties:
matchExpressions:
items:
properties:
key:
type: string
operator:
type: string
values:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
type: object
type: object
x-kubernetes-map-type: atomic
scrapeConfigSelector:
properties:
matchExpressions:
Expand Down Expand Up @@ -7965,6 +8046,33 @@ spec:
default: 30s
format: duration
type: string
serviceMonitorNamespaceSelector:
default: {}
properties:
matchExpressions:
items:
properties:
key:
type: string
operator:
type: string
values:
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
type: object
type: object
x-kubernetes-map-type: atomic
serviceMonitorSelector:
properties:
matchExpressions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ metadata:
categories: Logging & Tracing,Monitoring
certified: "false"
containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
createdAt: "2024-12-19T16:56:38Z"
createdAt: "2024-12-28T16:14:44Z"
description: Provides the OpenTelemetry components, including the Collector
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down
Loading
Loading