代码拉取完成,页面将自动刷新
package resourcequota
import (
"github.com/rancher/types/apis/core/v1"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
/*
cleanupController watches resource quota resource and cleans up those not created by Rancher
if the resource belongs to a project with resourceQuota set
*/
type cleanupController struct {
projectLister v3.ProjectLister
namespaceLister v1.NamespaceLister
resourceQuotas v1.ResourceQuotaInterface
resourceQuotaLister v1.ResourceQuotaLister
}
func (c *cleanupController) cleanup(key string, quota *corev1.ResourceQuota) error {
if quota == nil || quota.DeletionTimestamp != nil {
return nil
}
cleanup, err := c.needToCleanup(quota)
if err != nil || !cleanup {
return err
}
return c.cleanupResourcequota(key, quota)
}
func (c *cleanupController) needToCleanup(quota *corev1.ResourceQuota) (bool, error) {
if quota.Labels != nil {
if _, ok := quota.Labels[resourceQuotaLabel]; ok {
return false, nil
}
}
ns, err := c.namespaceLister.Get("", quota.Namespace)
if err != nil {
return false, err
}
projectLimit, _, err := getProjectResourceQuotaLimit(ns, c.projectLister)
if err != nil {
return false, err
}
return projectLimit != nil, nil
}
func (c *cleanupController) cleanupResourcequota(key string, quota *corev1.ResourceQuota) error {
logrus.Infof("Deleting resource quota [%s] created natively", key)
return c.resourceQuotas.DeleteNamespaced(quota.Namespace, quota.Name, &metav1.DeleteOptions{})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。