From 928b1312275d919831b90c462e0cc16a1864eadc Mon Sep 17 00:00:00 2001 From: Olivier Levitt Date: Mon, 2 Sep 2024 15:26:12 +0200 Subject: [PATCH] Add a runtime check for V3 migration (#484) --- .../api/configuration/checks/V3Checks.java | 43 +++++++++++++++++++ onyxia-api/src/main/resources/regions.json | 4 -- .../fr/insee/onyxia/model/region/Region.java | 16 +++++++ 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 onyxia-api/src/main/java/fr/insee/onyxia/api/configuration/checks/V3Checks.java diff --git a/onyxia-api/src/main/java/fr/insee/onyxia/api/configuration/checks/V3Checks.java b/onyxia-api/src/main/java/fr/insee/onyxia/api/configuration/checks/V3Checks.java new file mode 100644 index 00000000..7b897df6 --- /dev/null +++ b/onyxia-api/src/main/java/fr/insee/onyxia/api/configuration/checks/V3Checks.java @@ -0,0 +1,43 @@ +package fr.insee.onyxia.api.configuration.checks; + +import fr.insee.onyxia.api.configuration.properties.RegionsConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.context.event.EventListener; + +@Configuration +public class V3Checks { + + private static final Logger LOGGER = LoggerFactory.getLogger(V3Checks.class); + + private final RegionsConfiguration regionsConfiguration; + + private final Runnable exitHandler; + + @Autowired + public V3Checks(RegionsConfiguration regionsConfiguration) { + this(regionsConfiguration, () -> System.exit(0)); + } + + public V3Checks(RegionsConfiguration regionsConfiguration, Runnable exitHandler) { + this.regionsConfiguration = regionsConfiguration; + this.exitHandler = exitHandler; + } + + @EventListener(ContextRefreshedEvent.class) + public void checkDefaultConfigurationIsNoLongerSupported() { + regionsConfiguration + .getResolvedRegions() + .forEach( + region -> { + if (region.getServices().getDefaultConfiguration() != null) { + LOGGER.error( + "FATAL : Setting defaultConfiguration in region is no longer supported and has been replaced by JSONSchema support. See migration guide at https://docs.onyxia.sh/admin-doc/migration-guides/v8-greater-than-v9"); + exitHandler.run(); + } + }); + } +} diff --git a/onyxia-api/src/main/resources/regions.json b/onyxia-api/src/main/resources/regions.json index da9eca57..b8b9336c 100644 --- a/onyxia-api/src/main/resources/regions.json +++ b/onyxia-api/src/main/resources/regions.json @@ -49,10 +49,6 @@ "count/pods": "52" } }, - "defaultConfiguration": { - "IPProtection": false, - "networkPolicy": false - }, "expose": { "domain": "fakedomain.kub.example.com", "ingress": true, diff --git a/onyxia-model/src/main/java/fr/insee/onyxia/model/region/Region.java b/onyxia-model/src/main/java/fr/insee/onyxia/model/region/Region.java index 7e23209f..cb149c42 100644 --- a/onyxia-model/src/main/java/fr/insee/onyxia/model/region/Region.java +++ b/onyxia-model/src/main/java/fr/insee/onyxia/model/region/Region.java @@ -199,6 +199,14 @@ public static class Services { private Monitoring monitoring; private String allowedURIPattern = "^https://"; private Quotas quotas = new Quotas(); + + /*** + * @Deprecated since v3 + * Should no longer be used. If used, a check will fail at startup and crash the app. + * @See V3Checks + */ + private Object defaultConfiguration = null; + private K8sPublicEndpoint k8sPublicEndpoint = new K8sPublicEndpoint(); private NamespaceAnnotationsDynamic namespaceAnnotationsDynamic = @@ -212,6 +220,14 @@ public void setSingleNamespace(boolean singleNamespace) { this.singleNamespace = singleNamespace; } + public void setDefaultConfiguration(Object defaultConfiguration) { + this.defaultConfiguration = defaultConfiguration; + } + + public Object getDefaultConfiguration() { + return defaultConfiguration; + } + public boolean isAllowNamespaceCreation() { return allowNamespaceCreation; }