1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-01 15:37:31 +00:00
Files
steve/pkg/resources/schema.go

75 lines
2.3 KiB
Go
Raw Normal View History

2019-08-13 16:36:03 -07:00
package resources
import (
2020-06-02 08:51:42 -07:00
"context"
"github.com/rancher/apiserver/pkg/store/apiroot"
"github.com/rancher/apiserver/pkg/subscribe"
"github.com/rancher/apiserver/pkg/types"
2020-02-10 10:18:20 -07:00
"github.com/rancher/steve/pkg/accesscontrol"
2020-01-30 22:01:21 -07:00
"github.com/rancher/steve/pkg/client"
2019-09-11 14:05:00 -07:00
"github.com/rancher/steve/pkg/clustercache"
"github.com/rancher/steve/pkg/resources/apigroups"
"github.com/rancher/steve/pkg/resources/cluster"
"github.com/rancher/steve/pkg/resources/common"
"github.com/rancher/steve/pkg/resources/counts"
2020-08-03 19:52:04 -07:00
"github.com/rancher/steve/pkg/resources/formatters"
2021-03-01 22:26:26 -07:00
"github.com/rancher/steve/pkg/resources/userpreferences"
2020-01-30 22:37:59 -07:00
"github.com/rancher/steve/pkg/schema"
steveschema "github.com/rancher/steve/pkg/schema"
"github.com/rancher/steve/pkg/stores/proxy"
2020-09-10 23:04:28 -07:00
"github.com/rancher/steve/pkg/summarycache"
corecontrollers "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"k8s.io/apiserver/pkg/endpoints/request"
2020-01-30 22:37:59 -07:00
"k8s.io/client-go/discovery"
2019-08-13 16:36:03 -07:00
)
func DefaultSchemas(ctx context.Context, baseSchema *types.APISchemas, ccache clustercache.ClusterCache,
2021-08-10 16:09:19 -07:00
cg proxy.ClientGetter, schemaFactory steveschema.Factory, serverVersion string) error {
2019-09-09 14:28:55 -07:00
counts.Register(baseSchema, ccache)
subscribe.Register(baseSchema, func(apiOp *types.APIRequest) *types.APISchemas {
user, ok := request.UserFrom(apiOp.Context())
if ok {
schemas, err := schemaFactory.Schemas(user)
if err == nil {
return schemas
}
}
return apiOp.Schemas
2021-08-10 16:09:19 -07:00
}, serverVersion)
apiroot.Register(baseSchema, []string{"v1"}, "proxy:/apis")
cluster.Register(ctx, baseSchema, cg, schemaFactory)
2021-03-01 22:26:26 -07:00
userpreferences.Register(baseSchema)
return nil
2020-01-30 22:37:59 -07:00
}
2019-08-13 16:36:03 -07:00
2020-06-22 08:49:49 -07:00
func DefaultSchemaTemplates(cf *client.Factory,
baseSchemas *types.APISchemas,
2020-06-22 08:49:49 -07:00
summaryCache *summarycache.SummaryCache,
lookup accesscontrol.AccessSetLookup,
discovery discovery.DiscoveryInterface,
namespaceCache corecontrollers.NamespaceCache) []schema.Template {
2020-01-30 22:37:59 -07:00
return []schema.Template{
common.DefaultTemplate(cf, summaryCache, lookup, namespaceCache),
apigroups.Template(discovery),
2020-06-05 13:30:33 -07:00
{
ID: "configmap",
2020-08-03 19:52:04 -07:00
Formatter: formatters.DropHelmData,
2020-06-05 13:30:33 -07:00
},
{
ID: "secret",
2020-08-03 19:52:04 -07:00
Formatter: formatters.DropHelmData,
},
{
ID: "pod",
Formatter: formatters.Pod,
2020-06-05 13:30:33 -07:00
},
{
ID: "management.cattle.io.cluster",
Customize: func(apiSchema *types.APISchema) {
cluster.AddApply(baseSchemas, apiSchema)
},
},
2020-01-30 22:01:21 -07:00
}
2019-08-13 16:36:03 -07:00
}