代码拉取完成,页面将自动刷新
package resourcequota
import (
"reflect"
"fmt"
namespaceutil "github.com/rancher/rancher/pkg/namespace"
validate "github.com/rancher/rancher/pkg/resourcequota"
"github.com/rancher/types/apis/management.cattle.io/v3"
corev1 "k8s.io/api/core/v1"
clientcache "k8s.io/client-go/tools/cache"
api "k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/quota"
)
/*
collectController is responsible for calculate the combined limit set on the project's Namespaces,
and setting this information in the project
*/
type calculateLimitController struct {
projectLister v3.ProjectLister
projects v3.ProjectInterface
nsIndexer clientcache.Indexer
clusterName string
}
func (c *calculateLimitController) calculateResourceQuotaUsed(key string, ns *corev1.Namespace) error {
if ns == nil {
return nil
}
projectID := getProjectID(ns)
if projectID == "" {
return nil
}
return c.calculateProjectResourceQuota(projectID)
}
func (c *calculateLimitController) calculateResourceQuotaUsedProject(key string, p *v3.Project) error {
if p == nil || p.DeletionTimestamp != nil {
return nil
}
return c.calculateProjectResourceQuota(fmt.Sprintf("%s:%s", c.clusterName, p.Name))
}
func (c *calculateLimitController) calculateProjectResourceQuota(projectID string) error {
projectNamespace, projectName := getProjectNamespaceName(projectID)
project, err := c.projectLister.Get(projectNamespace, projectName)
if err != nil || project.Spec.ResourceQuota == nil {
return err
}
namespaces, err := c.nsIndexer.ByIndex(nsByProjectIndex, projectID)
if err != nil {
return err
}
nssResourceList := api.ResourceList{}
for _, n := range namespaces {
ns := n.(*corev1.Namespace)
if ns.DeletionTimestamp != nil {
continue
}
set, err := namespaceutil.IsNamespaceConditionSet(ns, resourceQuotaValidatedCondition, true)
if err != nil {
return err
}
if !set {
continue
}
nsLimit, err := getNamespaceLimit(ns)
if err != nil {
return err
}
nsResourceList, err := validate.ConvertLimitToResourceList(nsLimit)
if err != nil {
return err
}
nssResourceList = quota.Add(nssResourceList, nsResourceList)
}
limit, err := convertResourceListToLimit(nssResourceList)
if err != nil {
return err
}
if reflect.DeepEqual(project.Spec.ResourceQuota.UsedLimit, limit) {
return nil
}
toUpdate := project.DeepCopy()
toUpdate.Spec.ResourceQuota.UsedLimit = *limit
_, err = c.projects.Update(toUpdate)
return err
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。