Skip to content

Commit

Permalink
Quotas Part 1 (#168)
Browse files Browse the repository at this point in the history
Implment organization level quota objects, and project level
allocations.  Check this all hangs together in a rudimentary kind of way
also validating implicit stuff like "free" and "allocated" summaries are
filled in correctly and allocations cannot exceed quotas.  Also fixes a
slight RBAC problem with service accounts since I found it was broken
while testing.

Implements #167
  • Loading branch information
spjmurray authored Jan 31, 2025
1 parent ab31d5e commit 1c9b644
Show file tree
Hide file tree
Showing 27 changed files with 4,055 additions and 611 deletions.
4 changes: 2 additions & 2 deletions charts/identity/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: A Helm chart for deploying Unikorn's IdP

type: application

version: v0.2.53-rc3
appVersion: v0.2.53-rc3
version: v0.2.53-rc4
appVersion: v0.2.53-rc4

icon: https://raw.githubusercontent.com/unikorn-cloud/assets/main/images/logos/dark-on-light/icon.png

Expand Down
113 changes: 113 additions & 0 deletions charts/identity/crds/identity.unikorn-cloud.org_allocations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.3
name: allocations.identity.unikorn-cloud.org
spec:
group: identity.unikorn-cloud.org
names:
categories:
- unikorn
kind: Allocation
listKind: AllocationList
plural: allocations
singular: allocation
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .metadata.labels['unikorn-cloud\.org/resource-kind']
name: kind
type: string
- jsonPath: .metadata.labels['unikorn-cloud\.org/resource-id']
name: id
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: |-
Allocation objects are created for a resource, e.g. a cluster, on creation and
take up a slice of a quota's available resource quantities. At no point in time
are the sum of all resource allocations within an organization allowed to exceed
the overall organization quota.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
properties:
allocations:
description: Allocations are individual resource allocations.
items:
properties:
committed:
anyOf:
- type: integer
- type: string
description: |-
Committed resources are ones that are always present e.g. a baremetal server.
This is a hard allocation.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
kind:
description: Kind of resource e.g. "cluster" or "server".
type: string
reserved:
anyOf:
- type: integer
- type: string
description: |-
Reserved resources are ones that may or may not be present e.g. a server
that's part of an autoscaling group. This is a soft allocation and could
potentially be used as overcommit or burst capacity.
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
required:
- committed
- kind
- reserved
type: object
type: array
x-kubernetes-list-map-keys:
- kind
x-kubernetes-list-type: map
tags:
description: Tags are aribrary user data.
items:
description: Tag is an arbirary key/value.
properties:
name:
description: Name of the tag.
type: string
value:
description: Value of the tag.
type: string
required:
- name
- value
type: object
type: array
type: object
status:
type: object
required:
- spec
type: object
served: true
storage: true
subresources: {}
78 changes: 78 additions & 0 deletions charts/identity/crds/identity.unikorn-cloud.org_quotas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.3
name: quotas.identity.unikorn-cloud.org
spec:
group: identity.unikorn-cloud.org
names:
categories:
- unikorn
kind: Quota
listKind: QuotaList
plural: quotas
singular: quota
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: |-
Quota objects are defined per organization, and potentially in future subdivided
among projects that set limits on the quanity of arbitrary resources that can be
provisioned. The resources themselves are completely arbitrary and can conceivably
be used by 3rd party integrations.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
properties:
quotas:
description: Quotas are individual quotas.
items:
properties:
kind:
description: Kind of resource e.g. "cluster" or "server".
type: string
quantity:
anyOf:
- type: integer
- type: string
description: |-
Quantity of the resource, may be specified as an integer, a decimal
multiple (e,g, 10M), or a binary multiple (e.g. 10Mi).
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
required:
- kind
- quantity
type: object
type: array
x-kubernetes-list-map-keys:
- kind
x-kubernetes-list-type: map
type: object
status:
type: object
required:
- spec
type: object
served: true
storage: true
11 changes: 7 additions & 4 deletions charts/identity/templates/identity/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ rules:
- apiGroups:
- identity.unikorn-cloud.org
resources:
- allocations
- groups
- oauth2clients
- oauth2providers
- organizations
- users
- serviceaccounts
- roles
- groups
- projects
- quotas
- roles
- serviceaccounts
- users
verbs:
- list
- watch
Expand All @@ -37,6 +39,7 @@ rules:
resources:
- secrets
- configmaps
- namespaces
verbs:
- list
- watch
Expand Down
9 changes: 9 additions & 0 deletions charts/identity/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ roles:
identity:users: [create,read,update,delete]
identity:groups: [create,read,update,delete]
identity:projects: [create,read,update,delete]
identity:quotas: [create,read,update,delete]
identity:allocations: [create,read,update,delete]
region:regions: [create,read,update,delete]
region:flavors: [create,read,update,delete]
region:images: [create,read,update,delete]
Expand All @@ -115,6 +117,7 @@ roles:
decription: Infrastructure manager service
scopes:
global:
identity:allocations: [create,read,update,delete]
region:identities: [create,read,delete]
region:regions: [read]
region:flavors: [read]
Expand Down Expand Up @@ -143,6 +146,8 @@ roles:
identity:roles: [create,read,update,delete]
identity:groups: [create,read,update,delete]
identity:projects: [create,read,update,delete]
identity:quotas: [read]
identity:allocations: [read]
region:regions: [read]
kubernetes:flavors: [read]
kubernetes:images: [read]
Expand All @@ -158,6 +163,8 @@ roles:
description: Project user
scopes:
organization:
identity:quotas: [read]
identity:allocations: [read]
region:regions: [read]
kubernetes:flavors: [read]
kubernetes:images: [read]
Expand All @@ -175,6 +182,8 @@ roles:
description: Project reader
scopes:
organization:
identity:quotas: [read]
identity:allocations: [read]
region:regions: [read]
kubernetes:flavors: [read]
kubernetes:images: [read]
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.10.0
github.com/unikorn-cloud/core v0.1.89-rc3
github.com/unikorn-cloud/core v0.1.89-rc5
go.opentelemetry.io/otel v1.34.0
go.opentelemetry.io/otel/sdk v1.34.0
go.opentelemetry.io/otel/trace v1.34.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/unikorn-cloud/core v0.1.89-rc3 h1:SFsNCTfjQd9sawO7/6HFmNRacspfYG6SlVH8vF3Wy2U=
github.com/unikorn-cloud/core v0.1.89-rc3/go.mod h1:UW7g0AFLjY6r3KVPv9SPu/POttZx6Tl6UZ30+s4da+M=
github.com/unikorn-cloud/core v0.1.89-rc5 h1:DYT9DOO9gdqzN3U1cirxWDgvECN9vfPuZda7KQE86KI=
github.com/unikorn-cloud/core v0.1.89-rc5/go.mod h1:UW7g0AFLjY6r3KVPv9SPu/POttZx6Tl6UZ30+s4da+M=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/unikorn/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func init() {
SchemeBuilder.Register(&SigningKey{}, &SigningKeyList{})
SchemeBuilder.Register(&User{}, &UserList{})
SchemeBuilder.Register(&ServiceAccount{}, &ServiceAccountList{})
SchemeBuilder.Register(&Quota{}, &QuotaList{})
SchemeBuilder.Register(&Allocation{}, &AllocationList{})
}

// Resource maps a resource type to a group resource.
Expand Down
Loading

0 comments on commit 1c9b644

Please sign in to comment.