Skip to content

Commit

Permalink
Quotas : add ignore annotation (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
olevitt authored Jul 22, 2024
1 parent 3647872 commit e0155f3
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -199,7 +200,7 @@ private void applyQuotas(
resourceQuotaBuilder
.withNewMetadata()
.withLabels(Map.of("createdby", "onyxia"))
.withName("onyxia-quota")
.withName(ONYXIA_QUOTA)
.withNamespace(namespaceId)
.endMetadata();

Expand All @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e0155f3

Please sign in to comment.