37 Star 396 Fork 71

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
namespace_template_reset.go 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
Alena Prokharchyk 提交于 2018-06-26 16:21 . Project level resource quota
package resourcequota
import (
"fmt"
"github.com/rancher/types/apis/core/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
corev1 "k8s.io/api/core/v1"
clientcache "k8s.io/client-go/tools/cache"
)
/*
templateResetController is responsible for resetting resource quota template from the namespace
when project resource quota gets reset
*/
type templateResetController struct {
namespaces v1.NamespaceInterface
nsIndexer clientcache.Indexer
}
func (c *templateResetController) resetTemplate(key string, project *v3.Project) error {
if project == nil || project.DeletionTimestamp != nil {
return nil
}
if project.Spec.ResourceQuota != nil {
return nil
}
projectID := fmt.Sprintf("%s:%s", project.Namespace, project.Name)
namespaces, err := c.nsIndexer.ByIndex(nsByProjectIndex, projectID)
if err != nil {
return err
}
for _, n := range namespaces {
ns := n.(*corev1.Namespace)
templateID := getTemplateID(ns)
if templateID == "" {
continue
}
toUpdate := ns.DeepCopy()
delete(toUpdate.Annotations, resourceQuotaTemplateIDAnnotation)
delete(toUpdate.Annotations, resourceQuotaAppliedTemplateIDAnnotation)
if _, err := c.namespaces.Update(toUpdate); err != nil {
return err
}
}
return nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.14-rc2

搜索帮助

344bd9b3 5694891 D2dac590 5694891