From 0e56750e8240a0094a4343bdbdc9826817aaffeb Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Fri, 9 Feb 2018 13:33:36 -0700 Subject: [PATCH] Updates type for subcontext rewrite --- apis/cluster.cattle.io/v3/schema/schema.go | 8 ++-- apis/management.cattle.io/v3/schema/schema.go | 26 +---------- apis/project.cattle.io/v3/schema/schema.go | 27 ++++++++--- .../v3/stack_types.go | 0 config/context.go | 45 ++++++++++--------- 5 files changed, 50 insertions(+), 56 deletions(-) rename apis/{management.cattle.io => project.cattle.io}/v3/stack_types.go (100%) diff --git a/apis/cluster.cattle.io/v3/schema/schema.go b/apis/cluster.cattle.io/v3/schema/schema.go index 067b507c..bbcb98f7 100644 --- a/apis/cluster.cattle.io/v3/schema/schema.go +++ b/apis/cluster.cattle.io/v3/schema/schema.go @@ -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). diff --git a/apis/management.cattle.io/v3/schema/schema.go b/apis/management.cattle.io/v3/schema/schema.go index 7fde9bd8..38aa8af2 100644 --- a/apis/management.cattle.io/v3/schema/schema.go +++ b/apis/management.cattle.io/v3/schema/schema.go @@ -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) { diff --git a/apis/project.cattle.io/v3/schema/schema.go b/apis/project.cattle.io/v3/schema/schema.go index 73622e64..e36eec7d 100644 --- a/apis/project.cattle.io/v3/schema/schema.go +++ b/apis/project.cattle.io/v3/schema/schema.go @@ -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", + }, + } + }) +} diff --git a/apis/management.cattle.io/v3/stack_types.go b/apis/project.cattle.io/v3/stack_types.go similarity index 100% rename from apis/management.cattle.io/v3/stack_types.go rename to apis/project.cattle.io/v3/stack_types.go diff --git a/config/context.go b/config/context.go index 4cd16865..0242e8c1 100644 --- a/config/context.go +++ b/config/context.go @@ -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 }