Skip to content

Commit

Permalink
Add a runtime check for V3 migration (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
olevitt authored Sep 2, 2024
1 parent 63cf936 commit 928b131
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
});
}
}
4 changes: 0 additions & 4 deletions onyxia-api/src/main/resources/regions.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@
"count/pods": "52"
}
},
"defaultConfiguration": {
"IPProtection": false,
"networkPolicy": false
},
"expose": {
"domain": "fakedomain.kub.example.com",
"ingress": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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;
}
Expand Down

0 comments on commit 928b131

Please sign in to comment.