代码拉取完成,页面将自动刷新
package rbac
import (
"regexp"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var crbNamePattern = regexp.MustCompile("clusterrolebinding-.+")
var namespaceRoleRefPattern = regexp.MustCompile(".+-namespaces-.+")
var promotedRoleRefPattern = regexp.MustCompile(".+-promoted")
const createNSRoleRef = "create-ns"
func newLegacyCRBCleaner(m *manager) *crbCleaner {
return &crbCleaner{
m: m,
}
}
type crbCleaner struct {
m *manager
}
func (p *crbCleaner) sync(key string, obj *rbacv1.ClusterRoleBinding) error {
if key == "" || obj == nil {
return nil
}
eligible, err := p.eligibleForDeletion(obj)
if err != nil {
return err
}
if eligible {
if err := p.m.workload.RBAC.ClusterRoleBindings("").Delete(obj.Name, &metav1.DeleteOptions{}); err != nil {
if !errors.IsNotFound(err) {
return err
}
}
}
return nil
}
func (p *crbCleaner) eligibleForDeletion(crb *rbacv1.ClusterRoleBinding) (bool, error) {
if !crbNamePattern.MatchString(crb.Name) {
return false, nil
}
if noOwners, err := p.m.noRemainingOwnerLabels(crb); !noOwners || err != nil {
return false, err
}
roleRefName := crb.RoleRef.Name
if roleRefName == createNSRoleRef {
return true, nil
}
if namespaceRoleRefPattern.MatchString(roleRefName) {
return true, nil
}
if promotedRoleRefPattern.MatchString(roleRefName) {
return true, nil
}
return false, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。