37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
legacy_prtb_cleaner.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
Craig Jellick 提交于 2019-01-29 10:15 . Remove legacy role bindings
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
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.16-rc1

搜索帮助

0d507c66 1850385 C8b1a773 1850385