37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
template.go 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-06-12 09:11 . Run goimports on all of rancher
package podsecuritypolicy
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/cache"
)
const psptpbByPSPTNameIndex = "something.something.psptpb/pspt-name"
func Register(ctx context.Context, management *config.ManagementContext) {
psptpbInformer := management.Management.PodSecurityPolicyTemplateProjectBindings("").Controller().Informer()
psptpbIndexers := map[string]cache.IndexFunc{
psptpbByPSPTNameIndex: PSPTPBByPSPTName,
}
psptpbInformer.AddIndexers(psptpbIndexers)
lifecycle := &lifecycle{
psptpbs: management.Management.PodSecurityPolicyTemplateProjectBindings(""),
psptpbLister: management.Management.PodSecurityPolicyTemplateProjectBindings("").Controller().Lister(),
psptpbIndexer: psptpbInformer.GetIndexer(),
}
management.Management.PodSecurityPolicyTemplates("").AddLifecycle(ctx, "mgmt-pspt-lfc-handler", lifecycle)
}
type lifecycle struct {
psptpbs v3.PodSecurityPolicyTemplateProjectBindingInterface
psptpbLister v3.PodSecurityPolicyTemplateProjectBindingLister
psptpbIndexer cache.Indexer
}
func (l *lifecycle) Create(obj *v3.PodSecurityPolicyTemplate) (runtime.Object, error) {
return obj, nil
}
func (l *lifecycle) Updated(obj *v3.PodSecurityPolicyTemplate) (runtime.Object, error) {
return obj, nil
}
func (l *lifecycle) Remove(obj *v3.PodSecurityPolicyTemplate) (runtime.Object, error) {
psptpbs, err := l.psptpbIndexer.ByIndex(psptpbByPSPTNameIndex, obj.Name)
if err != nil {
return nil, fmt.Errorf("error getting psptpbs: %v", err)
}
for _, rawPSPTPB := range psptpbs {
psptpb := rawPSPTPB.(*v3.PodSecurityPolicyTemplateProjectBinding)
err := l.psptpbs.DeleteNamespaced(psptpb.Namespace, psptpb.Name, &v1.DeleteOptions{})
if err != nil {
return nil, fmt.Errorf("error deleting psptpb: %v", err)
}
}
return obj, nil
}
func PSPTPBByPSPTName(obj interface{}) ([]string, error) {
psptpb, ok := obj.(*v3.PodSecurityPolicyTemplateProjectBinding)
if !ok {
return []string{}, nil
}
return []string{psptpb.PodSecurityPolicyTemplateName}, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.3.0-alpha5

搜索帮助

0d507c66 1850385 C8b1a773 1850385