Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed quotas cap #875

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions operators/cmd/tenant-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

clv1alpha1 "github.com/netgroup-polito/CrownLabs/operators/api/v1alpha1"
clv1alpha2 "github.com/netgroup-polito/CrownLabs/operators/api/v1alpha2"
"github.com/netgroup-polito/CrownLabs/operators/pkg/forge"
controllers "github.com/netgroup-polito/CrownLabs/operators/pkg/tenant-controller"
"github.com/netgroup-polito/CrownLabs/operators/pkg/tenantwh"
"github.com/netgroup-polito/CrownLabs/operators/pkg/utils/args"
Expand Down Expand Up @@ -99,6 +100,9 @@ func main() {
flag.Var(&mydrivePVCsSize, "mydrive-pvcs-size", "The dimension of the user's personal space")
flag.StringVar(&mydrivePVCsStorageClassName, "mydrive-pvcs-storage-class-name", "rook-nfs", "The name for the user's storage class")
flag.StringVar(&myDrivePVCsNamespace, "mydrive-pvcs-namespace", "mydrive-pvcs", "The namespace where the PVCs are created")
flag.IntVar(&forge.CapInstance, "cap-instance", 10, "The cap number of instances that can be requested by a Tenant.")
flag.IntVar(&forge.CapCPU, "cap-cpu", 25, "The cap amount of CPU cores that can be requested by a Tenant.")
flag.IntVar(&forge.CapMemoryGiga, "cap-memory-giga", 50, "The cap amount of RAM memory in gigabytes that can be requested by a Tenant.")

klog.InitFlags(nil)
flag.Parse()
Expand Down
3 changes: 3 additions & 0 deletions operators/deploy/tenant-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ spec:
- "--mydrive-pvcs-size={{ .Values.configurations.mydrivePVCsSize }}"
- "--mydrive-pvcs-storage-class-name={{ .Values.configurations.mydrivePVCsStorageClassName }}"
- "--mydrive-pvcs-namespace={{ .Values.configurations.mydrivePVCsNamespace }}"
- "--cap-instance={{ .Values.configurations.tenant.resourcecaps.instances }}"
- "--cap-cpu={{ .Values.configurations.tenant.resourcecaps.cpu }}"
- "--cap-memory-giga={{ .Values.configurations.tenant.resourcecaps.memory }}"
ports:
- name: metrics
containerPort: 8080
Expand Down
8 changes: 8 additions & 0 deletions operators/deploy/tenant-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ configurations:
maxConcurrentReconciles: 1
sandboxClusterRole: crownlabs-sandbox
tenantNamespaceKeepAlive: 168h
tenant:
resourcecaps:
# Maximum number of virtual cpus that can be requested by a tenant. 0 means unlimited.
cpu: 25
# Maximum amount of memory that can be requested by a tenant (expressed in GB). 0 means unlimited.
memory: 50
# Maximum number of instances that can be created by a tenant. 0 means unlimited.
instances: 10

image:
repository: crownlabs/tenant-operator
Expand Down
26 changes: 16 additions & 10 deletions operators/pkg/forge/resourcequota.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ import (
const (
// InstancesCountKey -> The key for accessing at the total number of instances in the corev1.ResourceList map.
InstancesCountKey = "count/instances.crownlabs.polito.it"

// CapInstance -> The cap number of instances that can be requested by a Tenant.
CapInstance = 10
)

var (
// CapCPU -> The cap amount of CPU cores that can be requested by a Tenant.
CapCPU = *resource.NewQuantity(25, resource.DecimalSI)
// CapInstance -> The maximum number of instances that can be started by a Tenant.
CapInstance int

// CapCPU -> The total amount of CPU cores that can be requested by a Tenant.
CapCPU int

// CapMemory -> The cap amount of RAM memory that can be requested by a Tenant.
CapMemory = *resource.NewScaledQuantity(50, resource.Giga)
// CapMemoryGiga -> The total amount of RAM (in gigabytes) that can be requested by a Tenant.
CapMemoryGiga int

// SandboxCPUQuota -> The maximum amount of CPU cores that can be used by a sandbox namespace.
SandboxCPUQuota = *resource.NewQuantity(4, resource.DecimalSI)
Expand All @@ -62,9 +62,15 @@ func TenantResourceList(workspaces []clv1alpha1.Workspace, override *clv1alpha2.
quota.Instances += workspaces[i].Spec.Quota.Instances
}

quota.CPU = CapResourceQuantity(quota.CPU, CapCPU)
quota.Memory = CapResourceQuantity(quota.Memory, CapMemory)
quota.Instances = CapIntegerQuantity(quota.Instances, CapInstance)
if CapCPU > 0 {
quota.CPU = CapResourceQuantity(quota.CPU, *resource.NewQuantity(int64(CapCPU), resource.DecimalSI))
}
if CapMemoryGiga > 0 {
quota.Memory = CapResourceQuantity(quota.Memory, *resource.NewScaledQuantity(int64(CapMemoryGiga), resource.Giga))
}
if CapInstance > 0 {
quota.Instances = CapIntegerQuantity(quota.Instances, uint32(CapInstance))
}

return quota
}
Expand Down
3 changes: 3 additions & 0 deletions operators/pkg/forge/resourcequota_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ var _ = Describe("Resource quota spec forging", func() {
sampleWorkspace1.Spec.Quota = quota1
sampleWorkspace2.Spec.Quota = quota2
workspaces = append(workspaces, sampleWorkspace1, sampleWorkspace2)
forge.CapCPU = 25
forge.CapMemoryGiga = 40
forge.CapInstance = 5
})

JustBeforeEach(func() {
Expand Down
Loading