Skip to content

Commit 33cbf64

Browse files
authored
Allow enabling legacy namespace quota independent of usage profiles (#123)
1 parent 0c09073 commit 33cbf64

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ func main() {
8686
var namespaceMetadataValidatorEnabled bool
8787
flag.BoolVar(&namespaceMetadataValidatorEnabled, "namespace-metadata-validator-enabled", false, "Enable the NamespaceMetadataValidator webhook. Validates the metadata of a namespace.")
8888

89+
var legacyNamespaceQuotaEnabled bool
90+
flag.BoolVar(&legacyNamespaceQuotaEnabled, "legacy-namespace-quota-enabled", false, "Enable the legacy namespace quota controller. This controller is deprecated and will be removed in the future.")
91+
8992
var qps, burst int
9093
flag.IntVar(&qps, "qps", 20, "QPS to use for the controller-runtime client")
9194
flag.IntVar(&burst, "burst", 100, "Burst to use for the controller-runtime client")
@@ -241,15 +244,16 @@ func main() {
241244

242245
Skipper: psk,
243246

244-
SkipValidateQuota: disableUsageProfiles,
247+
SkipValidateQuota: disableUsageProfiles && !legacyNamespaceQuotaEnabled,
245248

246249
OrganizationLabel: conf.OrganizationLabel,
247250
UserDefaultOrganizationAnnotation: conf.UserDefaultOrganizationAnnotation,
248251

249252
SelectedProfile: selectedUsageProfile,
250253
QuotaOverrideNamespace: conf.QuotaOverrideNamespace,
251254

252-
LegacyNamespaceQuota: conf.LegacyNamespaceQuota,
255+
EnableLegacyNamespaceQuota: legacyNamespaceQuotaEnabled,
256+
LegacyNamespaceQuota: conf.LegacyNamespaceQuota,
253257
},
254258
})
255259

webhooks/namespace_quota_validator.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ type NamespaceQuotaValidator struct {
5050
// QuotaOverrideNamespace is the namespace in which the quota overrides are stored
5151
QuotaOverrideNamespace string
5252

53+
// EnableLegacyNamespaceQuota enables the legacy namespace quota.
54+
EnableLegacyNamespaceQuota bool
5355
// LegacyNamespaceQuota is the namespace quota for legacy mode.
5456
// It is used if no ZoneUsageProfile is selected.
5557
LegacyNamespaceQuota int
@@ -60,7 +62,7 @@ func (v *NamespaceQuotaValidator) Handle(ctx context.Context, req admission.Requ
6062
ctx = log.IntoContext(ctx, log.FromContext(ctx).
6163
WithName("webhook.validate-namespace-quota.appuio.io").
6264
WithValues("id", req.UID, "user", req.UserInfo.Username).
63-
WithValues("legacyMode", v.legacyMode()).
65+
WithValues("legacyMode", v.LegacyNamespaceQuota).
6466
WithValues("namespace", req.Namespace, "name", req.Name,
6567
"group", req.Kind.Group, "version", req.Kind.Version, "kind", req.Kind.Kind))
6668

@@ -117,7 +119,7 @@ func (v *NamespaceQuotaValidator) handle(ctx context.Context, req admission.Requ
117119
}
118120

119121
var nsCountLimit int
120-
if v.legacyMode() {
122+
if v.EnableLegacyNamespaceQuota {
121123
nsCountLimit = v.LegacyNamespaceQuota
122124
} else {
123125
if v.SelectedProfile == "" {
@@ -163,11 +165,6 @@ func (v *NamespaceQuotaValidator) handle(ctx context.Context, req admission.Requ
163165
return admission.Allowed("allowed")
164166
}
165167

166-
// legacyMode returns true if the legacy namespace quota is set and no ZoneUsageProfile is selected.
167-
func (v *NamespaceQuotaValidator) legacyMode() bool {
168-
return v.SelectedProfile == "" && v.LegacyNamespaceQuota > 0
169-
}
170-
171168
// logAdmissionResponse logs the admission response to the logger derived from the given context and returns it unchanged.
172169
func logAdmissionResponse(ctx context.Context, res admission.Response) admission.Response {
173170
l := log.FromContext(ctx)

webhooks/namespace_quota_validator_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ func TestNamespaceQuotaValidator_Handle(t *testing.T) {
344344
LegacyNamespaceQuota: test.legacyQuota,
345345
}
346346

347+
if test.legacyQuota > 0 {
348+
subject.EnableLegacyNamespaceQuota = true
349+
}
347350
if test.disableProfile {
348351
subject.SelectedProfile = ""
349352
}

0 commit comments

Comments
 (0)