代码拉取完成,页面将自动刷新
package resourcequota
import (
"context"
"github.com/rancher/types/config"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/cache"
)
const (
nsByProjectIndex = "resourcequota.cluster.cattle.io/ns-by-project"
)
func Register(ctx context.Context, cluster *config.UserContext) {
// Index for looking up Namespaces by projectID annotation
nsInformer := cluster.Core.Namespaces("").Controller().Informer()
nsIndexers := map[string]cache.IndexFunc{
nsByProjectIndex: nsByProjectID,
}
nsInformer.AddIndexers(nsIndexers)
sync := &SyncController{
Namespaces: cluster.Core.Namespaces(""),
NamespaceLister: cluster.Core.Namespaces("").Controller().Lister(),
NsIndexer: nsInformer.GetIndexer(),
ResourceQuotas: cluster.Core.ResourceQuotas(""),
ResourceQuotaLister: cluster.Core.ResourceQuotas("").Controller().Lister(),
LimitRange: cluster.Core.LimitRanges(""),
LimitRangeLister: cluster.Core.LimitRanges("").Controller().Lister(),
ProjectLister: cluster.Management.Management.Projects(cluster.ClusterName).Controller().Lister(),
}
cluster.Core.Namespaces("").AddHandler(ctx, "resourceQuotaSyncController", sync.syncResourceQuota)
reconcile := &reconcileController{
namespaces: cluster.Core.Namespaces(""),
nsIndexer: nsInformer.GetIndexer(),
}
cluster.Management.Management.Projects(cluster.ClusterName).AddHandler(ctx, "resourceQuotaNamespacesReconcileController", reconcile.reconcileNamespaces)
calculate := &calculateLimitController{
nsIndexer: nsInformer.GetIndexer(),
projectLister: cluster.Management.Management.Projects(cluster.ClusterName).Controller().Lister(),
projects: cluster.Management.Management.Projects(cluster.ClusterName),
clusterName: cluster.ClusterName,
}
cluster.Core.Namespaces("").AddHandler(ctx, "resourceQuotaUsedLimitController", calculate.calculateResourceQuotaUsed)
cluster.Management.Management.Projects(cluster.ClusterName).AddHandler(ctx, "resourceQuotaProjectUsedLimitController", calculate.calculateResourceQuotaUsedProject)
reset := "aResetController{
nsIndexer: nsInformer.GetIndexer(),
namespaces: cluster.Core.Namespaces(""),
}
cluster.Management.Management.Projects(cluster.ClusterName).AddHandler(ctx, "namespaceResourceQuotaResetController", reset.resetNamespaceQuota)
}
func nsByProjectID(obj interface{}) ([]string, error) {
ns, ok := obj.(*corev1.Namespace)
if !ok {
return []string{}, nil
}
if id, ok := ns.Annotations[projectIDAnnotation]; ok {
return []string{id}, nil
}
return []string{}, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。