37 Star 405 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
setup.go 29.33 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
package managementstored
import (
"context"
"net/http"
"github.com/rancher/norman/store/crd"
"github.com/rancher/norman/store/proxy"
"github.com/rancher/norman/store/subtype"
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/api/customization/alert"
"github.com/rancher/rancher/pkg/api/customization/app"
"github.com/rancher/rancher/pkg/api/customization/authn"
"github.com/rancher/rancher/pkg/api/customization/catalog"
ccluster "github.com/rancher/rancher/pkg/api/customization/cluster"
"github.com/rancher/rancher/pkg/api/customization/clusterregistrationtokens"
"github.com/rancher/rancher/pkg/api/customization/cred"
"github.com/rancher/rancher/pkg/api/customization/globaldns"
"github.com/rancher/rancher/pkg/api/customization/globalresource"
"github.com/rancher/rancher/pkg/api/customization/kontainerdriver"
"github.com/rancher/rancher/pkg/api/customization/logging"
"github.com/rancher/rancher/pkg/api/customization/monitor"
"github.com/rancher/rancher/pkg/api/customization/multiclusterapp"
"github.com/rancher/rancher/pkg/api/customization/node"
"github.com/rancher/rancher/pkg/api/customization/nodetemplate"
"github.com/rancher/rancher/pkg/api/customization/pipeline"
"github.com/rancher/rancher/pkg/api/customization/podsecuritypolicytemplate"
projectStore "github.com/rancher/rancher/pkg/api/customization/project"
projectaction "github.com/rancher/rancher/pkg/api/customization/project"
"github.com/rancher/rancher/pkg/api/customization/roletemplate"
"github.com/rancher/rancher/pkg/api/customization/roletemplatebinding"
"github.com/rancher/rancher/pkg/api/customization/setting"
appStore "github.com/rancher/rancher/pkg/api/store/app"
"github.com/rancher/rancher/pkg/api/store/cert"
"github.com/rancher/rancher/pkg/api/store/cluster"
globaldnsAPIStore "github.com/rancher/rancher/pkg/api/store/globaldns"
nodeStore "github.com/rancher/rancher/pkg/api/store/node"
nodeTemplateStore "github.com/rancher/rancher/pkg/api/store/nodetemplate"
"github.com/rancher/rancher/pkg/api/store/noopwatching"
passwordStore "github.com/rancher/rancher/pkg/api/store/password"
"github.com/rancher/rancher/pkg/api/store/preference"
"github.com/rancher/rancher/pkg/api/store/scoped"
settingstore "github.com/rancher/rancher/pkg/api/store/setting"
"github.com/rancher/rancher/pkg/api/store/userscope"
"github.com/rancher/rancher/pkg/auth/principals"
"github.com/rancher/rancher/pkg/auth/providerrefresh"
"github.com/rancher/rancher/pkg/auth/providers"
"github.com/rancher/rancher/pkg/clustermanager"
"github.com/rancher/rancher/pkg/controllers/management/compose/common"
"github.com/rancher/rancher/pkg/namespace"
"github.com/rancher/rancher/pkg/nodeconfig"
sourcecodeproviders "github.com/rancher/rancher/pkg/pipeline/providers"
managementschema "github.com/rancher/types/apis/management.cattle.io/v3/schema"
projectschema "github.com/rancher/types/apis/project.cattle.io/v3/schema"
"github.com/rancher/types/client/management/v3"
projectclient "github.com/rancher/types/client/project/v3"
"github.com/rancher/types/config"
)
func Setup(ctx context.Context, apiContext *config.ScaledContext, clusterManager *clustermanager.Manager,
k8sProxy http.Handler, localClusterEnabled bool) error {
// Here we setup all types that will be stored in the Management cluster
schemas := apiContext.Schemas
factory := &crd.Factory{ClientGetter: apiContext.ClientGetter}
factory.BatchCreateCRDs(ctx, config.ManagementStorageContext, schemas, &managementschema.Version,
client.AuthConfigType,
client.CatalogType,
client.CatalogTemplateType,
client.CatalogTemplateVersionType,
client.ClusterAlertType,
client.ClusterAlertGroupType,
client.ClusterCatalogType,
client.ClusterLoggingType,
client.ClusterAlertRuleType,
client.ClusterMonitorGraphType,
client.ClusterRegistrationTokenType,
client.ClusterRoleTemplateBindingType,
client.ClusterType,
client.ComposeConfigType,
client.DynamicSchemaType,
client.EtcdBackupType,
client.GlobalRoleBindingType,
client.GlobalRoleType,
client.GroupMemberType,
client.GroupType,
client.KontainerDriverType,
client.ListenConfigType,
client.MultiClusterAppType,
client.MultiClusterAppRevisionType,
client.MonitorMetricType,
client.NodeDriverType,
client.NodePoolType,
client.NodeTemplateType,
client.NodeType,
client.NotifierType,
client.PodSecurityPolicyTemplateProjectBindingType,
client.PodSecurityPolicyTemplateType,
client.PreferenceType,
client.ProjectAlertType,
client.ProjectAlertGroupType,
client.ProjectCatalogType,
client.ProjectLoggingType,
client.ProjectAlertRuleType,
client.ProjectMonitorGraphType,
client.ProjectNetworkPolicyType,
client.ProjectRoleTemplateBindingType,
client.ProjectType,
client.RoleTemplateType,
client.SettingType,
client.TemplateType,
client.TemplateVersionType,
client.TemplateContentType,
client.TokenType,
client.UserAttributeType,
client.UserType,
client.GlobalDNSType,
client.GlobalDNSProviderType)
factory.BatchCreateCRDs(ctx, config.ManagementStorageContext, schemas, &projectschema.Version,
projectclient.AppType,
projectclient.AppRevisionType,
projectclient.PipelineExecutionType,
projectclient.PipelineSettingType,
projectclient.PipelineType,
projectclient.SourceCodeCredentialType,
projectclient.SourceCodeProviderConfigType,
projectclient.SourceCodeRepositoryType,
)
factory.BatchWait()
Clusters(schemas, apiContext, clusterManager, k8sProxy)
ClusterRoleTemplateBinding(schemas, apiContext)
Templates(ctx, schemas, apiContext)
TemplateVersion(ctx, schemas, apiContext)
User(ctx, schemas, apiContext)
Catalog(schemas, apiContext)
ProjectCatalog(schemas, apiContext)
ClusterCatalog(schemas, apiContext)
SecretTypes(ctx, schemas, apiContext)
App(schemas, apiContext, clusterManager)
Setting(schemas)
Preference(schemas, apiContext)
ClusterRegistrationTokens(schemas)
NodeTemplates(schemas, apiContext)
LoggingTypes(schemas, apiContext, clusterManager, k8sProxy)
Alert(schemas, apiContext)
Pipeline(schemas, apiContext, clusterManager)
Project(schemas, apiContext)
ProjectRoleTemplateBinding(schemas, apiContext)
TemplateContent(schemas)
PodSecurityPolicyTemplate(schemas, apiContext)
RoleTemplate(schemas, apiContext)
MultiClusterApps(schemas, apiContext)
GlobalDNSs(schemas, apiContext, localClusterEnabled)
GlobalDNSProviders(schemas, apiContext, localClusterEnabled)
Monitor(schemas, apiContext, clusterManager)
KontainerDriver(schemas, apiContext)
if err := NodeTypes(schemas, apiContext); err != nil {
return err
}
principals.Schema(ctx, apiContext, schemas)
providers.SetupAuthConfig(ctx, apiContext, schemas)
authn.SetUserStore(schemas.Schema(&managementschema.Version, client.UserType), apiContext)
authn.SetRTBStore(ctx, schemas.Schema(&managementschema.Version, client.ClusterRoleTemplateBindingType), apiContext)
authn.SetRTBStore(ctx, schemas.Schema(&managementschema.Version, client.ProjectRoleTemplateBindingType), apiContext)
nodeStore.SetupStore(schemas.Schema(&managementschema.Version, client.NodeType))
projectStore.SetProjectStore(schemas.Schema(&managementschema.Version, client.ProjectType), apiContext)
setupScopedTypes(schemas)
setupPasswordTypes(ctx, schemas, apiContext)
multiclusterapp.SetMemberStore(ctx, schemas.Schema(&managementschema.Version, client.MultiClusterAppType), apiContext)
return nil
}
func setupPasswordTypes(ctx context.Context, schemas *types.Schemas, management *config.ScaledContext) {
secretStore := management.Core.Secrets("")
nsStore := management.Core.Namespaces("")
passwordStore.SetPasswordStore(schemas, secretStore, nsStore)
}
func setupScopedTypes(schemas *types.Schemas) {
for _, schema := range schemas.Schemas() {
if schema.Scope != types.NamespaceScope || schema.Store == nil || schema.Store.Context() != config.ManagementStorageContext {
continue
}
for _, key := range []string{"projectId", "clusterId"} {
ns, ok := schema.ResourceFields["namespaceId"]
if !ok {
continue
}
if _, ok := schema.ResourceFields[key]; !ok {
continue
}
schema.Store = scoped.NewScopedStore(key, schema.Store)
ns.Required = false
schema.ResourceFields["namespaceId"] = ns
break
}
}
}
func Clusters(schemas *types.Schemas, managementContext *config.ScaledContext, clusterManager *clustermanager.Manager, k8sProxy http.Handler) {
handler := ccluster.ActionHandler{
NodepoolGetter: managementContext.Management,
ClusterClient: managementContext.Management.Clusters(""),
UserMgr: managementContext.UserManager,
ClusterManager: clusterManager,
NodeTemplateGetter: managementContext.Management,
BackupClient: managementContext.Management.EtcdBackups(""),
}
schema := schemas.Schema(&managementschema.Version, client.ClusterType)
clusterFormatter := ccluster.Formatter{
KontainerDriverLister: managementContext.Management.KontainerDrivers("").Controller().Lister(),
}
schema.Formatter = clusterFormatter.Formatter
schema.ActionHandler = handler.ClusterActionHandler
clusterValidator := ccluster.Validator{
ClusterLister: managementContext.Management.Clusters("").Controller().Lister(),
}
schema.Validator = clusterValidator.Validator
cluster.SetClusterStore(schema, managementContext, clusterManager, k8sProxy)
}
func Templates(ctx context.Context, schemas *types.Schemas, managementContext *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.TemplateType)
schema.Scope = types.NamespaceScope
schema.Store = proxy.NewProxyStore(ctx, managementContext.ClientGetter,
config.ManagementStorageContext,
[]string{"apis"},
"management.cattle.io",
"v3",
"CatalogTemplate",
"catalogtemplates")
schema.Formatter = catalog.TemplateFormatter
wrapper := catalog.TemplateWrapper{
CatalogLister: managementContext.Management.Catalogs("").Controller().Lister(),
ClusterCatalogLister: managementContext.Management.ClusterCatalogs("").Controller().Lister(),
ProjectCatalogLister: managementContext.Management.ProjectCatalogs("").Controller().Lister(),
}
schema.LinkHandler = wrapper.TemplateIconHandler
schemaCatalogTemplate := schemas.Schema(&managementschema.Version, client.CatalogTemplateType)
schemaCatalogTemplate.CollectionMethods = []string{}
schemaCatalogTemplate.ResourceMethods = []string{}
}
func TemplateVersion(ctx context.Context, schemas *types.Schemas, managementContext *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.TemplateVersionType)
schema.Scope = types.NamespaceScope
schema.Store = proxy.NewProxyStore(ctx, managementContext.ClientGetter,
config.ManagementStorageContext,
[]string{"apis"},
"management.cattle.io",
"v3",
"CatalogTemplateVersion",
"catalogtemplateversions")
t := catalog.TemplateVerionFormatterWrapper{
CatalogLister: managementContext.Management.Catalogs("").Controller().Lister(),
ClusterCatalogLister: managementContext.Management.ClusterCatalogs("").Controller().Lister(),
ProjectCatalogLister: managementContext.Management.ProjectCatalogs("").Controller().Lister(),
}
schema.Formatter = t.TemplateVersionFormatter
schema.LinkHandler = t.TemplateVersionReadmeHandler
schema.Store = noopwatching.Wrap(schema.Store)
schemaCatalogTemplateVersion := schemas.Schema(&managementschema.Version, client.CatalogTemplateVersionType)
schemaCatalogTemplateVersion.CollectionMethods = []string{}
schemaCatalogTemplateVersion.ResourceMethods = []string{}
}
func TemplateContent(schemas *types.Schemas) {
schema := schemas.Schema(&managementschema.Version, client.TemplateContentType)
schema.Store = noopwatching.Wrap(schema.Store)
schema.CollectionMethods = []string{}
}
func Catalog(schemas *types.Schemas, managementContext *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.CatalogType)
schema.Formatter = catalog.Formatter
handler := catalog.ActionHandler{
CatalogClient: managementContext.Management.Catalogs(""),
}
schema.ActionHandler = handler.RefreshActionHandler
schema.CollectionFormatter = catalog.CollectionFormatter
schema.LinkHandler = handler.ExportYamlHandler
}
func ProjectCatalog(schemas *types.Schemas, managementContext *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.ProjectCatalogType)
schema.Formatter = catalog.Formatter
handler := catalog.ActionHandler{
ProjectCatalogClient: managementContext.Management.ProjectCatalogs(""),
}
schema.ActionHandler = handler.RefreshProjectCatalogActionHandler
schema.CollectionFormatter = catalog.CollectionFormatter
}
func ClusterCatalog(schemas *types.Schemas, managementContext *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.ClusterCatalogType)
schema.Formatter = catalog.Formatter
handler := catalog.ActionHandler{
ClusterCatalogClient: managementContext.Management.ClusterCatalogs(""),
}
schema.ActionHandler = handler.RefreshClusterCatalogActionHandler
schema.CollectionFormatter = catalog.CollectionFormatter
}
func ClusterRegistrationTokens(schemas *types.Schemas) {
schema := schemas.Schema(&managementschema.Version, client.ClusterRegistrationTokenType)
schema.Store = &cluster.RegistrationTokenStore{
Store: schema.Store,
}
schema.Formatter = clusterregistrationtokens.Formatter
}
func NodeTemplates(schemas *types.Schemas, management *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.NodeTemplateType)
npl := management.Management.NodePools("").Controller().Lister()
f := nodetemplate.Formatter{
NodePoolLister: npl,
}
schema.Formatter = f.Formatter
s := &nodeTemplateStore.Store{
Store: userscope.NewStore(management.Core.Namespaces(""), schema.Store),
NodePoolLister: npl,
CloudCredentialLister: management.Core.Secrets(namespace.GlobalNamespace).Controller().Lister(),
}
schema.Store = s
schema.Validator = nodetemplate.Validator
}
func SecretTypes(ctx context.Context, schemas *types.Schemas, management *config.ScaledContext) {
secretSchema := schemas.Schema(&projectschema.Version, projectclient.SecretType)
secretSchema.Store = proxy.NewProxyStore(ctx, management.ClientGetter,
config.ManagementStorageContext,
[]string{"api"},
"",
"v1",
"Secret",
"secrets")
for _, subSchema := range schemas.SchemasForVersion(projectschema.Version) {
if subSchema.BaseType == projectclient.SecretType && subSchema.ID != projectclient.SecretType {
if subSchema.CanList(nil) == nil {
subSchema.Store = subtype.NewSubTypeStore(subSchema.ID, secretSchema.Store)
}
}
}
secretSchema = schemas.Schema(&projectschema.Version, projectclient.CertificateType)
secretSchema.Store = cert.Wrap(secretSchema.Store)
mgmtSecretSchema := schemas.Schema(&managementschema.Version, client.ManagementSecretType)
mgmtSecretSchema.Store = proxy.NewProxyStore(ctx, management.ClientGetter,
config.ManagementStorageContext,
[]string{"api"},
"",
"v1",
"Secret",
"secrets")
credSchema := schemas.Schema(&managementschema.Version, client.CloudCredentialType)
credSchema.Store = cred.Wrap(mgmtSecretSchema.Store,
management.Core.Namespaces(""),
management.Management.NodeTemplates("").Controller().Lister())
credSchema.Validator = cred.Validator
}
func User(ctx context.Context, schemas *types.Schemas, management *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.UserType)
handler := &authn.Handler{
UserClient: management.Management.Users(""),
GlobalRoleBindingsClient: management.Management.GlobalRoleBindings(""),
UserAuthRefresher: providerrefresh.NewUserAuthRefresher(ctx, management),
}
schema.Formatter = handler.UserFormatter
schema.CollectionFormatter = handler.CollectionFormatter
schema.ActionHandler = handler.Actions
}
func Preference(schemas *types.Schemas, management *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.PreferenceType)
schema.Store = preference.NewStore(management.Core.Namespaces(""), schema.Store)
}
func NodeTypes(schemas *types.Schemas, management *config.ScaledContext) error {
secretStore, err := nodeconfig.NewStore(management.Core.Namespaces(""), management.Core)
if err != nil {
return err
}
schema := schemas.Schema(&managementschema.Version, client.NodeDriverType)
machineDriverHandlers := &node.DriverHandlers{
NodeDriverClient: management.Management.NodeDrivers(""),
}
schema.Formatter = machineDriverHandlers.Formatter
schema.ActionHandler = machineDriverHandlers.ActionHandler
schema.LinkHandler = machineDriverHandlers.ExportYamlHandler
machineHandler := &node.Handler{
SecretStore: secretStore,
}
schema = schemas.Schema(&managementschema.Version, client.NodeType)
schema.Formatter = node.Formatter
schema.LinkHandler = machineHandler.LinkHandler
actionWrapper := node.ActionWrapper{}
schema.ActionHandler = actionWrapper.ActionHandler
return nil
}
func App(schemas *types.Schemas, management *config.ScaledContext, kubeConfigGetter common.KubeConfigGetter) {
schema := schemas.Schema(&projectschema.Version, projectclient.AppType)
store := &appStore.Store{
Store: schema.Store,
Apps: management.Project.Apps("").Controller().Lister(),
}
schema.Store = store
wrapper := app.Wrapper{
Clusters: management.Management.Clusters(""),
TemplateVersionClient: management.Management.CatalogTemplateVersions(""),
KubeConfigGetter: kubeConfigGetter,
AppGetter: management.Project,
UserLister: management.Management.Users("").Controller().Lister(),
UserManager: management.UserManager,
}
schema.Formatter = app.Formatter
schema.ActionHandler = wrapper.ActionHandler
schema.LinkHandler = wrapper.LinkHandler
schema.Validator = wrapper.Validator
}
func Setting(schemas *types.Schemas) {
schema := schemas.Schema(&managementschema.Version, client.SettingType)
schema.Formatter = setting.Formatter
schema.Validator = setting.Validator
schema.Store = settingstore.New(schema.Store)
}
func LoggingTypes(schemas *types.Schemas, management *config.ScaledContext, clusterManager *clustermanager.Manager, k8sProxy http.Handler) {
handler := logging.NewHandler(
management.Dialer,
clusterManager,
management.Project,
management.Management.Projects("").Controller().Lister(),
management.Management.ProjectLoggings("").Controller().Lister(),
management.Management.CatalogTemplates("").Controller().Lister(),
)
schema := schemas.Schema(&managementschema.Version, client.ClusterLoggingType)
schema.CollectionFormatter = logging.CollectionFormatter
schema.ActionHandler = handler.ActionHandler
schema.Validator = logging.ClusterLoggingValidator
schema = schemas.Schema(&managementschema.Version, client.ProjectLoggingType)
schema.CollectionFormatter = logging.CollectionFormatter
schema.ActionHandler = handler.ActionHandler
schema.Validator = logging.ProjectLoggingValidator
}
func Alert(schemas *types.Schemas, management *config.ScaledContext) {
handler := &alert.Handler{
ClusterAlertRule: management.Management.ClusterAlertRules(""),
ProjectAlertRule: management.Management.ProjectAlertRules(""),
Notifiers: management.Management.Notifiers(""),
}
schema := schemas.Schema(&managementschema.Version, client.NotifierType)
schema.CollectionFormatter = alert.NotifierCollectionFormatter
schema.Formatter = alert.NotifierFormatter
schema.ActionHandler = handler.NotifierActionHandler
schema = schemas.Schema(&managementschema.Version, client.ClusterAlertRuleType)
schema.Formatter = alert.RuleFormatter
schema.Validator = alert.ClusterAlertRuleValidator
schema.ActionHandler = handler.ClusterAlertRuleActionHandler
schema = schemas.Schema(&managementschema.Version, client.ProjectAlertRuleType)
schema.Formatter = alert.RuleFormatter
schema.Validator = alert.ProjectAlertRuleValidator
schema.ActionHandler = handler.ProjectAlertRuleActionHandler
//old schema just for migrate
schema = schemas.Schema(&managementschema.Version, client.ClusterAlertType)
schema = schemas.Schema(&managementschema.Version, client.ProjectAlertType)
}
func Monitor(schemas *types.Schemas, management *config.ScaledContext, clusterManager *clustermanager.Manager) {
clusterGraphHandler := monitor.NewClusterGraphHandler(management.Dialer, clusterManager)
projectGraphHandler := monitor.NewProjectGraphHandler(management.Dialer, clusterManager)
metricHandler := monitor.NewMetricHandler(management.Dialer, clusterManager)
schema := schemas.Schema(&managementschema.Version, client.ClusterMonitorGraphType)
schema.CollectionFormatter = monitor.QueryGraphCollectionFormatter
schema.ActionHandler = clusterGraphHandler.QuerySeriesAction
schema = schemas.Schema(&managementschema.Version, client.ProjectMonitorGraphType)
schema.CollectionFormatter = monitor.QueryGraphCollectionFormatter
schema.ActionHandler = projectGraphHandler.QuerySeriesAction
schema = schemas.Schema(&managementschema.Version, client.MonitorMetricType)
schema.CollectionFormatter = monitor.MetricCollectionFormatter
schema.ActionHandler = metricHandler.Action
}
func Pipeline(schemas *types.Schemas, management *config.ScaledContext, clusterManager *clustermanager.Manager) {
pipelineHandler := &pipeline.Handler{
PipelineLister: management.Project.Pipelines("").Controller().Lister(),
PipelineExecutions: management.Project.PipelineExecutions(""),
SourceCodeCredentials: management.Project.SourceCodeCredentials(""),
SourceCodeCredentialLister: management.Project.SourceCodeCredentials("").Controller().Lister(),
}
schema := schemas.Schema(&projectschema.Version, projectclient.PipelineType)
schema.Formatter = pipeline.Formatter
schema.ActionHandler = pipelineHandler.ActionHandler
schema.LinkHandler = pipelineHandler.LinkHandler
pipelineExecutionHandler := &pipeline.ExecutionHandler{
ClusterManager: clusterManager,
PipelineLister: management.Project.Pipelines("").Controller().Lister(),
PipelineExecutionLister: management.Project.PipelineExecutions("").Controller().Lister(),
PipelineExecutions: management.Project.PipelineExecutions(""),
}
schema = schemas.Schema(&projectschema.Version, projectclient.PipelineExecutionType)
schema.Formatter = pipelineExecutionHandler.ExecutionFormatter
schema.LinkHandler = pipelineExecutionHandler.LinkHandler
schema.ActionHandler = pipelineExecutionHandler.ActionHandler
schema = schemas.Schema(&projectschema.Version, projectclient.PipelineSettingType)
schema.Formatter = setting.PipelineFormatter
sourceCodeCredentialHandler := &pipeline.SourceCodeCredentialHandler{
SourceCodeCredentials: management.Project.SourceCodeCredentials(""),
SourceCodeCredentialLister: management.Project.SourceCodeCredentials("").Controller().Lister(),
SourceCodeRepositories: management.Project.SourceCodeRepositories(""),
SourceCodeRepositoryLister: management.Project.SourceCodeRepositories("").Controller().Lister(),
}
schema = schemas.Schema(&projectschema.Version, projectclient.SourceCodeCredentialType)
schema.Formatter = pipeline.SourceCodeCredentialFormatter
schema.ListHandler = sourceCodeCredentialHandler.ListHandler
schema.ActionHandler = sourceCodeCredentialHandler.ActionHandler
schema.LinkHandler = sourceCodeCredentialHandler.LinkHandler
schema.Store = userscope.NewStore(management.Core.Namespaces(""), schema.Store)
schema = schemas.Schema(&projectschema.Version, projectclient.SourceCodeRepositoryType)
schema.Store = userscope.NewStore(management.Core.Namespaces(""), schema.Store)
//register and setup source code providers
sourcecodeproviders.SetupSourceCodeProviderConfig(management, schemas)
}
func Project(schemas *types.Schemas, management *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.ProjectType)
schema.Formatter = projectaction.Formatter
handler := &projectaction.Handler{
Projects: management.Management.Projects(""),
ProjectLister: management.Management.Projects("").Controller().Lister(),
UserMgr: management.UserManager,
ClusterManager: management.ClientGetter.(*clustermanager.Manager),
}
schema.ActionHandler = handler.Actions
}
func PodSecurityPolicyTemplate(schemas *types.Schemas, management *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.PodSecurityPolicyTemplateType)
schema.Formatter = podsecuritypolicytemplate.NewFormatter(management)
schema.Store = &podsecuritypolicytemplate.Store{
Store: schema.Store,
}
}
func ClusterRoleTemplateBinding(schemas *types.Schemas, management *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.ClusterRoleTemplateBindingType)
schema.Validator = roletemplatebinding.NewCRTBValidator(management)
}
func ProjectRoleTemplateBinding(schemas *types.Schemas, management *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.ProjectRoleTemplateBindingType)
schema.Validator = roletemplatebinding.NewPRTBValidator(management)
}
func RoleTemplate(schemas *types.Schemas, management *config.ScaledContext) {
rt := roletemplate.Wrapper{
RoleTemplateLister: management.Management.RoleTemplates("").Controller().Lister(),
}
schema := schemas.Schema(&managementschema.Version, client.RoleTemplateType)
schema.Validator = rt.Validator
}
func KontainerDriver(schemas *types.Schemas, management *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.KontainerDriverType)
handler := kontainerdriver.ActionHandler{
KontainerDrivers: management.Management.KontainerDrivers(""),
KontainerDriverLister: management.Management.KontainerDrivers("").Controller().Lister(),
}
schema.ActionHandler = handler.ActionHandler
schema.Formatter = kontainerdriver.NewFormatter(management)
schema.Store = kontainerdriver.NewStore(management, schema.Store)
kontainerDriverValidator := kontainerdriver.Validator{
KontainerDriverLister: management.Management.KontainerDrivers("").Controller().Lister(),
}
schema.Validator = kontainerDriverValidator.Validator
}
func MultiClusterApps(schemas *types.Schemas, management *config.ScaledContext) {
schema := schemas.Schema(&managementschema.Version, client.MultiClusterAppType)
schema.Store = &globalresource.GlobalNamespaceStore{
Store: schema.Store,
NamespaceInterface: management.Core.Namespaces(""),
}
revisionSchema := schemas.Schema(&managementschema.Version, client.MultiClusterAppRevisionType)
revisionSchema.Store = &globalresource.GlobalNamespaceStore{
Store: revisionSchema.Store,
NamespaceInterface: management.Core.Namespaces(""),
}
wrapper := multiclusterapp.Wrapper{
MultiClusterApps: management.Management.MultiClusterApps(""),
MultiClusterAppLister: management.Management.MultiClusterApps("").Controller().Lister(),
MultiClusterAppRevisionLister: management.Management.MultiClusterAppRevisions("").Controller().Lister(),
PrtbLister: management.Management.ProjectRoleTemplateBindings("").Controller().Lister(),
CrtbLister: management.Management.ClusterRoleTemplateBindings("").Controller().Lister(),
RoleTemplateLister: management.Management.RoleTemplates("").Controller().Lister(),
Users: management.Management.Users(""),
GrbLister: management.Management.GlobalRoleBindings("").Controller().Lister(),
GrLister: management.Management.GlobalRoles("").Controller().Lister(),
Prtbs: management.Management.ProjectRoleTemplateBindings(""),
Crtbs: management.Management.ClusterRoleTemplateBindings(""),
ProjectLister: management.Management.Projects("").Controller().Lister(),
ClusterLister: management.Management.Clusters("").Controller().Lister(),
Apps: management.Project.Apps(""),
}
schema.Formatter = wrapper.Formatter
schema.ActionHandler = wrapper.ActionHandler
schema.LinkHandler = wrapper.LinkHandler
schema.Validator = wrapper.Validator
}
func GlobalDNSs(schemas *types.Schemas, management *config.ScaledContext, localClusterEnabled bool) {
gdns := globaldns.Wrapper{
GlobalDNSes: management.Management.GlobalDNSs(""),
GlobalDNSLister: management.Management.GlobalDNSs("").Controller().Lister(),
PrtbLister: management.Management.ProjectRoleTemplateBindings("").Controller().Lister(),
MultiClusterAppLister: management.Management.MultiClusterApps("").Controller().Lister(),
Users: management.Management.Users(""),
GrbLister: management.Management.GlobalRoleBindings("").Controller().Lister(),
GrLister: management.Management.GlobalRoles("").Controller().Lister(),
}
schema := schemas.Schema(&managementschema.Version, client.GlobalDNSType)
schema.Store = &globalresource.GlobalNamespaceStore{
Store: schema.Store,
NamespaceInterface: management.Core.Namespaces(""),
}
schema.Formatter = gdns.Formatter
schema.ActionHandler = gdns.ActionHandler
schema.Validator = gdns.Validator
schema.Store = globaldnsAPIStore.Wrap(schema.Store)
if !localClusterEnabled {
schema.CollectionMethods = []string{}
schema.ResourceMethods = []string{}
}
}
func GlobalDNSProviders(schemas *types.Schemas, management *config.ScaledContext, localClusterEnabled bool) {
schema := schemas.Schema(&managementschema.Version, client.GlobalDNSProviderType)
schema.Store = &globalresource.GlobalNamespaceStore{
Store: schema.Store,
NamespaceInterface: management.Core.Namespaces(""),
}
schema.Store = globaldnsAPIStore.ProviderWrap(schema.Store)
if !localClusterEnabled {
schema.CollectionMethods = []string{}
schema.ResourceMethods = []string{}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.4-rc15

搜索帮助