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
  • Loading branch information
johnksv committed Sep 2, 2024
1 parent 5e48651 commit 4408435
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.github.inseefrlab.helmwrapper.utils.HelmReleaseInfoParser;
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -42,6 +43,7 @@ public void resume(
String version,
boolean dryRun,
final boolean skipTlsVerify,
Duration timeout,
String caFile)
throws InvalidExitValueException,
IOException,
Expand All @@ -58,6 +60,7 @@ public void resume(
null,
Map.of("global.suspend", "false"),
skipTlsVerify,
timeout,
caFile,
true);
}
Expand All @@ -70,6 +73,7 @@ public void suspend(
String version,
boolean dryRun,
final boolean skipTlsVerify,
Duration timeout,
String caFile)
throws InvalidExitValueException,
IOException,
Expand All @@ -86,6 +90,7 @@ public void suspend(
null,
Map.of("global.suspend", "true"),
skipTlsVerify,
timeout,
caFile,
true);
}
Expand All @@ -100,6 +105,7 @@ public HelmInstaller installChart(
File values,
Map<String, String> env,
final boolean skipTlsVerify,
Duration timeout,
String caFile)
throws InvalidExitValueException,
IOException,
Expand All @@ -116,6 +122,7 @@ public HelmInstaller installChart(
values,
env,
skipTlsVerify,
timeout,
caFile,
false);
}
Expand All @@ -130,6 +137,7 @@ public HelmInstaller installChart(
File values,
Map<String, String> env,
final boolean skipTlsVerify,
Duration timeout,
String caFile,
boolean reuseValues)
throws InvalidExitValueException,
Expand All @@ -138,6 +146,12 @@ public HelmInstaller installChart(
TimeoutException,
IllegalArgumentException {
StringBuilder command = new StringBuilder("helm upgrade --install --history-max 0 ");

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

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 @@ -7,6 +7,7 @@
import fr.insee.onyxia.model.catalog.CatalogStatus;
import fr.insee.onyxia.model.helm.Repository;
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -54,6 +55,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 Duration timeout;

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

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

public Duration getTimeout() {
return timeout;
}

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

public String getCaFile() {
return caFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
Expand Down Expand Up @@ -248,6 +249,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 +262,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 +476,20 @@ private Collection<Object> publishApps(

boolean skipTlsVerify = catalog.getSkipTlsVerify();
String caFile = catalog.getCaFile();
Duration 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 @@ -14,6 +14,7 @@
import io.github.inseefrlab.helmwrapper.service.HelmInstallService;
import java.io.IOException;
import java.text.ParseException;
import java.time.Duration;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
Expand All @@ -40,6 +41,7 @@ Collection<Object> installApp(
User user,
Map<String, Object> fusion,
final boolean skipTlsVerify,
Duration timeout,
final String caFile)
throws Exception;

Expand Down Expand Up @@ -69,6 +71,7 @@ void resume(
User user,
String serviceId,
boolean skipTlsVerify,
Duration timeout,
String caFile,
boolean dryRun)
throws IOException, InterruptedException, TimeoutException;
Expand All @@ -82,6 +85,7 @@ void suspend(
User user,
String serviceId,
boolean skipTlsVerify,
Duration timeout,
String caFile,
boolean dryRun)
throws IOException, InterruptedException, TimeoutException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -103,6 +104,7 @@ public Collection<Object> installApp(
User user,
Map<String, Object> fusion,
final boolean skipTlsVerify,
Duration timeout,
final String caFile)
throws IOException, TimeoutException, InterruptedException {

Expand All @@ -123,6 +125,7 @@ public Collection<Object> installApp(
values,
null,
skipTlsVerify,
timeout,
caFile);
InstallServiceEvent installServiceEvent =
new InstallServiceEvent(
Expand Down Expand Up @@ -410,6 +413,7 @@ public void suspend(
User user,
String serviceId,
boolean skipTlsVerify,
Duration timeout,
String caFile,
boolean dryRun)
throws IOException, InterruptedException, TimeoutException {
Expand All @@ -422,6 +426,7 @@ public void suspend(
user,
serviceId,
skipTlsVerify,
timeout,
caFile,
dryRun,
true);
Expand All @@ -437,6 +442,7 @@ public void resume(
User user,
String serviceId,
boolean skipTlsVerify,
Duration timeout,
String caFile,
boolean dryRun)
throws IOException, InterruptedException, TimeoutException {
Expand All @@ -449,6 +455,7 @@ public void resume(
user,
serviceId,
skipTlsVerify,
timeout,
caFile,
dryRun,
false);
Expand All @@ -463,6 +470,7 @@ public void suspendOrResume(
User user,
String serviceId,
boolean skipTlsVerify,
Duration timeout,
String caFile,
boolean dryRun,
boolean suspend)
Expand All @@ -479,6 +487,7 @@ public void suspendOrResume(
version,
dryRun,
skipTlsVerify,
timeout,
caFile);
} else {
getHelmInstallService()
Expand All @@ -490,6 +499,7 @@ public void suspendOrResume(
version,
dryRun,
skipTlsVerify,
timeout,
caFile);
}
SuspendResumeServiceEvent event =
Expand Down

0 comments on commit 4408435

Please sign in to comment.