Skip to content

Commit c406799

Browse files
committed
fix: sync quota values from tenant to resourcequota object
Signed-off-by: Dario Tranchitella <dario@tranchitella.eu>
1 parent 5e13ac9 commit c406799

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

api/v1beta2/tenant_annotations.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import (
1212
const (
1313
// Annotation name part must be no more than 63 characters.
1414
maxAnnotationLength = 63
15+
16+
HardCapsuleQuotaAnnotation = "quota.capsule.clastix.io/hard-"
17+
UsedCapsuleQuotaAnnotation = "quota.capsule.clastix.io/used-"
1518
)
1619

1720
func createAnnotation(format string, resource fmt.Stringer) (string, error) {
@@ -36,9 +39,9 @@ func createAnnotation(format string, resource fmt.Stringer) (string, error) {
3639
}
3740

3841
func UsedQuotaFor(resource fmt.Stringer) (string, error) {
39-
return createAnnotation("quota.capsule.clastix.io/used-", resource)
42+
return createAnnotation(UsedCapsuleQuotaAnnotation, resource)
4043
}
4144

4245
func HardQuotaFor(resource fmt.Stringer) (string, error) {
43-
return createAnnotation("quota.capsule.clastix.io/hard-", resource)
46+
return createAnnotation(HardCapsuleQuotaAnnotation, resource)
4447
}

controllers/tenant/resourcequotas.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"fmt"
99
"strconv"
10+
"strings"
1011

1112
"golang.org/x/sync/errgroup"
1213
corev1 "k8s.io/api/core/v1"
@@ -236,6 +237,16 @@ func (r *Manager) resourceQuotasUpdate(ctx context.Context, resourceName corev1.
236237
if found.Annotations == nil {
237238
found.Annotations = make(map[string]string)
238239
}
240+
// Pruning the Capsule quota annotations:
241+
// if the ResourceQuota is updated by removing some objects,
242+
// we could still have left-overs which could be misleading.
243+
// This will not lead to a reconciliation loop since the whole code is idempotent.
244+
for k := range found.Annotations {
245+
if strings.HasPrefix(k, capsulev1beta2.HardCapsuleQuotaAnnotation) || strings.HasPrefix(k, capsulev1beta2.UsedCapsuleQuotaAnnotation) {
246+
delete(found.Annotations, k)
247+
}
248+
}
249+
239250
found.Labels = rq.Labels
240251
if actualKey, keyErr := capsulev1beta2.UsedQuotaFor(resourceName); keyErr == nil {
241252
found.Annotations[actualKey] = actual.String()

0 commit comments

Comments
 (0)