Skip to content

Commit

Permalink
Add support for specifying timeout in catalogs
Browse files Browse the repository at this point in the history
Since some chart may use more than the standard 5 min timeout that helm
is configured with to install.
Use string as type since there was some issues with using java.time.Duration and parsing with jackson.
  • Loading branch information
johnksv committed Sep 4, 2024
1 parent 5e48651 commit a601126
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void resume(
String version,
boolean dryRun,
final boolean skipTlsVerify,
String timeout,
String caFile)
throws InvalidExitValueException,
IOException,
Expand All @@ -58,6 +59,7 @@ public void resume(
null,
Map.of("global.suspend", "false"),
skipTlsVerify,
timeout,
caFile,
true);
}
Expand All @@ -70,6 +72,7 @@ public void suspend(
String version,
boolean dryRun,
final boolean skipTlsVerify,
String timeout,
String caFile)
throws InvalidExitValueException,
IOException,
Expand All @@ -86,6 +89,7 @@ public void suspend(
null,
Map.of("global.suspend", "true"),
skipTlsVerify,
timeout,
caFile,
true);
}
Expand All @@ -100,6 +104,7 @@ public HelmInstaller installChart(
File values,
Map<String, String> env,
final boolean skipTlsVerify,
String timeout,
String caFile)
throws InvalidExitValueException,
IOException,
Expand All @@ -116,6 +121,7 @@ public HelmInstaller installChart(
values,
env,
skipTlsVerify,
timeout,
caFile,
false);
}
Expand All @@ -130,6 +136,7 @@ public HelmInstaller installChart(
File values,
Map<String, String> env,
final boolean skipTlsVerify,
String timeout,
String caFile,
boolean reuseValues)
throws InvalidExitValueException,
Expand All @@ -138,6 +145,11 @@ public HelmInstaller installChart(
TimeoutException,
IllegalArgumentException {
StringBuilder command = new StringBuilder("helm upgrade --install --history-max 0 ");

if (timeout != null) {
command.append("--timeout " + timeout + " ");
}

if (skipTlsVerify) {
command.append("--insecure-skip-tls-verify ");
} else if (caFile != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public class CatalogWrapper {
@Schema(description = "Skip tls certificate checks for the repository")
private boolean skipTlsVerify;

@Schema(description = "value to wait for helm command to complete")
private String timeout;

@Schema(description = "Verify certificates of HTTPS-enabled servers using this CA bundle")
private String caFile;

Expand Down Expand Up @@ -199,6 +202,14 @@ public void setSkipTlsVerify(boolean skipTlsVerify) {
this.skipTlsVerify = skipTlsVerify;
}

public String getTimeout() {
return timeout;
}

public void setTimeout(String timeout) {
this.timeout = timeout;
}

public String getCaFile() {
return caFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class CatalogsConfiguration {

private List<CatalogWrapper> resolvedCatalogs;

private ObjectMapper mapper;
private final ObjectMapper mapper;

@Autowired
public CatalogsConfiguration(ObjectMapper mapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ private void suspendOrResume(Region region, Project project, String serviceId, b
user,
serviceId,
catalog.get().getSkipTlsVerify(),
catalog.get().getTimeout(),
catalog.get().getCaFile(),
false);
} else {
Expand All @@ -260,6 +261,7 @@ private void suspendOrResume(Region region, Project project, String serviceId, b
user,
serviceId,
catalog.get().getSkipTlsVerify(),
catalog.get().getTimeout(),
catalog.get().getCaFile(),
false);
}
Expand Down Expand Up @@ -473,10 +475,20 @@ private Collection<Object> publishApps(

boolean skipTlsVerify = catalog.getSkipTlsVerify();
String caFile = catalog.getCaFile();
String timeout = catalog.getTimeout();
Map<String, Object> fusion = new HashMap<>();
fusion.putAll((Map<String, Object>) requestDTO.getOptions());
return helmAppsService.installApp(
region, project, requestDTO, catalogId, pkg, user, fusion, skipTlsVerify, caFile);
region,
project,
requestDTO,
catalogId,
pkg,
user,
fusion,
skipTlsVerify,
timeout,
caFile);
}

public static class SuspendOrResumeRequestDTO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Collection<Object> installApp(
User user,
Map<String, Object> fusion,
final boolean skipTlsVerify,
String timeout,
final String caFile)
throws Exception;

Expand Down Expand Up @@ -69,6 +70,7 @@ void resume(
User user,
String serviceId,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean dryRun)
throws IOException, InterruptedException, TimeoutException;
Expand All @@ -82,6 +84,7 @@ void suspend(
User user,
String serviceId,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean dryRun)
throws IOException, InterruptedException, TimeoutException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public Collection<Object> installApp(
User user,
Map<String, Object> fusion,
final boolean skipTlsVerify,
String timeout,
final String caFile)
throws IOException, TimeoutException, InterruptedException {

Expand All @@ -123,6 +124,7 @@ public Collection<Object> installApp(
values,
null,
skipTlsVerify,
timeout,
caFile);
InstallServiceEvent installServiceEvent =
new InstallServiceEvent(
Expand Down Expand Up @@ -410,6 +412,7 @@ public void suspend(
User user,
String serviceId,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean dryRun)
throws IOException, InterruptedException, TimeoutException {
Expand All @@ -422,6 +425,7 @@ public void suspend(
user,
serviceId,
skipTlsVerify,
timeout,
caFile,
dryRun,
true);
Expand All @@ -437,6 +441,7 @@ public void resume(
User user,
String serviceId,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean dryRun)
throws IOException, InterruptedException, TimeoutException {
Expand All @@ -449,6 +454,7 @@ public void resume(
user,
serviceId,
skipTlsVerify,
timeout,
caFile,
dryRun,
false);
Expand All @@ -463,6 +469,7 @@ public void suspendOrResume(
User user,
String serviceId,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean dryRun,
boolean suspend)
Expand All @@ -479,6 +486,7 @@ public void suspendOrResume(
version,
dryRun,
skipTlsVerify,
timeout,
caFile);
} else {
getHelmInstallService()
Expand All @@ -490,6 +498,7 @@ public void suspendOrResume(
version,
dryRun,
skipTlsVerify,
timeout,
caFile);
}
SuspendResumeServiceEvent event =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fr.insee.onyxia.api.configuration.properties;

import static fr.insee.onyxia.api.util.TestUtils.getClassPathResource;
import static org.junit.jupiter.api.Assertions.*;

import com.fasterxml.jackson.databind.ObjectMapper;
import fr.insee.onyxia.api.configuration.CatalogWrapper;
import fr.insee.onyxia.api.configuration.CustomObjectMapper;
import java.util.List;
import org.junit.jupiter.api.Test;

class CatalogsConfigurationTest {

@Test
void shouldBeAbleToParseCatalogWithTimeout() throws Exception {
ObjectMapper objectMapper = new CustomObjectMapper().objectMapper();
String catalogWrapper = getClassPathResource("catalog-loader-test/catalog-wrapper.json5");

CatalogsConfiguration catalogsConfiguration = new CatalogsConfiguration(objectMapper);
catalogsConfiguration.setCatalogs(catalogWrapper);
catalogsConfiguration.load();
List<CatalogWrapper> resolvedCatalogs = catalogsConfiguration.getResolvedCatalogs();

assertEquals(1, resolvedCatalogs.size());
assertEquals("10m", resolvedCatalogs.getFirst().getTimeout());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This file is a json5-file, which onyxia-api should be able to parse to a CatalogWrapper list
[
{
"id": "ide",
"name": "IDE",
"description": "Services for datascientists.",
"maintainer": "[email protected]",
"location": "https://inseefrlab.github.io/helm-charts-interactive-services",
"status": "PROD",
"highlightedCharts": ["jupyter-python", "rstudio", "vscode-python"],
// Single quote should be supported
"timeout": '10m',
"type": 'helm',
/* block comment
over several
lines are supported */
"skipTlsVerify": false,
"caFile": null,
"allowSharing": false,
"visible": {
"user": true,
// Trailing comma is supported
"project": true,
},
"restrictions": [
{
"userAttribute": {
"key": "sub",
"match": "^onyxia.*"
}
}
]
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"status": "PROD",
"highlightedCharts": ["jupyter-python", "rstudio", "vscode-python"],
// Single quote should be supported
"timeout": '10m',
"type": 'helm',
/* block comment
over several
Expand Down

0 comments on commit a601126

Please sign in to comment.