Skip to content

Commit

Permalink
helm:init - Adding "fallbackBinaryDownload" parameter. Controls wheth…
Browse files Browse the repository at this point in the history
…er a download should occur when local helm binary is not found/verified.
  • Loading branch information
rstribrny committed Jul 12, 2023
1 parent 9468a1b commit 04570ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ Parameter | Type | User Property | Required | Description
`<tmpDir>` | string | helm.tmpDir | false | Directory where to store cached Github responses. Defaults to `${java.io.tmpdir}/helm-maven-plugin`
`<excludes>` | list of strings | helm.excludes | false | list of chart directories to exclude
`<useLocalHelmBinary>` | boolean | helm.useLocalHelmBinary | false | Controls whether a local binary should be used instead of downloading it. If set to `true` path has to be set with property `executableDirectory`
`<autoDetectLocalHelmBinary>` | boolean | helm.autoDetectLocalHelmBinary | true | Controls whether the local binary should be auto-detected from `PATH` environment variable. If set to `false` the binary in `<helmExecutableDirectory>` is used. This property has no effect unless `<useLocalHelmBinary>` is set to `true`.
`<helmExecutableDirectory>` | string | helm.executableDirectory | false | directory of your helm installation (default: `${project.build.directory}/helm`)
`<autoDetectLocalHelmBinary>` | boolean | helm.autoDetectLocalHelmBinary | true | Controls whether the local binary should be auto-detected from `PATH` environment variable. If set to `false`, the binary in `<helmExecutableDirectory>` is used only. This property has no effect unless `<useLocalHelmBinary>` is set to `true`.
`<helmExecutableDirectory>` | string | helm.executableDirectory | false | directory of your helm installation (default: `${project.build.directory}/helm`). If defined, directory is used also for `<autoDetectLocalHelmBinary>` as a last resort.
`<outputDirectory>` | string | helm.outputDirectory | false | chart output directory (default: `${project.build.directory}/helm/repo`)
`<debug>` | boolean | helm.debug | false | add debug to helm
`<registryConfig>` | string | helm.registryConfig | false | path to the registry config file
Expand Down Expand Up @@ -313,6 +313,7 @@ Parameter | Type | User Property | Required | Description
`<templateGenerateName>` | boolean | helm.template.generate-name | false | Generate the name (and omit the NAME parameter).
`<caFile>` | boolean | helm.push.caFile | false | Verify certificates of HTTPS-enabled servers using this CA bundle.
`<insecure>` | boolean | helm.push.insecure | false | Skip tls certificate checks for the chart upload. Also known as `helm push --insecure-skip-tls-verify`
`<fallbackBinaryDownload>` | boolean | helm.fallbackBinaryDownload | Controls whether a download should occur when local helm binary is not found. This property has no effect unless `<useLocalHelmBinary>` is set to `true`.

## Packaging with the Helm Lifecycle

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/kokuwa/maven/helm/AbstractHelmMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ Path getHelmExecutablePath() throws MojoExecutionException {
Stream<Path> optional;
if (useLocalHelmBinary && autoDetectLocalHelmBinary) {
optional = Stream.of(System.getenv("PATH").split(Pattern.quote(File.pathSeparator))).map(Paths::get);
if (helmExecutableDirectory != null) {
// if defined, search also in helm executable directory (eg. used for fallback binary download)
optional = Stream.concat(optional, Stream.of(helmExecutableDirectory.toPath()));
}
} else {
optional = Stream.of(helmExecutableDirectory.toPath());
}
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/io/kokuwa/maven/helm/InitMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ public class InitMojo extends AbstractHelmMojo {
@Parameter(property = "helm.downloadServerId")
private String helmDownloadServerId;

/**
* Controls whether a download should occur when local helm binary is not found. This property has no effect unless
* "helm.useLocalHelmBinary" is set to <code>true</code>.
*
* @since 6.8.1
*/
@Parameter(property = "helm.init.fallbackBinaryDownload", defaultValue = "false")
private boolean fallbackBinaryDownload;

@Override
public void execute() throws MojoExecutionException {

Expand All @@ -146,10 +155,22 @@ public void execute() throws MojoExecutionException {
}
}

boolean performDownload = true;
if (isUseLocalHelmBinary()) {
verifyLocalHelmBinary();
getLog().info("Using local HELM binary [" + getHelmExecutablePath() + "]");
} else {
try {
verifyLocalHelmBinary();
getLog().info("Using local HELM binary [" + getHelmExecutablePath() + "]");
performDownload = false;
} catch (Exception e) {
if (fallbackBinaryDownload) {
getLog().info("Local HELM not verified => falling back to binary download");
} else {
getLog().debug("Skipping fallback binary download");
throw e;
}
}
}
if (performDownload) {
downloadAndUnpackHelm();
}

Expand Down

0 comments on commit 04570ac

Please sign in to comment.