@@ -3,7 +3,7 @@ package quota
33import (
44 "fmt"
55
6- apiv1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
6+ v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
77 adminv1 "github.com/acorn-io/runtime/pkg/apis/internal.admin.acorn.io/v1"
88 "github.com/acorn-io/runtime/pkg/labels"
99 corev1 "k8s.io/api/core/v1"
@@ -19,11 +19,11 @@ import (
1919// WaitForAllocation blocks the appInstance from being deployed until quota has been allocated on
2020// an associated QuotaRequest object.
2121func WaitForAllocation (req router.Request , resp router.Response ) error {
22- appInstance := req .Object .(* apiv1 .AppInstance )
22+ appInstance := req .Object .(* v1 .AppInstance )
2323
2424 // Create a condition setter for AppInstanceConditionQuota, which blocks the appInstance from being deployed
2525 // until quota has been allocated.
26- status := condition .Setter (appInstance , resp , apiv1 .AppInstanceConditionQuota )
26+ status := condition .Setter (appInstance , resp , v1 .AppInstanceConditionQuota )
2727
2828 // Don't do anything if quota isn't enabled for this project.
2929 enforced , err := isEnforced (req , appInstance .Namespace )
@@ -64,7 +64,7 @@ func WaitForAllocation(req router.Request, resp router.Response) error {
6464
6565// EnsureQuotaRequest ensures that the quota request exists and is up to date.
6666func EnsureQuotaRequest (req router.Request , resp router.Response ) error {
67- appInstance := req .Object .(* apiv1 .AppInstance )
67+ appInstance := req .Object .(* v1 .AppInstance )
6868
6969 // Don't do anything if quota isn't enabled for this project
7070 if enforced , err := isEnforced (req , appInstance .Namespace ); err != nil || ! enforced {
@@ -86,7 +86,7 @@ func EnsureQuotaRequest(req router.Request, resp router.Response) error {
8686 },
8787 }
8888
89- status := condition .Setter (appInstance , resp , apiv1 .AppInstanceConditionQuota )
89+ status := condition .Setter (appInstance , resp , v1 .AppInstanceConditionQuota )
9090
9191 // Add the more complex values to the quota request
9292 addContainers (app .Containers , quotaRequest )
@@ -106,14 +106,14 @@ func EnsureQuotaRequest(req router.Request, resp router.Response) error {
106106}
107107
108108// addContainers adds the number of containers and accounts for the scale of each container.
109- func addContainers (containers map [string ]apiv1 .Container , quotaRequest * adminv1.QuotaRequestInstance ) {
109+ func addContainers (containers map [string ]v1 .Container , quotaRequest * adminv1.QuotaRequestInstance ) {
110110 for _ , container := range containers {
111111 quotaRequest .Spec .Resources .Containers += replicas (container .Scale )
112112 }
113113}
114114
115115// addCompute adds the compute resources of the containers passed to the quota request.
116- func addCompute (containers map [string ]apiv1 .Container , appInstance * apiv1 .AppInstance , quotaRequest * adminv1.QuotaRequestInstance ) {
116+ func addCompute (containers map [string ]v1 .Container , appInstance * v1 .AppInstance , quotaRequest * adminv1.QuotaRequestInstance ) {
117117 // For each workload, add their memory/cpu requests to the quota request
118118 for name , container := range containers {
119119 var requirements corev1.ResourceRequirements
@@ -135,7 +135,7 @@ func addCompute(containers map[string]apiv1.Container, appInstance *apiv1.AppIns
135135}
136136
137137// addStorage adds the storage resources of the volumes passed to the quota request.
138- func addStorage (appInstance * apiv1 .AppInstance , quotaRequest * adminv1.QuotaRequestInstance ) error {
138+ func addStorage (appInstance * v1 .AppInstance , quotaRequest * adminv1.QuotaRequestInstance ) error {
139139 app := appInstance .Status .AppSpec
140140
141141 // Add the volume storage needed to the quota request. We only parse net new volumes, not
@@ -171,7 +171,7 @@ func addStorage(appInstance *apiv1.AppInstance, quotaRequest *adminv1.QuotaReque
171171
172172// boundVolumeSize determines if the specified volume will be bound to an existing one. If
173173// it will not be bound, the size of the new volume is returned.
174- func boundVolumeSize (name string , bindings []apiv1 .VolumeBinding ) (bool , apiv1 .Quantity ) {
174+ func boundVolumeSize (name string , bindings []v1 .VolumeBinding ) (bool , v1 .Quantity ) {
175175 for _ , binding := range bindings {
176176 if binding .Target == name && binding .Volume == "" {
177177 return true , binding .Size
@@ -181,7 +181,7 @@ func boundVolumeSize(name string, bindings []apiv1.VolumeBinding) (bool, apiv1.Q
181181}
182182
183183// boundSecret determines if the specified secret will be bound to an existing one.
184- func boundSecret (name string , bindings []apiv1 .SecretBinding ) bool {
184+ func boundSecret (name string , bindings []v1 .SecretBinding ) bool {
185185 for _ , binding := range bindings {
186186 if binding .Target == name && binding .Secret == "" {
187187 return true
@@ -190,10 +190,9 @@ func boundSecret(name string, bindings []apiv1.SecretBinding) bool {
190190 return false
191191}
192192
193- // isEnforced determines if the project has quota enabled .
193+ // isEnforced determines if the project requires quota enforcement .
194194func isEnforced (req router.Request , namespace string ) (bool , error ) {
195- // Use the underlying Namespace type that stores Projects
196- project := corev1.Namespace {}
195+ project := v1.ProjectInstance {}
197196 if err := req .Client .Get (req .Ctx , router .Key ("" , namespace ), & project ); err != nil {
198197 return false , err
199198 }
0 commit comments