Compare commits

...

4 Commits

Author SHA1 Message Date
Augusto Ribeiro
88515f8d55
Merge 042eb6c579 into 4a94cb9dae 2026-04-01 19:27:57 +02:00
Kenny Root
4a94cb9dae
fix(metrics): announce sidecar injection capability (#776)
Some checks failed
release-please / release-please (push) Failing after 5s
The operator was not announcing the TYPE_INSTANCE_SIDECAR_INJECTION
capability so the CNPG operator did not consider the plugin enabled
for instance pods. The instance manager never queried the plugin's
metrics endpoint, and the barman_cloud_cloudnative_pg_io_* metrics
were missing entirely.

This bug was masked when isWALArchiver was set to true in the plugin
configuration, because the backward compatibility code in CNPG would
mark the plugin as enabled as a side-effect. Users with isWALArchiver
set to false (or omitted) never saw the new metrics.

Closes #682 

Signed-off-by: Kenny Root <kenny@the-b.org>
2026-03-31 15:36:09 +02:00
Augusto Ribeiro
042eb6c579
Merge branch 'cloudnative-pg:main' into watchworkspace 2026-02-02 14:58:54 +01:00
augusto.ribeiro
5d514f481f adding a watch-namespace option in order to only watch one namespace if set
Signed-off-by: augusto.ribeiro <augusto.ribeiro@cloudkitchens.com>
Signed-off-by: augustoribeiro <augusto.mcc@gmail.com>
2026-02-02 14:57:43 +01:00
3 changed files with 24 additions and 0 deletions

View File

@ -103,5 +103,12 @@ func NewCmd() *cobra.Command {
_ = viper.BindEnv("sidecar-image", "SIDECAR_IMAGE") _ = viper.BindEnv("sidecar-image", "SIDECAR_IMAGE")
cmd.Flags().String(
"watch-namespace",
"",
"The namespace to watch for CloudNativePG clusters. If empty, all namespaces will be watched.",
)
_ = viper.BindPFlag("watch-namespace", cmd.Flags().Lookup("watch-namespace"))
return cmd return cmd
} }

View File

@ -62,6 +62,13 @@ func (i IdentityImplementation) GetPluginCapabilities(
}, },
}, },
}, },
{
Type: &identity.PluginCapability_Service_{
Service: &identity.PluginCapability_Service{
Type: identity.PluginCapability_Service_TYPE_INSTANCE_SIDECAR_INJECTION,
},
},
},
}, },
}, nil }, nil
} }

View File

@ -31,6 +31,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme" clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime" ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/metrics/filters" "sigs.k8s.io/controller-runtime/pkg/metrics/filters"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
@ -102,6 +103,14 @@ func Start(ctx context.Context) error {
metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
} }
var cacheOptions cache.Options
if viper.GetString("watch-namespace") != "" {
setupLog.Info("Watching a single namespace", "namespace", viper.GetString("watch-namespace"))
cacheOptions = cache.Options{
DefaultNamespaces: map[string]cache.Config{viper.GetString("watch-namespace"): {}},
}
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme, Scheme: scheme,
Metrics: metricsServerOptions, Metrics: metricsServerOptions,
@ -120,6 +129,7 @@ func Start(ctx context.Context) error {
// if you are doing or is intended to do any operation such as perform cleanups // if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe. // after the manager stops then its usage might be unsafe.
LeaderElectionReleaseOnCancel: true, LeaderElectionReleaseOnCancel: true,
Cache: cacheOptions,
}) })
if err != nil { if err != nil {
setupLog.Error(err, "unable to start manager") setupLog.Error(err, "unable to start manager")