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

ctrl:rule: Add ability to configure with PrometheusRule CRDs #167

Merged
merged 8 commits into from
Dec 8, 2024

Conversation

saswatamcode
Copy link
Member

@saswatamcode saswatamcode commented Nov 14, 2024

This PR adds the ability to detect PrometheusRule CRD and generate configmaps to mount to Thanos Ruler pods via ThanosRuler CRD.

PrometheusRule objects will take priority over ConfigMaps.

For now, rules are limited by size restriction of ConfigMaps (will address in future PR): A ConfigMap is not designed to hold large chunks of data. The data stored in a ConfigMap cannot exceed 1 MiB.

Signed-off-by: Saswata Mukherjee <[email protected]>
Signed-off-by: Saswata Mukherjee <[email protected]>
Signed-off-by: Saswata Mukherjee <[email protected]>
@saswatamcode saswatamcode marked this pull request as ready for review December 5, 2024 10:11
@philipgough
Copy link
Collaborator

This looks good overall. I wonder should we add it to the feature gates though? Even if we want to enable it by default that would be fine, what do you think?

The main issue I have is that we have introduced a client for a GVK that may not be present in the cluster. See https://github.com/thanos-community/thanos-operator/blob/main/cmd/main.go#L87 where we have added that feature as opt-out, perhaps we could even lump the prom operator apis under a single flag?

@saswatamcode
Copy link
Member Author

That's a good point, let me try single flag approach

flag.BoolVar(&featureGatePrometheusOperator, "feature-gate.enable-service-monitors", true,
"If set, the operator will manage ServiceMonitors for Prometheus Operator")
flag.BoolVar(&featureGatePrometheusOperator, "feature-gate.enable-prometheus-operator-crds", true,
"If set, the operator will manage ServiceMonitors for components it deploys, and discover PrometheusRule objects to set on Thanos Ruler, from Prometheus Operator.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is good for now, but probably want to move the more detailed description of behaviour into docs at some point and we can keep this brief!

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a section!

// Once detected, these rules are made into configmaps and added to the Ruler.
// +kubebuilder:default:={matchLabels:{"operator.thanos.io/prometheus-rule": "true"}}
// +kubebuilder:validation:Required
PrometheusRuleSelector metav1.LabelSelector `json:"prometheusRuleSelector,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

somethings here seem conflicting

  1. If not specified, no PrometheusRules will be loaded.
  2. +kubebuilder:validation:Required

I think it should be made optional and turned into a pointer?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right that line shouldn't be there.
The behavior for this, is that will always look for prometheusrule objects and is set to our label by default
But you can customize this label (which is something we would need, as it might be hard for users to update all their existing prometheusrule objects with a specific label.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a rule to validate minimum of one label

"github.com/thanos-community/thanos-operator/test/utils"

monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a -local flag to goimport to prevent this. Hopefully this can be done automatically now :)

@philipgough
Copy link
Collaborator

@saswatamcode looking good generally, just some small comments/nits

@saswatamcode
Copy link
Member Author

@philipgough I'm going to merge this as CI is green, comments are addressed and I would like to build a few things on top of this. But feel free to add more comments, will address in future PR!

@saswatamcode saswatamcode merged commit 365d84a into thanos-community:main Dec 8, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants