2019-08-13 23:36:03 +00:00
|
|
|
package resources
|
|
|
|
|
|
|
|
import (
|
2020-06-02 15:51:42 +00:00
|
|
|
"context"
|
|
|
|
|
2020-06-12 04:50:59 +00:00
|
|
|
"github.com/rancher/apiserver/pkg/store/apiroot"
|
|
|
|
"github.com/rancher/apiserver/pkg/subscribe"
|
|
|
|
"github.com/rancher/apiserver/pkg/types"
|
2020-02-10 17:18:20 +00:00
|
|
|
"github.com/rancher/steve/pkg/accesscontrol"
|
2020-01-31 05:01:21 +00:00
|
|
|
"github.com/rancher/steve/pkg/client"
|
2019-09-11 21:05:00 +00:00
|
|
|
"github.com/rancher/steve/pkg/clustercache"
|
2020-06-12 04:50:59 +00:00
|
|
|
"github.com/rancher/steve/pkg/resources/apigroups"
|
2021-03-02 00:12:28 +00:00
|
|
|
"github.com/rancher/steve/pkg/resources/cluster"
|
2020-06-12 04:50:59 +00:00
|
|
|
"github.com/rancher/steve/pkg/resources/common"
|
|
|
|
"github.com/rancher/steve/pkg/resources/counts"
|
2020-08-04 02:52:04 +00:00
|
|
|
"github.com/rancher/steve/pkg/resources/formatters"
|
2021-03-02 05:26:26 +00:00
|
|
|
"github.com/rancher/steve/pkg/resources/userpreferences"
|
2020-01-31 05:37:59 +00:00
|
|
|
"github.com/rancher/steve/pkg/schema"
|
2021-03-02 00:12:28 +00:00
|
|
|
steveschema "github.com/rancher/steve/pkg/schema"
|
2020-06-12 04:50:59 +00:00
|
|
|
"github.com/rancher/steve/pkg/stores/proxy"
|
2020-09-11 06:04:28 +00:00
|
|
|
"github.com/rancher/steve/pkg/summarycache"
|
2024-01-11 21:32:09 +00:00
|
|
|
corecontrollers "github.com/rancher/wrangler/v2/pkg/generated/controllers/core/v1"
|
2021-08-10 18:03:59 +00:00
|
|
|
"k8s.io/apiserver/pkg/endpoints/request"
|
2020-01-31 05:37:59 +00:00
|
|
|
"k8s.io/client-go/discovery"
|
2019-08-13 23:36:03 +00:00
|
|
|
)
|
|
|
|
|
2021-03-02 00:12:28 +00:00
|
|
|
func DefaultSchemas(ctx context.Context, baseSchema *types.APISchemas, ccache clustercache.ClusterCache,
|
2021-08-10 23:09:19 +00:00
|
|
|
cg proxy.ClientGetter, schemaFactory steveschema.Factory, serverVersion string) error {
|
2019-09-09 21:28:55 +00:00
|
|
|
counts.Register(baseSchema, ccache)
|
2021-08-10 18:03:59 +00:00
|
|
|
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 23:09:19 +00:00
|
|
|
}, serverVersion)
|
2020-06-12 04:50:59 +00:00
|
|
|
apiroot.Register(baseSchema, []string{"v1"}, "proxy:/apis")
|
2021-03-02 00:12:28 +00:00
|
|
|
cluster.Register(ctx, baseSchema, cg, schemaFactory)
|
2021-03-02 05:26:26 +00:00
|
|
|
userpreferences.Register(baseSchema)
|
2021-03-02 00:12:28 +00:00
|
|
|
return nil
|
2020-01-31 05:37:59 +00:00
|
|
|
}
|
2019-08-13 23:36:03 +00:00
|
|
|
|
2020-06-22 15:49:49 +00:00
|
|
|
func DefaultSchemaTemplates(cf *client.Factory,
|
2021-03-02 00:12:28 +00:00
|
|
|
baseSchemas *types.APISchemas,
|
2020-06-22 15:49:49 +00:00
|
|
|
summaryCache *summarycache.SummaryCache,
|
|
|
|
lookup accesscontrol.AccessSetLookup,
|
2023-05-10 22:31:01 +00:00
|
|
|
discovery discovery.DiscoveryInterface,
|
|
|
|
namespaceCache corecontrollers.NamespaceCache) []schema.Template {
|
2020-01-31 05:37:59 +00:00
|
|
|
return []schema.Template{
|
2023-05-10 22:31:01 +00:00
|
|
|
common.DefaultTemplate(cf, summaryCache, lookup, namespaceCache),
|
2020-03-11 06:12:04 +00:00
|
|
|
apigroups.Template(discovery),
|
2020-06-05 20:30:33 +00:00
|
|
|
{
|
|
|
|
ID: "configmap",
|
2024-10-28 20:55:44 +00:00
|
|
|
Formatter: formatters.HandleHelmData,
|
2020-06-05 20:30:33 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "secret",
|
2024-10-28 20:55:44 +00:00
|
|
|
Formatter: formatters.HandleHelmData,
|
2020-08-04 02:52:04 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "pod",
|
|
|
|
Formatter: formatters.Pod,
|
2020-06-05 20:30:33 +00:00
|
|
|
},
|
2021-03-02 00:12:28 +00:00
|
|
|
{
|
|
|
|
ID: "management.cattle.io.cluster",
|
|
|
|
Customize: func(apiSchema *types.APISchema) {
|
|
|
|
cluster.AddApply(baseSchemas, apiSchema)
|
|
|
|
},
|
|
|
|
},
|
2020-01-31 05:01:21 +00:00
|
|
|
}
|
2019-08-13 23:36:03 +00:00
|
|
|
}
|