From eb18b360c0ad74d55ea8807433cded0c6b14d77c Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Thu, 23 Aug 2018 09:53:34 -0700 Subject: [PATCH] Resoure quota refactor - no more template --- apis/cluster.cattle.io/v3/schema/schema.go | 12 ++++---- apis/cluster.cattle.io/v3/schema/types.go | 20 +++++++++++++ apis/management.cattle.io/v3/authz_types.go | 9 +++--- .../v3/resource_quota_types.go | 28 +++++-------------- apis/management.cattle.io/v3/schema/schema.go | 10 +------ 5 files changed, 38 insertions(+), 41 deletions(-) diff --git a/apis/cluster.cattle.io/v3/schema/schema.go b/apis/cluster.cattle.io/v3/schema/schema.go index 8034b1ba..43004fe4 100644 --- a/apis/cluster.cattle.io/v3/schema/schema.go +++ b/apis/cluster.cattle.io/v3/schema/schema.go @@ -31,16 +31,14 @@ func namespaceTypes(schemas *types.Schemas) *types.Schemas { AddMapperForType(&Version, v1.Namespace{}, &m.AnnotationField{Field: "description"}, &m.AnnotationField{Field: "projectId"}, - &m.AnnotationField{Field: "resourceQuotaTemplateId"}, - &m.AnnotationField{Field: "resourceQuotaAppliedTemplateId"}, - + &m.AnnotationField{Field: "resourceQuota", Object: true}, &m.Drop{Field: "status"}, ). + MustImport(&Version, NamespaceResourceQuota{}). MustImport(&Version, v1.Namespace{}, struct { - Description string `json:"description"` - ProjectID string `norman:"type=reference[/v3/schemas/project]"` - ResourceQuotaTemplateID string `json:"resourceQuotaTemplateId,omitempty" norman:"type=reference[/v3/schemas/resourceQuotaTemplate]"` - ResourceQuotaAppliedTemplateID string `json:"resourceQuotaAppliedTemplateId,omitempty" norman:"type=reference[/v3/schemas/resourceQuotaTemplate],nocreate,noupdate"` + Description string `json:"description"` + ProjectID string `norman:"type=reference[/v3/schemas/project]"` + ResourceQuota string `json:"resourceQuota,omitempty" norman:"type=namespaceResourceQuota"` }{}) } diff --git a/apis/cluster.cattle.io/v3/schema/types.go b/apis/cluster.cattle.io/v3/schema/types.go index d0a14ccf..07785689 100644 --- a/apis/cluster.cattle.io/v3/schema/types.go +++ b/apis/cluster.cattle.io/v3/schema/types.go @@ -25,3 +25,23 @@ type KubernetesInfo struct { KubeletVersion string KubeProxyVersion string } + +type NamespaceResourceQuota struct { + Limit ResourceQuotaLimit `json:"limit,omitempty"` +} + +type ResourceQuotaLimit struct { + Pods string `json:"pods,omitempty"` + Services string `json:"services,omitempty"` + ReplicationControllers string `json:"replicationControllers,omitempty"` + Secrets string `json:"secrets,omitempty"` + ConfigMaps string `json:"configMaps,omitempty"` + PersistentVolumeClaims string `json:"persistentVolumeClaims,omitempty"` + ServicesNodePorts string `json:"servicesNodePorts,omitempty"` + ServicesLoadBalancers string `json:"servicesLoadBalancers,omitempty"` + RequestsCPU string `json:"requestsCpu,omitempty"` + RequestsMemory string `json:"requestsMemory,omitempty"` + RequestsStorage string `json:"requestsStorage,omitempty"` + LimitsCPU string `json:"limitsCpu,omitempty"` + LimitsMemory string `json:"limitsMemory,omitempty"` +} diff --git a/apis/management.cattle.io/v3/authz_types.go b/apis/management.cattle.io/v3/authz_types.go index 04a23e7e..91169412 100644 --- a/apis/management.cattle.io/v3/authz_types.go +++ b/apis/management.cattle.io/v3/authz_types.go @@ -47,10 +47,11 @@ type ProjectCondition struct { } type ProjectSpec struct { - DisplayName string `json:"displayName,omitempty" norman:"required"` - Description string `json:"description"` - ClusterName string `json:"clusterName,omitempty" norman:"required,type=reference[cluster]"` - ResourceQuota *ProjectResourceQuota `json:"resourceQuota,omitempty"` + DisplayName string `json:"displayName,omitempty" norman:"required"` + Description string `json:"description"` + ClusterName string `json:"clusterName,omitempty" norman:"required,type=reference[cluster]"` + ResourceQuota *ProjectResourceQuota `json:"resourceQuota,omitempty"` + NamespaceDefaultResourceQuota *NamespaceResourceQuota `json:"namespaceDefaultResourceQuota,omitempty"` } type GlobalRole struct { diff --git a/apis/management.cattle.io/v3/resource_quota_types.go b/apis/management.cattle.io/v3/resource_quota_types.go index 48a49c8e..586de7ab 100644 --- a/apis/management.cattle.io/v3/resource_quota_types.go +++ b/apis/management.cattle.io/v3/resource_quota_types.go @@ -1,16 +1,15 @@ package v3 -import ( - "github.com/rancher/norman/types" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - type ProjectResourceQuota struct { - Limit ProjectResourceLimit `json:"limit,omitempty"` - UsedLimit ProjectResourceLimit `json:"usedLimit,omitempty"` + Limit ResourceQuotaLimit `json:"limit,omitempty"` + UsedLimit ResourceQuotaLimit `json:"usedLimit,omitempty"` } -type ProjectResourceLimit struct { +type NamespaceResourceQuota struct { + Limit ResourceQuotaLimit `json:"limit,omitempty"` +} + +type ResourceQuotaLimit struct { Pods string `json:"pods,omitempty"` Services string `json:"services,omitempty"` ReplicationControllers string `json:"replicationControllers,omitempty"` @@ -25,16 +24,3 @@ type ProjectResourceLimit struct { LimitsCPU string `json:"limitsCpu,omitempty"` LimitsMemory string `json:"limitsMemory,omitempty"` } - -type ResourceQuotaTemplate struct { - types.Namespaced - - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Description string `json:"description"` - IsDefault bool `json:"isDefault"` - ClusterName string `json:"clusterName,omitempty" norman:"required,type=reference[cluster]"` - - ProjectResourceQuota -} diff --git a/apis/management.cattle.io/v3/schema/schema.go b/apis/management.cattle.io/v3/schema/schema.go index 12bea36b..f8d60dec 100644 --- a/apis/management.cattle.io/v3/schema/schema.go +++ b/apis/management.cattle.io/v3/schema/schema.go @@ -34,8 +34,7 @@ var ( Init(globalTypes). Init(rkeTypes). Init(alertTypes). - Init(composeType). - Init(resourceQuotaTemplateTypes) + Init(composeType) TokenSchemas = factory.Schemas(&Version). Init(tokens) @@ -537,10 +536,3 @@ func alertTypes(schema *types.Schemas) *types.Schemas { func composeType(schemas *types.Schemas) *types.Schemas { return schemas.MustImport(&Version, v3.ComposeConfig{}) } - -func resourceQuotaTemplateTypes(schemas *types.Schemas) *types.Schemas { - return schemas. - MustImportAndCustomize(&Version, v3.ResourceQuotaTemplate{}, func(schema *types.Schema) { - schema.ResourceMethods = []string{http.MethodGet, http.MethodDelete} - }) -}