()
| 177 | } |
| 178 | |
| 179 | func main() { |
| 180 | running, stopRunning := context.WithCancel(context.Background()) |
| 181 | defer stopRunning() |
| 182 | |
| 183 | initVersion() |
| 184 | initLogging() |
| 185 | log := logging.FromContext(running) |
| 186 | log.V(1).Info("debug flag set to true") |
| 187 | |
| 188 | // Start a goroutine that waits for SIGINT or SIGTERM. |
| 189 | { |
| 190 | signals := []os.Signal{os.Interrupt, syscall.SIGTERM} |
| 191 | receive := make(chan os.Signal, len(signals)) |
| 192 | signal.Notify(receive, signals...) |
| 193 | go func() { |
| 194 | // Wait for a signal then immediately restore the default signal handlers. |
| 195 | // After this, a SIGHUP, SIGINT, or SIGTERM causes the program to exit. |
| 196 | // - https://pkg.go.dev/os/signal#hdr-Default_behavior_of_signals_in_Go_programs |
| 197 | s := <-receive |
| 198 | signal.Stop(receive) |
| 199 | |
| 200 | log.Info("received signal from OS", "signal", s.String()) |
| 201 | stopRunning() |
| 202 | }() |
| 203 | } |
| 204 | |
| 205 | features := feature.NewGate() |
| 206 | must(features.Set(os.Getenv("PGO_FEATURE_GATES"))) |
| 207 | |
| 208 | running = feature.NewContext(running, features) |
| 209 | log.Info("feature gates", |
| 210 | // These are set by the user |
| 211 | "PGO_FEATURE_GATES", feature.ShowAssigned(running), |
| 212 | // These are enabled, including features that are on by default |
| 213 | "enabled", feature.ShowEnabled(running)) |
| 214 | |
| 215 | // Initialize OpenTelemetry and flush data when there is a panic. |
| 216 | otelFinish := need(initOpenTelemetry(running)) |
| 217 | defer func(ctx context.Context) { _ = otelFinish(ctx) }(running) |
| 218 | |
| 219 | tracing.SetDefaultTracer(tracing.New("github.com/CrunchyData/postgres-operator")) |
| 220 | |
| 221 | // Load Kubernetes client configuration and ensure it works. |
| 222 | config := need(initClient()) |
| 223 | k8s := need(kubernetes.NewDiscoveryRunner(config)) |
| 224 | must(k8s.Read(running)) |
| 225 | log.Info("connected to Kubernetes", "api", k8s.Version().String(), "openshift", k8s.IsOpenShift()) |
| 226 | |
| 227 | options := need(initManager(running)) |
| 228 | |
| 229 | // Add to the Context that Manager passes to Reconciler.Start, Runnable.Start, |
| 230 | // and eventually Reconciler.Reconcile. |
| 231 | options.BaseContext = func() context.Context { |
| 232 | ctx := context.Background() |
| 233 | ctx = feature.NewContext(ctx, features) |
| 234 | ctx = kubernetes.NewAPIContext(ctx, k8s) |
| 235 | return ctx |
| 236 | } |
nothing calls this directly
no test coverage detected