Skip to content
Open
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
49 changes: 29 additions & 20 deletions docs/region-configuration.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.github.inseefrlab.helmwrapper.service;

public record HelmFlags(
boolean dryRun,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean reuseValues,
boolean forceConflicts,
String serverSide) {

public static HelmFlags suspendAndResumeFlags(
boolean dryRun,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean forceConflicts,
String serverSide) {
return new HelmFlags(
dryRun, skipTlsVerify, timeout, caFile, true, forceConflicts, serverSide);
}

public static HelmFlags installFlags(
boolean dryRun,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean forceConflicts,
String serverSide) {
return new HelmFlags(
dryRun, skipTlsVerify, timeout, caFile, false, forceConflicts, serverSide);
}

/**
* @return cli ready string to use for helm upgrade, ending with a space such that it is safe to
* further append on
*/
public String toHelmUpgradeCliString() {
StringBuilder result = new StringBuilder();
if (forceConflicts) {
result.append("--force-conflicts ");
}
if (serverSide != null) {
result.append(" --server-side " + serverSide + " ");
}

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

if (skipTlsVerify) {
result.append("--insecure-skip-tls-verify ");
} else if (caFile != null) {
result.append("--ca-file " + System.getenv("CACERTS_DIR") + "/" + caFile + " ");
}

if (dryRun) {
result.append("--dry-run ");
}
if (reuseValues) {
result.append("--reuse-values ");
}

return result.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,127 +38,23 @@ public class HelmInstallService {
private static final String MANIFEST_INFO_TYPE = "manifest";
private static final String NOTES_INFO_TYPE = "notes";

public void resume(
HelmConfiguration configuration,
String chart,
String namespace,
String name,
String version,
boolean dryRun,
final boolean skipTlsVerify,
String timeout,
String caFile)
throws InvalidExitValueException,
IOException,
InterruptedException,
TimeoutException,
IllegalArgumentException {
installChart(
configuration,
chart,
namespace,
name,
version,
dryRun,
null,
Map.of("global.suspend", "false"),
skipTlsVerify,
timeout,
caFile,
true);
}

public void suspend(
HelmConfiguration configuration,
String chart,
String namespace,
String name,
String version,
boolean dryRun,
final boolean skipTlsVerify,
String timeout,
String caFile)
throws InvalidExitValueException,
IOException,
InterruptedException,
TimeoutException,
IllegalArgumentException {
installChart(
configuration,
chart,
namespace,
name,
version,
dryRun,
null,
Map.of("global.suspend", "true"),
skipTlsVerify,
timeout,
caFile,
true);
}

public HelmInstaller installChart(
HelmConfiguration configuration,
String chart,
String namespace,
String name,
String version,
boolean dryRun,
File values,
Map<String, String> env,
final boolean skipTlsVerify,
String timeout,
String caFile)
throws InvalidExitValueException,
IOException,
InterruptedException,
TimeoutException,
IllegalArgumentException {
return installChart(
configuration,
chart,
namespace,
name,
version,
dryRun,
values,
env,
skipTlsVerify,
timeout,
caFile,
false);
}

public HelmInstaller installChart(
HelmConfiguration configuration,
String chart,
String namespace,
String name,
String version,
boolean dryRun,
File values,
Map<String, String> env,
final boolean skipTlsVerify,
String timeout,
String caFile,
boolean reuseValues)
HelmFlags additionalFlags)
throws InvalidExitValueException,
IOException,
InterruptedException,
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) {
command.append("--ca-file " + System.getenv("CACERTS_DIR") + "/" + caFile + " ");
}
command.append(additionalFlags.toHelmUpgradeCliString());

if (name != null) {
if (!helmNamePattern.matcher(name).matches() || name.length() > 53) {
Expand Down Expand Up @@ -196,12 +92,6 @@ public HelmInstaller installChart(
if (env != null) {
command.append(buildEnvVar(env));
}
if (dryRun) {
command.append(" --dry-run");
}
if (reuseValues) {
command.append(" --reuse-values");
}
String res =
Command.executeAndGetResponseAsJson(configuration, command.toString())
.getOutput()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.fabric8.kubernetes.client.WatcherException;
import io.github.inseefrlab.helmwrapper.service.HelmFlags;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
Expand Down Expand Up @@ -297,6 +298,14 @@ private void suspendOrResume(Region region, Project project, String serviceId, b
throw new IllegalStateException("Catalog " + catalogId + " is not available anymore");
}

var flags =
HelmFlags.suspendAndResumeFlags(
false,
catalog.get().getSkipTlsVerify(),
catalog.get().getTimeout(),
catalog.get().getCaFile(),
region.getServices().getHelm().getForceConflicts(),
region.getServices().getHelm().getServerSide());
if (suspend) {
helmAppsService.suspend(
region,
Expand All @@ -306,10 +315,7 @@ private void suspendOrResume(Region region, Project project, String serviceId, b
version,
user,
serviceId,
catalog.get().getSkipTlsVerify(),
catalog.get().getTimeout(),
catalog.get().getCaFile(),
false);
flags);
} else {
helmAppsService.resume(
region,
Expand All @@ -319,10 +325,7 @@ private void suspendOrResume(Region region, Project project, String serviceId, b
version,
user,
serviceId,
catalog.get().getSkipTlsVerify(),
catalog.get().getTimeout(),
catalog.get().getCaFile(),
false);
flags);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.fabric8.kubernetes.api.model.Event;
import io.fabric8.kubernetes.client.Watch;
import io.fabric8.kubernetes.client.Watcher;
import io.github.inseefrlab.helmwrapper.service.HelmFlags;
import io.github.inseefrlab.helmwrapper.service.HelmInstallService;
import java.io.IOException;
import java.text.ParseException;
Expand Down Expand Up @@ -69,10 +70,7 @@ void resume(
String version,
User user,
String serviceId,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean dryRun)
HelmFlags flags)
throws IOException, InterruptedException, TimeoutException;

void suspend(
Expand All @@ -83,9 +81,6 @@ void suspend(
String version,
User user,
String serviceId,
boolean skipTlsVerify,
String timeout,
String caFile,
boolean dryRun)
HelmFlags flags)
throws IOException, InterruptedException, TimeoutException;
}
Loading
Loading