Skip to content

Commit 1f6bd1e

Browse files
committed
add graceful shutdown
1 parent 3420830 commit 1f6bd1e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

main.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func main() {
112112
crds = crdsToWatch{mongoDBCRDPlural, mongoDBUserCRDPlural, mongoDBOpsManagerCRDPlural, mongoDBCommunityCRDPlural, mongoDBSearchCRDPlural}
113113
}
114114

115-
signelCtx := signals.SetupSignalHandler()
115+
signalCtx := signals.SetupSignalHandler()
116116
operator.OmUpdateChannel = make(chan event.GenericEvent)
117117

118118
klog.InitFlags(nil)
@@ -136,11 +136,11 @@ func main() {
136136
cfg := ctrl.GetConfigOrDie()
137137

138138
log.Infof("Setting up tracing with ID: %s, Parent ID: %s, Endpoint: %s", traceIDHex, spanIDHex, endpoint)
139-
traceCtx, tp, err := telemetry.SetupTracing(signelCtx, traceIDHex, spanIDHex, endpoint)
139+
traceCtx, tp, err := telemetry.SetupTracing(signalCtx, traceIDHex, spanIDHex, endpoint)
140140
if err != nil {
141141
log.Errorf("Failed to setup tracing: %v", err)
142142
// Continue without tracing instead of failing
143-
traceCtx = signelCtx
143+
traceCtx = signalCtx
144144
} else if tp != nil {
145145
defer func(tp *sdktrace.TracerProvider, ctx context.Context) {
146146
log.Info("Shutting down tracer provider to ensure all spans are exported")
@@ -153,15 +153,14 @@ func main() {
153153
} else {
154154
log.Info("Tracer provider successfully shut down")
155155
}
156-
}(tp, signelCtx)
156+
}(tp, signalCtx)
157157
log.Info("OpenTelemetry tracing successfully configured")
158158
} else {
159159
log.Warn("No tracer provider created, tracing will be disabled")
160160
}
161161

162162
log.Infof("Starting spans with trace context: %+v", traceCtx)
163163

164-
// Create the root operator span with improved visibility attributes
165164
opts := []trace.SpanStartOption{
166165
trace.WithAttributes(
167166
attribute.String("component", "operator"),
@@ -374,7 +373,7 @@ func main() {
374373

375374
log.Info("Starting the Cmd.")
376375

377-
if err := mgr.Start(signelCtx); err != nil {
376+
if err := mgr.Start(signalCtx); err != nil {
378377
log.Fatal(err)
379378
}
380379
}

scripts/evergreen/teardown_kubernetes_environment.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ set -Eeou pipefail
44

55
source scripts/dev/set_env_context.sh
66

7+
# Gracefully shutdown the operator to ensure we can verify graceful shutdown
8+
kubectl -n "${NAMESPACE}" scale deployment "mongodb-kubernetes-operator" --replicas=0 || true
9+
sleep 5
10+
711
if [ "${KUBE_ENVIRONMENT_NAME}" = "kind" ]; then
812
echo "Deleting Kind cluster"
913
kind delete clusters --all

0 commit comments

Comments
 (0)