Provisioning: Enforce instance repository isolation (#109512)

* Fix validation on repository creation

* Fix linting

* Do not count the provided one

* Fix test

* Fix tests
This commit is contained in:
Roberto Jiménez Sánchez
2025-08-14 10:19:40 +00:00
committed by GitHub
parent dfae5e5b4d
commit ffc7508a46
4 changed files with 297 additions and 7 deletions
+19 -3
View File
@@ -612,15 +612,31 @@ func (b *APIBuilder) verifyAgaintsExistingRepositories(cfg *provisioning.Reposit
}
if cfg.Spec.Sync.Target == provisioning.SyncTargetTypeInstance {
// Instance sync can only be created if NO other repositories exist
for _, v := range all {
if v.Name != cfg.Name && v.Spec.Sync.Target == provisioning.SyncTargetTypeInstance {
if v.Name != cfg.Name {
return field.Forbidden(field.NewPath("spec", "sync", "target"),
"Another repository is already targeting root: "+v.Name)
"Instance repository can only be created when no other repositories exist. Found: "+v.Name)
}
}
} else {
// Folder sync cannot be created if an instance repository exists
for _, v := range all {
if v.Spec.Sync.Target == provisioning.SyncTargetTypeInstance {
return field.Forbidden(field.NewPath("spec", "sync", "target"),
"Cannot create folder repository when instance repository exists: "+v.Name)
}
}
}
if len(all) >= 10 {
// Count repositories excluding the current one being created/updated
count := 0
for _, v := range all {
if v.Name != cfg.Name {
count++
}
}
if count >= 10 {
return field.Forbidden(field.NewPath("spec"),
"Maximum number of 10 repositories reached")
}