1
0
mirror of https://github.com/coreos/prometheus-operator.git synced 2026-02-05 06:45:27 +01:00

38 Commits

Author SHA1 Message Date
dongjiang
fcc78c7e07 change sort to slices package
Signed-off-by: dongjiang <dongjiang1989@126.com>
2025-11-04 16:28:38 +08:00
Hélia Barroso
cacffa596c feat: Apply modernize analyzer to the codebase (#7854)
Signed-off-by: Hélia Barroso <helia_barroso@hotmail.com>
2025-09-01 11:33:41 +02:00
M Viswanath Sai
baf40889d1 Chore: rename internal/util package to sortutil (#7719)
* rename internal/util -> internal/sortutil
2025-07-22 14:40:33 +05:30
Jayapriya Pai
7476f376f1 chore: update logger with slog's discard handler
Signed-off-by: Jayapriya Pai <slashpai9@gmail.com>
2025-05-19 11:06:13 +05:30
Simon Pasquier
34b82db925 chore: update k8s dependencies to v0.33.0
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2025-05-14 13:42:53 +02:00
dongjiang
5a8daae34b chore: Upgrade golangci-lint to v2 and golangci-lint-action to v7.0.0 (#7430)
---------

Signed-off-by: dongjiang <dongjiang1989@126.com>
Co-authored-by: Simon Pasquier <spasquie@redhat.com>
2025-03-31 09:51:44 +02:00
dongjiang
d1fb419659 chore: optimize maps order function (#7001)
---------

Signed-off-by: dongjiang1989 <dongjiang1989@126.com>
2024-10-11 17:31:54 +02:00
perebaj
a40ef97244 replace goKitLogger in controller and namespace denylist 2024-08-29 17:33:39 -03:00
Jonathan
0cf01e5485 replace goKitLogger in operators (#6881)
* replace goKitLogger in operators

* remove goKitLogger from alertmanager operator

* remove goKitLogger from main
2024-08-28 09:49:42 +02:00
Simon Pasquier
365809896c chore: simplify controller constructors
This change introduces functional options for all 4 controllers
(previously only Prometheus used them).

It also reduces code duplication regarding API version checks.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2024-07-25 09:33:42 +02:00
Ashwin Sriram
cbf0f66c68 Replacing t.fatal with require Package (#6680)
chore: Replace t.Fatal with require package
2024-06-17 17:51:47 -03:00
Arthur Silva Sens
164cb034ec Ensure all comments end with a period (#6208)
* Ensure all comments end with a period.

By enabling the godot linter

Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>

* Fix godot issues

Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>

---------

Signed-off-by: Arthur Silva Sens <arthur.sens@coralogix.com>
2024-01-08 12:07:39 -03:00
Simon Pasquier
7f06be09f1 fix: detect changes without list/watch perms on namespaces
This change implements a poll-based namespace lister/watcher when the
operator's service account isn't granted the list & watch permissions on
all namespaces. Instead of sending a watch request, the controller will
get every configured namespace every 15 seconds and sends the expected
watch events when a namespace is added/updated/deleted.

It still requires the service account to be granted the get permission
on the configured namespaces.

Closes #3847

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2023-09-21 11:23:17 +02:00
Simon Pasquier
e274af7fbc fix: reconcile on namespace changes
When the operator was configured to select only a limited number of
namespaces, it would not watch for namespace changes. It means that the
operator may not reconcile when a namespace label is added/removed
(affecting which objects should be selected or not).

This change enables the operator to use a privileged namespace
lister/watcher whenever the service account has the needed permissions.

**IMPORTANT:** it also requires Kubernetes >= 1.22 to be effective but
the operator will degrade to the suboptimal implementation without watch
if this condition isn't met.

Closes #3847

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2023-09-21 09:18:59 +02:00
Simon Pasquier
3e6870ef5f chore: simplify NewUnprivilegedNamespaceListWatchFromClient()
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2023-09-05 17:00:06 +02:00
Simon Pasquier
12580d663a chore: fix imports order
The commit also enables the gci linter in the golangci-lint
configuration.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2023-06-15 10:03:42 +02:00
Simon Pasquier
91bf2091c7 chore: update golangci-lint to v1.53.1 (#5633)
* chore: update golangci-lint to v1.53.1

* chore: resolve new linter errors

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2023-06-06 14:47:01 +02:00
Simon Pasquier
f1fed965bb *: switch to github.com/go-kit/log
Using github.com/go-kit/log instead of github.com/go-kit/kit reduces the
list of things this project depends on. This commit also removes the
wrapper for k8s.io/klog because none of the k8s libraries depend on it
anymore.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2021-07-22 16:22:28 +02:00
paulfantom
650d35136a *: run gofmt
Signed-off-by: paulfantom <pawel@krupa.net.pl>
2021-06-09 20:56:17 +02:00
Arghya Sadhu
b5e6053b3e refactor to remove context.TODO 2020-10-26 14:17:02 +05:30
Simon Pasquier
434f9f7e0b Don't block when namespace aren't found (#3545)
* pkg/listwatch: don't block when namespaces aren't found

The namespaces listerwatcher shouldn't return an error when some of the
monitored namespaces don't exist. Otherwise the operator will block
while waiting for the informers to sync their cache and it will never
be able to reconcile resources.

Closes #3347

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Refactor waitForCacheSync() functions

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Add `prometheus_operator_ready` metric

Also add the `PrometheusOperatorNotReady` alert that fires when a
controller hasn't initialized after 5 minutes.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* example/mixin: regenerate

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2020-10-01 13:51:03 +02:00
Sergiusz Urbaniak
34ba8237f5 pkg/informers: fix stylistic nits
Co-authored-by: Simon Pasquier <spasquie@redhat.com>
2020-09-04 17:08:33 +02:00
Sergiusz Urbaniak
5e94344182 pkg/listwatch: remove multilistwatcher 2020-09-04 17:08:33 +02:00
Sergiusz Urbaniak
27c1680975 pkg/*: renamings and reformatting 2020-09-04 17:08:33 +02:00
Sergiusz Urbaniak
f22fd2c7c0 pkg/listwach: remove denylist ListerWatcher 2020-09-04 16:58:51 +02:00
Lili Cosic
8f49757672 pkg/listwatch: Change to accept single instance of rvs 2020-07-29 11:46:06 +02:00
Michal Fojtik
7bbd81692a listwatch: do not duplicate resource versions 2020-07-29 11:45:59 +02:00
Simon Pasquier
8d2152cd25 *: create separate namespace informers if needed
Service/pod monitors and rules resources watched by the operator
can live in different namespaces than the configmaps and secrets
associated to the Prometheus custom resources.

Before this change, we had only one namespace informer scoped to the
monitor/rule namespaces. Whenever a change of configmap or secret was
detected, the operator couldn't retrieve the associated namespace
because it didn't exist in the monitor/rule namespaces and the
reconciliation wouldn't happen. The same issue applies for Thanos Ruler
and rules.

With this change, separate namespace informers are used when the
monitors/rules and prometheus namespaces aren't identical.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2020-04-29 14:24:49 +02:00
Joe Lanford
bfbb40ae56 *: update kubernetes deps to v1.18.2
This commit bumps the kubernetes version dependencies from v1.17
to v1.18.

The kubernetes client-go library introduced breaking
changes in v1.18 by adding context.Context to many of its function
signatures. The kubernetes-sigs/clientgofix tools was used in this
commit to automatically add the necessary context.TODO() arguments
to all client-go usage in the repo.

Fixes #3146
2020-04-21 08:53:31 -04:00
Paul Gier
e182cad921 cmd/operator: use maps for namespaces config
Instead of converting between a map and slice (and back to map again
in some cases), just use a map throughout.
2020-04-05 13:43:28 -05:00
Lucas Servén Marín
43f9a122c0 Merge pull request #2723 from squat/denynamespaces
pkg/listwatch: ensure namespace objects are denied
2019-08-20 16:17:35 +02:00
Lucas Servén Marín
fcba318169 pkg/listwatch: ensure namespace objects are denied
The original implementation of the denylist-listwatch does not properly
filter out namespace objects as they are not namespaced. Nevertheless,
the denylist-listwatch is applied to the multi-namespace listwatch. This
means that changes to blacklisted namespaces would be handled by
unsuspecting informers.

This commit ensures that namespaces are correctly filtered.
2019-08-20 15:17:56 +02:00
Lucas Servén Marín
56ca4a7e33 pkg/listwatch: fix listwatch wrapping regression
Whenever a multi-listwatch contains only one listwatch, it
should simply use the underlying listwatch without any wrapper. This
improves performance and eliminates unnecessary go routines. This commit
fixes a regression where a denylist-listwatch would wrap underlying
listwatches even if the denylist was empty.
2019-08-20 14:24:04 +02:00
Sergiusz Urbaniak
b42a28407b *: support namespace denylists
Currently, it is possible to explicitly watch for namespaces with the --namespaces option.
If unset, all namespaces are being watched.

The reverse is not possible today, namely exclude (deny) namespaces from being watched.
This fixes it by introducing the --deny-namespaces option.
It is mutually exclusive with --namespaces.
2019-08-16 15:59:07 +02:00
Sergiusz Urbaniak
47cd71761d pkg/listwatch: fix racy multiwatch
Currently, listwatch is racy, as revealed by the following error, when
running in k8s:

```
W1128 16:49:11.288643       1 reflector.go:270] github.com/coreos/prometheus-operator/pkg/prometheus/operator.go:403: watch of *v1.ConfigMap ended with: too old resource version: 14464 (19288)
panic: send on closed channel

goroutine 1373 [running]:
github.com/coreos/prometheus-operator/pkg/listwatch.newMultiWatch.func1(0x17f1c00, 0xc00084cab0, 0xc0002bbce0)
    /home/sur/go/src/github.com/coreos/prometheus-operator/pkg/listwatch/listwatch.go:181 +0x4f
created by github.com/coreos/prometheus-operator/pkg/listwatch.newMultiWatch
    /home/sur/go/src/github.com/coreos/prometheus-operator/pkg/listwatch/listwatch.go:175 +0x298
```

This fixes it by ensuring that the event sender channel is closed,
once all sender dispatcher goroutines exited.

This also fixes a small concurrency issue in the tests and adds the
`-race` parameter to unit tests in the Makefile.
2018-11-29 18:09:56 +01:00
Lucas Serven
6bf7e05796 pkg/listwatch: add unit tests for multiWatch 2018-08-22 17:46:28 +02:00
Lucas Serven
d1af613243 pkg: wrap comments at 80 char 2018-08-22 13:44:27 +02:00
Lucas Serven
86c358e26d pkg: add multi-namespace support
This commit adds multi-namespace support to the Prometheus Operator. PO
now allows all informers to react to changes to multiple, individually
configured, namespaces, i.e. without specifying v1.NamespaceAll. This is
important for cases where the Prometheus Operator does not have
privileges to List all namespaces but should still administer multiple
namespaces. This capability is accomplished by abstracting the
cache.ListerWatchers for the various informers the PO uses.
2018-08-22 11:41:39 +02:00