in pkg/controller/controller.go [88:154]
func NewManagerForRestConfig(conf *config.Config, rc *rest.Config) (ctrl.Manager, error) {
// client creates ListWatch cache for all resources that are
// GET or LISTed. this uses too much memory on large clusters.
var clientOpts *client.CacheOptions
cacheOpts := cache.Options{}
if conf.DisableExpensiveCache {
clientOpts = &client.CacheOptions{
// we only interact with a small subset of pods
// but there's no good filter to only cache the pods we care about
// so we disable caching them for now.
DisableFor: []client.Object{&corev1.Pod{}},
}
cacheOpts.ByObject = map[client.Object]cache.ByObject{
&corev1.Event{}: {
Field: keyvault.EventMirrorSelector,
},
}
}
m, err := ctrl.NewManager(rc, ctrl.Options{
Metrics: metricsserver.Options{BindAddress: conf.MetricsAddr},
HealthProbeBindAddress: conf.ProbeAddr,
Scheme: scheme,
// we use an active-passive HA model meaning only the leader performs actions
LeaderElection: true,
LeaderElectionNamespace: "kube-system",
LeaderElectionID: "aks-app-routing-operator-leader",
Client: client.Options{Cache: clientOpts},
Cache: cacheOpts,
})
if err != nil {
return nil, fmt.Errorf("creating manager: %w", err)
}
setupLog := m.GetLogger().WithName("setup")
if err := setupProbes(conf, m, setupLog); err != nil {
setupLog.Error(err, "failed to set up probes")
return nil, fmt.Errorf("setting up probes: %w", err)
}
// create non-caching clients, non-caching for use before manager has started
cl, err := client.New(rc, client.Options{Scheme: scheme})
if err != nil {
setupLog.Error(err, "unable to create non-caching client")
return nil, fmt.Errorf("creating non-caching client: %w", err)
}
if err := loadCRDs(cl, conf, setupLog); err != nil {
setupLog.Error(err, "failed to load CRDs")
return nil, fmt.Errorf("loading CRDs: %w", err)
}
if err := setupIndexers(m, setupLog, conf); err != nil {
setupLog.Error(err, "unable to setup indexers")
return nil, fmt.Errorf("setting up indexers: %w", err)
}
if err := setupControllers(m, conf, setupLog, cl); err != nil {
setupLog.Error(err, "unable to setup controllers")
return nil, fmt.Errorf("setting up controllers: %w", err)
}
return m, nil
}