From 6ec1e0a01817ae16a52308c73301ca20c52200b3 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 26 Jun 2018 16:01:42 -0700 Subject: [PATCH] Resource quota --- apis/cluster.cattle.io/v3/schema/schema.go | 9 ++++- apis/management.cattle.io/v3/authz_types.go | 7 ++-- .../v3/resource_quota_types.go | 40 +++++++++++++++++++ apis/management.cattle.io/v3/schema/schema.go | 8 +++- main.go | 1 + 5 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 apis/management.cattle.io/v3/resource_quota_types.go diff --git a/apis/cluster.cattle.io/v3/schema/schema.go b/apis/cluster.cattle.io/v3/schema/schema.go index 3f75d92c..8034b1ba 100644 --- a/apis/cluster.cattle.io/v3/schema/schema.go +++ b/apis/cluster.cattle.io/v3/schema/schema.go @@ -31,11 +31,16 @@ 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.Drop{Field: "status"}, ). MustImport(&Version, v1.Namespace{}, struct { - Description string `json:"description"` - ProjectID string `norman:"type=reference[/v3/schemas/project]"` + 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"` }{}) } diff --git a/apis/management.cattle.io/v3/authz_types.go b/apis/management.cattle.io/v3/authz_types.go index b03dc57b..04a23e7e 100644 --- a/apis/management.cattle.io/v3/authz_types.go +++ b/apis/management.cattle.io/v3/authz_types.go @@ -47,9 +47,10 @@ 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]"` + 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"` } 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 new file mode 100644 index 00000000..48a49c8e --- /dev/null +++ b/apis/management.cattle.io/v3/resource_quota_types.go @@ -0,0 +1,40 @@ +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"` +} + +type ProjectResourceLimit 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"` +} + +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 08c76f86..d9d009aa 100644 --- a/apis/management.cattle.io/v3/schema/schema.go +++ b/apis/management.cattle.io/v3/schema/schema.go @@ -35,7 +35,8 @@ var ( Init(rkeTypes). Init(alertTypes). Init(pipelineTypes). - Init(composeType) + Init(composeType). + Init(resourceQuotaTemplateTypes) TokenSchemas = factory.Schemas(&Version). Init(tokens) @@ -583,3 +584,8 @@ func pipelineTypes(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. + MustImport(&Version, v3.ResourceQuotaTemplate{}) +} diff --git a/main.go b/main.go index 0e49c3e8..ba15ceb5 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,7 @@ func main() { v1.ConfigMap{}, v1.ServiceAccount{}, v1.ReplicationController{}, + v1.ResourceQuota{}, }, []interface{}{ v1.Node{}, v1.ComponentStatus{},