in main.go [87:169]
func main() {
var configFile string
flag.StringVar(&configFile, "config", "",
"The controller will load its initial configuration from this file. "+
"Omit this flag to use the default configuration values. ")
var featureGates string
flag.StringVar(&featureGates, "feature-gates", "", "A set of key=value pairs that describe feature gates for alpha/experimental features.")
opts := zap.Options{
TimeEncoder: zapcore.RFC3339NanoTimeEncoder,
ZapOpts: []zaplog.Option{zaplog.AddCaller()},
}
opts.BindFlags(flag.CommandLine)
flag.Parse()
if err := utilfeature.DefaultMutableFeatureGate.Set(featureGates); err != nil {
setupLog.Error(err, "Unable to set flag gates for known features")
os.Exit(1)
}
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
setupLog.Info("Initializing", "gitVersion", version.GitVersion, "gitCommit", version.GitCommit)
options, cfg, err := apply(configFile)
if err != nil {
setupLog.Error(err, "Unable to load the configuration")
os.Exit(1)
}
metrics.Register()
kubeConfig := ctrl.GetConfigOrDie()
if kubeConfig.UserAgent == "" {
kubeConfig.UserAgent = useragent.Default()
}
kubeConfig.QPS = *cfg.ClientConnection.QPS
kubeConfig.Burst = int(*cfg.ClientConnection.Burst)
setupLog.V(2).Info("K8S Client", "qps", kubeConfig.QPS, "burst", kubeConfig.Burst)
mgr, err := ctrl.NewManager(kubeConfig, options)
if err != nil {
setupLog.Error(err, "Unable to start manager")
os.Exit(1)
}
certsReady := make(chan struct{})
if cfg.InternalCertManagement != nil && *cfg.InternalCertManagement.Enable {
if err = cert.ManageCerts(mgr, cfg, certsReady); err != nil {
setupLog.Error(err, "Unable to set up cert rotation")
os.Exit(1)
}
} else {
close(certsReady)
}
cCache := cache.New(mgr.GetClient(), cache.WithPodsReadyTracking(blockForPodsReady(&cfg)))
queues := queue.NewManager(mgr.GetClient(), cCache)
ctx := ctrl.SetupSignalHandler()
setupIndexes(ctx, mgr, &cfg)
setupProbeEndpoints(mgr)
// Cert won't be ready until manager starts, so start a goroutine here which
// will block until the cert is ready before setting up the controllers.
// Controllers who register after manager starts will start directly.
go setupControllers(mgr, cCache, queues, certsReady, &cfg)
go func() {
queues.CleanUpOnContext(ctx)
}()
go func() {
cCache.CleanUpOnContext(ctx)
}()
setupScheduler(mgr, cCache, queues, &cfg)
setupLog.Info("Starting manager")
if err := mgr.Start(ctx); err != nil {
setupLog.Error(err, "Could not run manager")
os.Exit(1)
}
}