Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying timeout in catalogs #481

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -235,6 +235,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 @@ -247,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);
}
Expand Down Expand Up @@ -449,10 +451,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 @@ -108,6 +108,7 @@ public Collection<Object> installApp(
User user,
Map<String, Object> fusion,
final boolean skipTlsVerify,
String timeout,
final String caFile)
throws IOException, TimeoutException, InterruptedException, ValidationException {

Expand Down Expand Up @@ -136,6 +137,7 @@ public Collection<Object> installApp(
values,
null,
skipTlsVerify,
timeout,
caFile);
InstallServiceEvent installServiceEvent =
new InstallServiceEvent(
Expand Down Expand Up @@ -422,6 +424,7 @@ public void suspend(
User user,
String serviceId,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean dryRun)
throws IOException, InterruptedException, TimeoutException {
Expand All @@ -434,6 +437,7 @@ public void suspend(
user,
serviceId,
skipTlsVerify,
timeout,
caFile,
dryRun,
true);
Expand All @@ -449,6 +453,7 @@ public void resume(
User user,
String serviceId,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean dryRun)
throws IOException, InterruptedException, TimeoutException {
Expand All @@ -461,6 +466,7 @@ public void resume(
user,
serviceId,
skipTlsVerify,
timeout,
caFile,
dryRun,
false);
Expand All @@ -475,6 +481,7 @@ public void suspendOrResume(
User user,
String serviceId,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean dryRun,
boolean suspend)
Expand All @@ -491,6 +498,7 @@ public void suspendOrResume(
version,
dryRun,
skipTlsVerify,
timeout,
caFile);
} else {
getHelmInstallService()
Expand All @@ -502,6 +510,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
Loading