37 Star 407 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
register.go 2.95 KB
一键复制 编辑 原始数据 按行查看 历史
dax 提交于 2019-05-06 09:14 . Fix default admin stuck in removing
package clusterauthtoken
import (
"context"
"fmt"
"github.com/rancher/rancher/pkg/controllers/user/clusterauthtoken/common"
managementv3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
"k8s.io/client-go/tools/cache"
)
const tokenByUserAndClusterIndex = "auth.management.cattle.io/token-by-user-and-cluster"
func Register(ctx context.Context, cluster *config.UserContext) {
tokenInformer := cluster.Management.Management.Tokens("").Controller().Informer()
tokenIndexers := map[string]cache.IndexFunc{
tokenByUserAndClusterIndex: tokenByUserAndCluster,
}
if err := tokenInformer.AddIndexers(tokenIndexers); err != nil {
logrus.Error(err)
return
}
namespace := common.DefaultNamespace
clusterName := cluster.ClusterName
clusterAuthToken := cluster.Cluster.ClusterAuthTokens(namespace)
clusterAuthTokenLister := cluster.Cluster.ClusterAuthTokens(namespace).Controller().Lister()
clusterUserAttribute := cluster.Cluster.ClusterUserAttributes(namespace)
clusterUserAttributeLister := cluster.Cluster.ClusterUserAttributes(namespace).Controller().Lister()
clusterConfigMap := cluster.Core.ConfigMaps(namespace)
clusterConfigMapLister := cluster.Core.ConfigMaps(namespace).Controller().Lister()
tokenIndexer := tokenInformer.GetIndexer()
userLister := cluster.Management.Management.Users("").Controller().Lister()
userAttribute := cluster.Management.Management.UserAttributes("")
userAttributeLister := cluster.Management.Management.UserAttributes("").Controller().Lister()
settingInterface := cluster.Management.Management.Settings("")
cluster.Management.Management.Settings("").AddHandler(ctx, "cat-setting-controller", (&settingHandler{
namespace,
clusterConfigMap,
clusterConfigMapLister,
settingInterface,
}).Sync)
cluster.Management.Management.Tokens("").AddClusterScopedLifecycle(ctx,
"cat-token-controller",
clusterName,
&tokenHandler{
namespace,
clusterAuthToken,
clusterAuthTokenLister,
clusterUserAttribute,
clusterUserAttributeLister,
tokenIndexer,
userLister,
userAttributeLister,
})
cluster.Management.Management.Users("").AddHandler(ctx, "cat-user-controller", (&userHandler{
namespace,
clusterUserAttribute,
clusterUserAttributeLister,
}).Sync)
cluster.Management.Management.UserAttributes("").AddHandler(ctx, "cat-user-attribute-controller", (&userAttributeHandler{
namespace,
clusterUserAttribute,
clusterUserAttributeLister,
}).Sync)
cluster.Cluster.ClusterUserAttributes(namespace).AddHandler(ctx, "cat-cluster-user-attribute-controller", (&clusterUserAttributeHandler{
userAttribute,
userAttributeLister,
}).Sync)
}
func tokenUserClusterKey(token *managementv3.Token) string {
return fmt.Sprintf("%s/%s", token.UserID, token.ClusterName)
}
func tokenByUserAndCluster(obj interface{}) ([]string, error) {
t, ok := obj.(*managementv3.Token)
if !ok {
return []string{}, nil
}
return []string{tokenUserClusterKey(t)}, nil
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.5

搜索帮助