-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package io.kokuwa.maven.helm; | ||
|
||
import java.nio.file.Path; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import lombok.Setter; | ||
|
||
/** | ||
* Mojo for executing "helm uninstall". | ||
* | ||
* @author [email protected] | ||
* @see <a href="https://helm.sh/docs/helm/helm_uninstall">helm uninstall</a> | ||
* @since 6.10.0 | ||
*/ | ||
@Mojo(name = "uninstall", defaultPhase = LifecyclePhase.DEPLOY, threadSafe = true) | ||
@Setter | ||
public class UninstallMojo extends AbstractHelmWithValueOverrideMojo { | ||
|
||
/** | ||
* Must be "background", "orphan", or "foreground". Selects the deletion cascading strategy for the dependents. | ||
* Defaults to background. (default "background" from helm) | ||
* | ||
* @since 6.10.0 | ||
*/ | ||
@Parameter(property = "helm.uninstall.cascade") | ||
private String uninstallCascade; | ||
|
||
/** | ||
* Prevent hooks from running during uninstallation. | ||
* | ||
* @since 6.10.0 | ||
*/ | ||
@Parameter(property = "helm.uninstall.no-hooks", defaultValue = "false") | ||
private boolean uninstallNoHooks; | ||
|
||
/** | ||
* Remove all associated resources and mark the release as deleted, but retain the release history. | ||
* | ||
* @since 6.10.0 | ||
*/ | ||
@Parameter(property = "helm.uninstall.keep-history ", defaultValue = "false") | ||
private boolean uninstallKeepHistory; | ||
|
||
/** | ||
* If set, will wait until all the resources are deleted before returning. It will wait for as long | ||
* as"uninstallTimeout". | ||
* | ||
* @since 6.10.0 | ||
*/ | ||
@Parameter(property = "helm.uninstall.wait ", defaultValue = "false") | ||
private boolean uninstallWait; | ||
|
||
/** | ||
* Time to wait for any individual Kubernetes operation (like Jobs for hooks) (default 5m0s). | ||
* | ||
* @since 6.10.0 | ||
*/ | ||
@Parameter(property = "helm.uninstall.timeout") | ||
private Integer uninstallTimeout; | ||
|
||
/** | ||
* Set this to <code>true</code> to skip invoking uninstall goal. | ||
* | ||
* @since 6.10 | ||
*/ | ||
@Parameter(property = "helm.uninstall.skip", defaultValue = "true") | ||
private boolean skipUninstall; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException { | ||
|
||
if (skip || skipUninstall) { | ||
getLog().info("Skip uninstall"); | ||
return; | ||
} | ||
|
||
for (Path chartDirectory : getChartDirectories()) { | ||
getLog().info("Perform uninstall for chart " + chartDirectory); | ||
helm().arguments("uninstall", chartDirectory.getFileName().toString()) | ||
.flag("wait", uninstallWait) | ||
.flag("timeout", uninstallTimeout != null ? uninstallTimeout + "s" : null) | ||
.flag("cascade", uninstallCascade) | ||
.flag("no-hooks", uninstallNoHooks) | ||
.flag("keep-history", uninstallKeepHistory) | ||
.execute("Failed to deploy helm chart"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.kokuwa.maven.helm; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test for {@link UninstallMojoTest} | ||
* | ||
* @author [email protected] | ||
* @since 6.10.0 | ||
*/ | ||
@DisplayName("helm:uninstall") | ||
public class UninstallMojoTest extends AbstractMojoTest { | ||
|
||
@DisplayName("default values") | ||
@Test | ||
void install(UninstallMojo mojo) { | ||
mojo.setSkipUninstall(false); | ||
assertHelm(mojo, "uninstall simple"); | ||
} | ||
|
||
@DisplayName("with flag skip") | ||
@Test | ||
void skip(UninstallMojo mojo) { | ||
assertHelm(mojo); | ||
assertHelm(mojo.setSkipUninstall(false).setSkip(true)); | ||
assertHelm(mojo.setSkipUninstall(true).setSkip(false)); | ||
assertHelm(mojo.setSkipUninstall(true).setSkip(true)); | ||
} | ||
|
||
@DisplayName("with flag keep-history") | ||
@Test | ||
void keepHistory(UninstallMojo mojo) { | ||
mojo.setSkipUninstall(false); | ||
mojo.setUninstallKeepHistory(true); | ||
assertHelm(mojo, "uninstall simple --keep-history"); | ||
} | ||
|
||
@DisplayName("with flag no-hooks") | ||
@Test | ||
void noHooks(UninstallMojo mojo) { | ||
mojo.setSkipUninstall(false); | ||
mojo.setUninstallNoHooks(true); | ||
assertHelm(mojo, "uninstall simple --no-hooks"); | ||
} | ||
|
||
@DisplayName("with flags cascade background") | ||
@Test | ||
void cascade(UninstallMojo mojo) { | ||
mojo.setSkipUninstall(false); | ||
mojo.setUninstallCascade("background"); | ||
assertHelm(mojo, "uninstall simple --cascade background"); | ||
} | ||
|
||
@DisplayName("with flags wait and timeout") | ||
@Test | ||
void timeout(UninstallMojo mojo) { | ||
mojo.setSkipUninstall(false); | ||
mojo.setUninstallWait(true); | ||
mojo.setUninstallTimeout(41); | ||
assertHelm(mojo, "uninstall simple --wait --timeout 41s"); | ||
} | ||
} |