Skip to content

Commit d35b1f4

Browse files
committed
draft experimental launch
Signed-off-by: jose.vazquez <[email protected]>
1 parent 9430b0b commit d35b1f4

File tree

7 files changed

+787
-23
lines changed

7 files changed

+787
-23
lines changed

internal/cmd/main.go

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Copyright 2025 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"context"
19+
"log"
20+
"os"
21+
"os/exec"
22+
"os/signal"
23+
"syscall"
24+
)
25+
26+
func main() {
27+
// setupLog := ctrl.Log.WithName("experimental-launcher")
28+
29+
// Graceful shutdown context
30+
ctx, cancel := context.WithCancel(context.Background())
31+
defer cancel()
32+
33+
// Start experimental controllers
34+
// go func() {
35+
// setupLog.Info("Starting experimental controllers")
36+
// mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
37+
// Scheme: runtime.Scheme,
38+
// })
39+
// if err != nil {
40+
// setupLog.Error(err, "unable to start manager for experimental controllers")
41+
// cancel()
42+
// os.Exit(1)
43+
// }
44+
45+
// // Register experimental controllers
46+
// if err := (&experimental.ExperimentalController{}).SetupWithManager(mgr); err != nil {
47+
// setupLog.Error(err, "unable to setup experimental controller")
48+
// cancel()
49+
// os.Exit(1)
50+
// }
51+
52+
// // Start the experimental manager
53+
// if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
54+
// setupLog.Error(err, "problem running experimental manager")
55+
// cancel()
56+
// os.Exit(1)
57+
// }
58+
// }()
59+
60+
// Launch production binary as a subprocess
61+
cmd := exec.Command("./my-operator-production-binary") // Path to your production binary
62+
cmd.Stdout = os.Stdout
63+
cmd.Stderr = os.Stderr
64+
65+
// Start the subprocess
66+
if err := cmd.Start(); err != nil {
67+
log.Fatalf("Failed to start production binary: %v", err)
68+
cancel()
69+
os.Exit(1)
70+
}
71+
72+
log.Println("Experimental launcher is running. Production binary started.")
73+
74+
// Handle OS signals for graceful shutdown
75+
signalCh := make(chan os.Signal, 1)
76+
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
77+
78+
select {
79+
case <-signalCh: // If the launcher gets terminated
80+
log.Println("Received termination signal. Stopping everything...")
81+
82+
// Stop the experimental controllers by calling cancel()
83+
cancel()
84+
85+
// Kill the production subprocess
86+
if err := cmd.Process.Signal(syscall.SIGTERM); err != nil {
87+
log.Printf("Failed to terminate production subprocess: %v", err)
88+
}
89+
90+
case <-ctx.Done(): // If the experimental controllers fail
91+
log.Println("Experimental controllers stopped. Terminating...")
92+
if err := cmd.Process.Kill(); err != nil {
93+
log.Printf("Failed to force-kill production subprocess: %v", err)
94+
}
95+
}
96+
97+
// Wait for subprocess to fully shut down
98+
_ = cmd.Wait()
99+
100+
log.Println("Experimental launcher shut down completely.")
101+
}
102+
103+
// func startExperimentalControllers(setupLog logr.Logger, cancel context.CancelCauseFunc) error {
104+
// setupLog.Info("Starting experimental controllers")
105+
// mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
106+
// Scheme: ctrl.Scheme,
107+
// })
108+
// if err != nil {
109+
// return fmt.Errorf("failed to start experimentar controller manager: %w", err)
110+
// }
111+
112+
// // TODO Register experimental controllers
113+
// if err := (&experimental.ExperimentalController{}).SetupWithManager(mgr); err != nil {
114+
// return fmt.Errorf("failed to setup experimental controller: %w", err)
115+
// }
116+
117+
// go func() {
118+
// if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
119+
// setupLog.Error(err, "problem running experimental manager")
120+
// cancel()
121+
// os.Exit(1)
122+
// }
123+
// }()
124+
// return nil
125+
// }

internal/controller/atlasthirdpartyintegrations/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (h *AtlasThirdPartyIntegrationHandler) HandleCreated(ctx context.Context, i
8484

8585
func (h *AtlasThirdPartyIntegrationHandler) handleIdle(ctx context.Context, integration *akov2next.AtlasThirdPartyIntegration) (ctrlstate.Result, error) {
8686
// TODO skew detection here
87-
87+
8888
return ctrlstate.Result{}, nil
8989
}
9090

0 commit comments

Comments
 (0)