代码拉取完成,页面将自动刷新
package podsecuritypolicy
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
"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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。