Skip to content

Commit

Permalink
Merge pull request #178 from unbroken-dome/feature/uninstall-cascade
Browse files Browse the repository at this point in the history
Support for helm uninstall cascade
  • Loading branch information
tkrullmann authored Sep 17, 2023
2 parents 751a3b7 + dcec9a3 commit c0d7491
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ subprojects {
if (maxParallelForks > 1) {
// Parallel tests seem to need a little more time to set up, so increase the test timeout to
// make sure that the first test in a forked process doesn't fail because of this
systemProperty("SPEK_TIMEOUT", 30000)
systemProperty("spek2.execution.test.timeout", 30000)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ open class HelmUninstall : AbstractHelmServerOperationCommandTask() {
project.objects.property()


/**
* Selects the deletion cascading strategy for the dependents. Valid values are `"background"`, `"orphan"` or
* `"foreground"`. Defaults to `"background"` if not set.
*
* Corresponds to the `--cascade` CLI parameter.
*/
@get:Internal
val cascade: Property<String> =
project.objects.property()


init {
onlyIf {
if (!doesReleaseExist()) {
Expand All @@ -64,6 +75,7 @@ open class HelmUninstall : AbstractHelmServerOperationCommandTask() {
flag("--dry-run", dryRun)
flag("--keep-history", keepHistory)
flag("--wait", wait)
option("--cascade", cascade)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ object HelmUninstallTest : ExecutionResultAwareSpek({
}
}

it("should use cascade property") {
task.cascade.set("foreground")

task.execute()

commandExecMock.singleInvocation {
expectCommand("uninstall")
expectOption("--cascade", "foreground")
expectArg("awesome-release")
}
}

it("should use wait property") {
task.wait.set(true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ interface HelmReleaseProperties : Named, ConfigurableHelmInstallFromRepositoryOp
*/
val keepHistoryOnUninstall: Property<Boolean>

/**
* Selects the deletion cascading strategy for the dependents when the release is uninstalled. Valid values are
* `"background"`, `"orphan"` or `"foreground"`. Defaults to `"background"` if not set.
*
* Corresponds to the `--cascade` CLI parameter on the `helm uninstall` command.
*/
val cascadeOnUninstall: Property<String>


/**
* Names of other releases that this release depends on.
Expand Down Expand Up @@ -506,6 +514,10 @@ private abstract class AbstractHelmRelease(
.convention(false)


final override val cascadeOnUninstall: Property<String> =
project.objects.property<String>()


@Deprecated(message = "use release tags instead")
@Suppress("OverridingDeprecatedMember")
final override val dependsOn: SetProperty<String> =
Expand Down Expand Up @@ -612,6 +624,7 @@ private open class DefaultHelmRelease
targetSpecific.replace.set(this.replace)
targetSpecific.historyMax.set(this.historyMax)
targetSpecific.keepHistoryOnUninstall.set(this.keepHistoryOnUninstall)
targetSpecific.cascadeOnUninstall.set(this.cascadeOnUninstall)
@Suppress("DEPRECATION")
targetSpecific.dependsOn.addAll(this.dependsOn)
targetSpecific.installDependsOn.addAll(this.installDependsOn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ internal class HelmUninstallReleaseFromTargetTaskRule(
setFrom(targetSpecific)
releaseName.set(targetSpecific.releaseName)
keepHistory.set(targetSpecific.keepHistoryOnUninstall)
cascade.set(targetSpecific.cascadeOnUninstall)
wait.set(targetSpecific.wait)

// Make sure all dependent releases are uninstalled first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ object HelmReleasesPluginTest : Spek({
propertyMappingInfo(
HelmRelease::keepHistoryOnUninstall, HelmUninstall::keepHistory, true
),
propertyMappingInfo(
HelmRelease::cascadeOnUninstall, HelmUninstall::cascade, "foreground"
),
propertyMappingInfo(HelmRelease::wait, HelmUninstall::wait, true)
)
}
Expand Down

0 comments on commit c0d7491

Please sign in to comment.