37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
register.go 2.52 KB
一键复制 编辑 原始数据 按行查看 历史
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 := &quotaResetController{
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.4-rc9

搜索帮助