From dfc3a01ecd4941e0ddecdc852d0f1f058f8d44d6 Mon Sep 17 00:00:00 2001
From: Pavol Loffay
Date: Thu, 5 Dec 2024 16:15:47 +0100
Subject: [PATCH] Fix certificate issue at startup upgrade
Signed-off-by: Pavol Loffay
---
main.go | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/main.go b/main.go
index 7c82ce103d..6dd901735e 100644
--- a/main.go
+++ b/main.go
@@ -524,15 +524,16 @@ func main() {
func addDependencies(_ context.Context, mgr ctrl.Manager, cfg config.Config, v version.Version) error {
// adds the upgrade mechanism to be executed once the manager is ready
- err := mgr.Add(manager.RunnableFunc(func(c context.Context) error {
- up := &collectorupgrade.VersionUpgrade{
- Log: ctrl.Log.WithName("collector-upgrade"),
- Version: v,
- Client: mgr.GetClient(),
- Recorder: mgr.GetEventRecorderFor("opentelemetry-operator"),
- }
- return up.ManagedInstances(c)
- }))
+ up := &collectorupgrade.VersionUpgrade{
+ Log: ctrl.Log.WithName("collector-upgrade"),
+ Version: v,
+ Client: mgr.GetClient(),
+ Recorder: mgr.GetEventRecorderFor("opentelemetry-operator"),
+ }
+ err := mgr.Add(leaderElectionRunnable{
+ up: up,
+ })
+
if err != nil {
return fmt.Errorf("failed to upgrade OpenTelemetryCollector instances: %w", err)
}
@@ -599,3 +600,17 @@ func parseFipsFlag(fipsFlag string) ([]string, []string, []string, []string) {
}
return receivers, exporters, processors, extensions
}
+
+var _ manager.LeaderElectionRunnable = (*leaderElectionRunnable)(nil)
+
+type leaderElectionRunnable struct {
+ up *collectorupgrade.VersionUpgrade
+}
+
+func (l leaderElectionRunnable) Start(ctx context.Context) error {
+ return l.up.ManagedInstances(ctx)
+}
+
+func (l leaderElectionRunnable) NeedLeaderElection() bool {
+ return true
+}