diff --git a/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/kubernetes/KubernetesService.java b/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/kubernetes/KubernetesService.java index 4e265928..95688518 100644 --- a/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/kubernetes/KubernetesService.java +++ b/onyxia-api/src/main/java/fr/insee/onyxia/api/services/impl/kubernetes/KubernetesService.java @@ -32,6 +32,7 @@ public class KubernetesService { final OnyxiaEventPublisher onyxiaEventPublisher; private static final Logger LOGGER = LoggerFactory.getLogger(KubernetesService.class); + public static final String ONYXIA_QUOTA = "onyxia-quota"; @Autowired public KubernetesService( @@ -199,7 +200,7 @@ private void applyQuotas( resourceQuotaBuilder .withNewMetadata() .withLabels(Map.of("createdby", "onyxia")) - .withName("onyxia-quota") + .withName(ONYXIA_QUOTA) .withNamespace(namespaceId) .endMetadata(); @@ -219,6 +220,14 @@ private void applyQuotas( resourceQuotaBuilderSpecNested.endSpec(); final ResourceQuota quota = resourceQuotaBuilder.build(); + ResourceQuota resourceQuota = + kubClient.resourceQuotas().inNamespace(namespaceId).withName(ONYXIA_QUOTA).get(); + if (resourceQuota != null + && resourceQuota.getMetadata().getAnnotations().containsKey("onyxia_ignore")) { + // The annotation onyxia_ignore can be set to prevent Onyxia from managing this + // resourcequota + return; + } if (overrideExisting) { kubClient.resourceQuotas().inNamespace(namespaceId).createOrReplace(quota); } else { @@ -299,7 +308,7 @@ public void applyQuota(Region region, Project project, User user, Quota quota) { public ResourceQuota getOnyxiaQuota(Region region, Project project, User user) { final KubernetesClient kubClient = kubernetesClientProvider.getRootClient(region); final String namespace = determineNamespaceAndCreateIfNeeded(region, project, user); - return kubClient.resourceQuotas().inNamespace(namespace).withName("onyxia-quota").get(); + return kubClient.resourceQuotas().inNamespace(namespace).withName(ONYXIA_QUOTA).get(); } private String getSubjectKind(Owner owner) {