const namespaceDeletionGracePeriod … type NamespaceController … // NewNamespaceController creates a new NamespaceController func NewNamespaceController( ctx context.Context, kubeClient clientset.Interface, metadataClient metadata.Interface, discoverResourcesFn func() ([]*metav1.APIResourceList, error), namespaceInformer coreinformers.NamespaceInformer, resyncPeriod time.Duration, finalizerToken v1.FinalizerName) *NamespaceController { … } // nsControllerRateLimiter is tuned for a faster than normal recycle time with default backoff speed and default overall // requeing speed. We do this so that namespace cleanup is reliably faster and we know that the number of namespaces being // deleted is smaller than total number of other namespace scoped resources in a cluster. func nsControllerRateLimiter() workqueue.TypedRateLimiter[string] { … } // enqueueNamespace adds an object to the controller work queue // obj could be an *v1.Namespace, or a DeletionFinalStateUnknown item. func (nm *NamespaceController) enqueueNamespace(obj interface{ … } // worker processes the queue of namespace objects. // Each namespace can be in the queue at most once. // The system ensures that no two workers can process // the same namespace at the same time. func (nm *NamespaceController) worker(ctx context.Context) { … } // syncNamespaceFromKey looks for a namespace with the specified key in its store and synchronizes it func (nm *NamespaceController) syncNamespaceFromKey(ctx context.Context, key string) (err error) { … } // Run starts observing the system with the specified number of workers. func (nm *NamespaceController) Run(ctx context.Context, workers int) { … }