Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit 0860841

Browse files
committed
Update quota request syncing
This change does three things: 1. Updates the baaah dependency to fix a race condition during controller start. This was affecting quota requests. 2. Changes an import name that was slightly confusing. 3. Changes the determination of checking if quota is enforced from checking namespaces (the old way) to checking project instances (the new way). Signed-off-by: Donnie Adams <donnie@acorn.io>
1 parent 243e5f9 commit 0860841

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ require (
1616
github.com/acorn-io/aml v0.0.0-20231009045340-a31c45f6d100
1717
github.com/acorn-io/aml/cli v0.0.0-20231009055509-3c83c1247cf8
1818
github.com/acorn-io/aml/legacy v0.0.0-20230929081514-1e9f3394432e
19-
github.com/acorn-io/baaah v0.0.0-20231006151510-91fb95b6997d
19+
github.com/acorn-io/baaah v0.0.0-20231009165317-af2b68361b8a
2020
github.com/acorn-io/mink v0.0.0-20230804175412-8d121aae112c
2121
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78
2222
github.com/acorn-io/z v0.0.0-20230714155009-a770ecbbdc45

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ github.com/acorn-io/aml/cli v0.0.0-20231009055509-3c83c1247cf8 h1:eQhRTIMBGbufCc
108108
github.com/acorn-io/aml/cli v0.0.0-20231009055509-3c83c1247cf8/go.mod h1:CQ8Bc6t6xgu/K8vU8rl5LBz45aTzTj1eL4yQYZy6zh8=
109109
github.com/acorn-io/aml/legacy v0.0.0-20230929081514-1e9f3394432e h1:W67DG9AcoNvBwIOR9OFUCZlSJBaHuvM2kXQ2+C6EnLk=
110110
github.com/acorn-io/aml/legacy v0.0.0-20230929081514-1e9f3394432e/go.mod h1:XnJZSZq/tG/jWPE/tmm2zy90gOZrJRIaOyKpoMulxfE=
111-
github.com/acorn-io/baaah v0.0.0-20231006151510-91fb95b6997d h1:6b7zZ4If/X0rT3j3MAXXnX/WIZMXfy+7YB8aruifwa4=
112-
github.com/acorn-io/baaah v0.0.0-20231006151510-91fb95b6997d/go.mod h1:1KSGxZt0E2MDedJESKUUYtxCwsJ3A+xZiw2QD8cVbjU=
111+
github.com/acorn-io/baaah v0.0.0-20231009165317-af2b68361b8a h1:0bHfiYUw4ojXCUfGHUPmRewrgJ/EpLQ4BaR4yEy8BC4=
112+
github.com/acorn-io/baaah v0.0.0-20231009165317-af2b68361b8a/go.mod h1:1KSGxZt0E2MDedJESKUUYtxCwsJ3A+xZiw2QD8cVbjU=
113113
github.com/acorn-io/cmd v0.0.0-20230929053520-ebe1b9879b38 h1:oJMGvI702ZW5L0JjJfGV9ekzU2IqqTGjmAQl4gkO6Ro=
114114
github.com/acorn-io/cmd v0.0.0-20230929053520-ebe1b9879b38/go.mod h1:bo9ONX4kagbQmXcG4bnfoK53MBFFtbUZ5fR7s9NfS+M=
115115
github.com/acorn-io/mink v0.0.0-20230804175412-8d121aae112c h1:3equCG9oMf2I5iDZxllb41jmNNSTiIpU3IegCHBtVyk=

pkg/controller/quota/quota.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package quota
33
import (
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.
2121
func 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.
6666
func 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.
194194
func 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

Comments
 (0)