From 04570ac841bdce176998439803789ea811ca4d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rostislav=20St=C5=99=C3=ADbrn=C3=BD?= Date: Wed, 12 Jul 2023 19:45:50 +0200 Subject: [PATCH] helm:init - Adding "fallbackBinaryDownload" parameter. Controls whether a download should occur when local helm binary is not found/verified. --- README.md | 5 ++-- .../kokuwa/maven/helm/AbstractHelmMojo.java | 4 +++ .../java/io/kokuwa/maven/helm/InitMojo.java | 27 ++++++++++++++++--- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index abdee94c..536ddad7 100644 --- a/README.md +++ b/README.md @@ -272,8 +272,8 @@ Parameter | Type | User Property | Required | Description `` | string | helm.tmpDir | false | Directory where to store cached Github responses. Defaults to `${java.io.tmpdir}/helm-maven-plugin` `` | list of strings | helm.excludes | false | list of chart directories to exclude `` | 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` -`` | boolean | helm.autoDetectLocalHelmBinary | true | Controls whether the local binary should be auto-detected from `PATH` environment variable. If set to `false` the binary in `` is used. This property has no effect unless `` is set to `true`. -`` | string | helm.executableDirectory | false | directory of your helm installation (default: `${project.build.directory}/helm`) +`` | boolean | helm.autoDetectLocalHelmBinary | true | Controls whether the local binary should be auto-detected from `PATH` environment variable. If set to `false`, the binary in `` is used only. This property has no effect unless `` is set to `true`. +`` | string | helm.executableDirectory | false | directory of your helm installation (default: `${project.build.directory}/helm`). If defined, directory is used also for `` as a last resort. `` | string | helm.outputDirectory | false | chart output directory (default: `${project.build.directory}/helm/repo`) `` | boolean | helm.debug | false | add debug to helm `` | string | helm.registryConfig | false | path to the registry config file @@ -313,6 +313,7 @@ Parameter | Type | User Property | Required | Description `` | boolean | helm.template.generate-name | false | Generate the name (and omit the NAME parameter). `` | boolean | helm.push.caFile | false | Verify certificates of HTTPS-enabled servers using this CA bundle. `` | boolean | helm.push.insecure | false | Skip tls certificate checks for the chart upload. Also known as `helm push --insecure-skip-tls-verify` +`` | boolean | helm.fallbackBinaryDownload | Controls whether a download should occur when local helm binary is not found. This property has no effect unless `` is set to `true`. ## Packaging with the Helm Lifecycle diff --git a/src/main/java/io/kokuwa/maven/helm/AbstractHelmMojo.java b/src/main/java/io/kokuwa/maven/helm/AbstractHelmMojo.java index 425dd49c..05764b44 100644 --- a/src/main/java/io/kokuwa/maven/helm/AbstractHelmMojo.java +++ b/src/main/java/io/kokuwa/maven/helm/AbstractHelmMojo.java @@ -265,6 +265,10 @@ Path getHelmExecutablePath() throws MojoExecutionException { Stream 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()); } diff --git a/src/main/java/io/kokuwa/maven/helm/InitMojo.java b/src/main/java/io/kokuwa/maven/helm/InitMojo.java index e6666da2..4d7d52f2 100644 --- a/src/main/java/io/kokuwa/maven/helm/InitMojo.java +++ b/src/main/java/io/kokuwa/maven/helm/InitMojo.java @@ -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 true. + * + * @since 6.8.1 + */ + @Parameter(property = "helm.init.fallbackBinaryDownload", defaultValue = "false") + private boolean fallbackBinaryDownload; + @Override public void execute() throws MojoExecutionException { @@ -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(); }