1
0
mirror of https://github.com/rancher/types.git synced 2025-07-31 04:49:37 +00:00

Updates type for subcontext rewrite

This commit is contained in:
Darren Shepherd 2018-02-09 13:33:36 -07:00
parent 55e121c54f
commit 0e56750e82
5 changed files with 50 additions and 56 deletions

View File

@ -12,9 +12,11 @@ import (
var (
Version = types.APIVersion{
Version: "v3",
Group: "cluster.cattle.io",
Path: "/v3/clusters",
Version: "v3",
Group: "cluster.cattle.io",
Path: "/v3/cluster",
SubContext: true,
SubContextSchema: "/v3/schemas/cluster",
}
Schemas = factory.Schemas(&Version).

View File

@ -16,9 +16,6 @@ var (
Version: "v3",
Group: "management.cattle.io",
Path: "/v3",
SubContexts: map[string]bool{
"clusters": true,
},
}
Schemas = factory.Schemas(&Version).
@ -30,7 +27,6 @@ var (
Init(authnTypes).
Init(tokens).
Init(schemaTypes).
Init(stackTypes).
Init(userTypes).
Init(logTypes).
Init(globalTypes).
@ -84,9 +80,7 @@ func clusterTypes(schemas *types.Schemas) *types.Schemas {
AddMapperForType(&Version, v3.RancherKubernetesEngineConfig{},
m.Drop{Field: "systemImages"},
).
MustImportAndCustomize(&Version, v3.Cluster{}, func(schema *types.Schema) {
schema.SubContext = "clusters"
}).
MustImport(&Version, v3.Cluster{}).
MustImport(&Version, v3.ClusterEvent{}).
MustImport(&Version, v3.ClusterRegistrationToken{}).
MustImportAndCustomize(&Version, v3.Cluster{}, func(schema *types.Schema) {
@ -109,9 +103,7 @@ func authzTypes(schemas *types.Schemas) *types.Schemas {
AddMapperForType(&Version, v3.ProjectRoleTemplateBinding{},
&mapper.NamespaceIDMapper{},
).
MustImportAndCustomize(&Version, v3.Project{}, func(schema *types.Schema) {
schema.SubContext = "projects"
}).
MustImport(&Version, v3.Project{}).
MustImport(&Version, v3.GlobalRole{}).
MustImport(&Version, v3.GlobalRoleBinding{}).
MustImport(&Version, v3.RoleTemplate{}).
@ -218,20 +210,6 @@ func authnTypes(schemas *types.Schemas) *types.Schemas {
})
}
func stackTypes(schema *types.Schemas) *types.Schemas {
return schema.
MustImportAndCustomize(&Version, v3.App{}, func(schema *types.Schema) {
schema.ResourceActions = map[string]types.Action{
"upgrade": {
Input: "templateVersionId",
},
"rollback": {
Input: "revision",
},
}
})
}
func userTypes(schema *types.Schemas) *types.Schemas {
return schema.
MustImportAndCustomize(&Version, v3.Preference{}, func(schema *types.Schema) {

View File

@ -13,17 +13,15 @@ import (
var (
Version = types.APIVersion{
Version: "v3",
Group: "project.cattle.io",
Path: "/v3/projects",
SubContexts: map[string]bool{
"projects": true,
},
Version: "v3",
Group: "project.cattle.io",
Path: "/v3/project",
SubContext: true,
SubContextSchema: "/v3/schemas/project",
}
Schemas = factory.Schemas(&Version).
// Namespace must be first
Init(namespaceTypes).
// volume before pod types. pod types uses volume things, so need to register mapper
Init(volumeTypes).
Init(ingressTypes).
@ -36,6 +34,7 @@ var (
Init(replicationController).
Init(daemonSet).
Init(workloadTypes).
Init(appTypes).
Init(configMapTypes)
)
@ -454,3 +453,17 @@ func volumeTypes(schemas *types.Schemas) *types.Schemas {
return schemas.
MustImport(&Version, v1.PersistentVolumeClaim{}, projectOverride{})
}
func appTypes(schema *types.Schemas) *types.Schemas {
return schema.
MustImportAndCustomize(&Version, v3.App{}, func(schema *types.Schema) {
schema.ResourceActions = map[string]types.Action{
"upgrade": {
Input: "templateVersionId",
},
"rollback": {
Input: "revision",
},
}
})
}

View File

@ -7,6 +7,7 @@ import (
"github.com/rancher/norman/controller"
"github.com/rancher/norman/event"
"github.com/rancher/norman/signal"
"github.com/rancher/norman/store/proxy"
"github.com/rancher/norman/types"
appsv1beta2 "github.com/rancher/types/apis/apps/v1beta2"
clusterSchema "github.com/rancher/types/apis/cluster.cattle.io/v3/schema"
@ -17,9 +18,9 @@ import (
projectv3 "github.com/rancher/types/apis/project.cattle.io/v3"
projectSchema "github.com/rancher/types/apis/project.cattle.io/v3/schema"
rbacv1 "github.com/rancher/types/apis/rbac.authorization.k8s.io/v1"
projectClient "github.com/rancher/types/client/project/v3"
"github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
@ -29,28 +30,24 @@ import (
)
var (
ProjectTypes = []string{
projectClient.RegistryCredentialType,
projectClient.BasicAuthType,
projectClient.CertificateType,
projectClient.DockerCredentialType,
projectClient.ServiceAccountTokenType,
projectClient.SecretType,
projectClient.SSHAuthType,
}
UserStorageContext types.StorageContext = "user"
ManagementStorageContext types.StorageContext = "mgmt"
)
type ManagementContext struct {
eventBroadcaster record.EventBroadcaster
ClientGetter proxy.ClientGetter
LocalConfig *rest.Config
RESTConfig rest.Config
UnversionedClient rest.Interface
K8sClient kubernetes.Interface
APIExtClient clientset.Interface
Events record.EventRecorder
EventLogger event.Logger
Schemas *types.Schemas
Scheme *runtime.Scheme
AccessControl types.AccessControl
Management managementv3.Interface
RBAC rbacv1.Interface
@ -66,11 +63,11 @@ func (c *ManagementContext) controllers() []controller.Starter {
}
type UserContext struct {
Schemas *types.Schemas
Management *ManagementContext
ClusterName string
RESTConfig rest.Config
UnversionedClient rest.Interface
APIExtClient clientset.Interface
K8sClient kubernetes.Interface
Apps appsv1beta2.Interface
@ -92,7 +89,7 @@ func (w *UserContext) controllers() []controller.Starter {
func (w *UserContext) UserOnlyContext() *UserOnlyContext {
return &UserOnlyContext{
Schemas: w.Schemas,
Schemas: w.Management.Schemas,
ClusterName: w.ClusterName,
RESTConfig: w.RESTConfig,
UnversionedClient: w.UnversionedClient,
@ -168,16 +165,19 @@ func NewManagementContext(config rest.Config) (*ManagementContext, error) {
return nil, err
}
context.Schemas = types.NewSchemas().
AddSchemas(managementSchema.Schemas)
for _, projectType := range ProjectTypes {
schema := projectSchema.Schemas.Schema(&projectSchema.Version, projectType)
context.Schemas.AddSchema(*schema)
context.APIExtClient, err = clientset.NewForConfig(&dynamicConfig)
if err != nil {
return nil, err
}
context.Schemas = types.NewSchemas().
AddSchemas(managementSchema.Schemas).
AddSchemas(clusterSchema.Schemas).
AddSchemas(projectSchema.Schemas)
context.Scheme = runtime.NewScheme()
managementv3.AddToScheme(context.Scheme)
projectv3.AddToScheme(context.Scheme)
context.eventBroadcaster = record.NewBroadcaster()
context.Events = context.eventBroadcaster.NewRecorder(context.Scheme, v1.EventSource{
@ -215,10 +215,6 @@ func NewUserContext(managementConfig, config rest.Config, clusterName string) (*
context := &UserContext{
RESTConfig: config,
ClusterName: clusterName,
Schemas: types.NewSchemas().
AddSchemas(managementSchema.Schemas).
AddSchemas(clusterSchema.Schemas).
AddSchemas(projectSchema.Schemas),
}
context.Management, err = NewManagementContext(managementConfig)
@ -272,6 +268,11 @@ func NewUserContext(managementConfig, config rest.Config, clusterName string) (*
return nil, err
}
context.APIExtClient, err = clientset.NewForConfig(&dynamicConfig)
if err != nil {
return nil, err
}
return context, err
}