Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for --history-max parameter to helm upgrade #148

Merged
merged 2 commits into from
Nov 10, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ open class HelmInstallOrUpgrade : AbstractHelmInstallationCommandTask() {
project.objects.property()


/**
* Limit the maximum number of revisions saved per release.
*
* Use `0` for no limit. If not set, the default value from Helm (currently `10`) is used.
*
* Corresponds to the `--history-max` parameter of the `helm upgrade` CLI command.
*
* If [replace] is set to `true`, this property will be ignored.
*/
@get:Internal
val historyMax: Property<Int> =
project.objects.property()


@TaskAction
fun installOrUpgrade() {

Expand All @@ -70,6 +84,7 @@ open class HelmInstallOrUpgrade : AbstractHelmInstallationCommandTask() {
flag("--install")
flag("--reset-values", resetValues)
flag("--reuse-values", reuseValues)
option("--history-max", historyMax)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.unbrokendome.gradle.pluginutils.property
*/
open class HelmUpgrade : AbstractHelmInstallationCommandTask() {


/**
* If `true`, run an install if a release by this name doesn't already exist.
*/
Expand Down Expand Up @@ -41,6 +40,18 @@ open class HelmUpgrade : AbstractHelmInstallationCommandTask() {
project.objects.property()


/**
* Limit the maximum number of revisions saved per release.
*
* Use `0` for no limit. If not set, the default value from Helm (currently `10`) is used.
*
* Corresponds to the `--history-max` parameter of the `helm upgrade` CLI command.
*/
@get:Internal
val historyMax: Property<Int> =
project.objects.property()


@TaskAction
fun upgradeRelease() {
execHelm("upgrade") {
Expand All @@ -50,6 +61,7 @@ open class HelmUpgrade : AbstractHelmInstallationCommandTask() {
flag("--install", install)
flag("--reset-values", resetValues)
flag("--reuse-values", reuseValues)
option("--history-max", historyMax)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,50 +42,58 @@ object HelmUpgradeTest : ExecutionResultAwareSpek({
expectArg("custom/awesome")
}
}
}
}


it("should use install property") {
describe("executing a HelmUpgrade task") {
it("should use install property") {

task.install.set(true)
task.install.set(true)

task.execute()
task.execute()

execMock.singleInvocation {
expectCommand("upgrade")
expectFlag("--install")
expectArg("awesome-release")
expectArg("custom/awesome")
}
execMock.singleInvocation {
expectCommand("upgrade")
expectFlag("--install")
}
}


it("should use reuseValues property") {
it("should use reuseValues property") {

task.reuseValues.set(true)
task.reuseValues.set(true)

task.execute()
task.execute()

execMock.singleInvocation {
expectCommand("upgrade")
expectFlag("--reuse-values")
expectArg("awesome-release")
expectArg("custom/awesome")
}
execMock.singleInvocation {
expectCommand("upgrade")
expectFlag("--reuse-values")
}
}


it("should use resetValues property") {
it("should use resetValues property") {

task.resetValues.set(true)
task.resetValues.set(true)

task.execute()
task.execute()

execMock.singleInvocation {
expectCommand("upgrade")
expectFlag("--reset-values")
expectArg("awesome-release")
expectArg("custom/awesome")
}
execMock.singleInvocation {
expectCommand("upgrade")
expectFlag("--reset-values")
}
}

it("should use resetValues property") {

task.historyMax.set(42)

task.execute()

execMock.singleInvocation {
expectCommand("upgrade")
expectOption("--history-max", "42")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package org.unbrokendome.gradle.plugins.helm.release.dsl

import org.gradle.api.Action
import org.gradle.api.Named
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.*
import org.gradle.api.file.Directory
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFile
Expand All @@ -15,20 +11,10 @@ import org.gradle.api.provider.SetProperty
import org.slf4j.LoggerFactory
import org.unbrokendome.gradle.plugins.helm.command.ConfigurableHelmInstallFromRepositoryOptions
import org.unbrokendome.gradle.plugins.helm.command.ConfigurableHelmValueOptions
import org.unbrokendome.gradle.plugins.helm.command.internal.HelmInstallFromRepositoryOptionsHolder
import org.unbrokendome.gradle.plugins.helm.command.internal.HelmValueOptionsHolder
import org.unbrokendome.gradle.plugins.helm.command.internal.mergeValues
import org.unbrokendome.gradle.plugins.helm.command.internal.setFrom
import org.unbrokendome.gradle.plugins.helm.command.internal.withDefaults
import org.unbrokendome.gradle.plugins.helm.command.internal.*
import org.unbrokendome.gradle.plugins.helm.dsl.HelmChart
import org.unbrokendome.gradle.plugins.helm.rules.ChartDirArtifactRule
import org.unbrokendome.gradle.pluginutils.andThen
import org.unbrokendome.gradle.pluginutils.asFile
import org.unbrokendome.gradle.pluginutils.capitalizeWords
import org.unbrokendome.gradle.pluginutils.combine
import org.unbrokendome.gradle.pluginutils.listProperty
import org.unbrokendome.gradle.pluginutils.property
import org.unbrokendome.gradle.pluginutils.setProperty
import org.unbrokendome.gradle.pluginutils.*
import java.io.File
import java.net.URI
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -135,6 +121,18 @@ interface HelmReleaseProperties : Named, ConfigurableHelmInstallFromRepositoryOp
val replace: Property<Boolean>


/**
* Limit the maximum number of revisions saved per release.
*
* Use `0` for no limit. If not set, the default value from Helm (currently `10`) is used.
*
* Corresponds to the `--history-max` parameter of the `helm upgrade` CLI command.
*
* If [replace] is set to `true`, this property will be ignored.
*/
val historyMax: Property<Int>


/**
* If `true`, the associated `helmUninstall` task will retain the release history
* (using the `--keep-history` flag).
Expand Down Expand Up @@ -515,6 +513,10 @@ private abstract class AbstractHelmRelease(
.convention(false)


final override val historyMax: Property<Int> =
project.objects.property()


final override val keepHistoryOnUninstall: Property<Boolean> =
project.objects.property<Boolean>()
.convention(false)
Expand Down Expand Up @@ -623,6 +625,7 @@ private open class DefaultHelmRelease
targetSpecific.releaseName.set(this.releaseName)
targetSpecific.chart.set(this.chart)
targetSpecific.replace.set(this.replace)
targetSpecific.historyMax.set(this.historyMax)
targetSpecific.keepHistoryOnUninstall.set(this.keepHistoryOnUninstall)
@Suppress("DEPRECATION")
targetSpecific.dependsOn.addAll(this.dependsOn)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ internal class HelmInstallReleaseToTargetTaskRule(
chart.set(targetSpecific.chart.map { it.chartLocation })
version.set(targetSpecific.version)
replace.set(targetSpecific.replace)
historyMax.set(targetSpecific.historyMax)

dependsOn(targetSpecific.chart)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,10 @@ import org.unbrokendome.gradle.plugins.helm.command.tasks.HelmInstallOrUpgrade
import org.unbrokendome.gradle.plugins.helm.command.tasks.HelmTest
import org.unbrokendome.gradle.plugins.helm.command.tasks.HelmUninstall
import org.unbrokendome.gradle.plugins.helm.dsl.internal.helm
import org.unbrokendome.gradle.plugins.helm.release.dsl.HelmRelease
import org.unbrokendome.gradle.plugins.helm.release.dsl.HelmReleaseTarget
import org.unbrokendome.gradle.plugins.helm.release.dsl.activeReleaseTarget
import org.unbrokendome.gradle.plugins.helm.release.dsl.releaseTargets
import org.unbrokendome.gradle.plugins.helm.release.dsl.releases
import org.unbrokendome.gradle.plugins.helm.release.dsl.*
import org.unbrokendome.gradle.plugins.helm.release.spek.propertyMappingInfo
import org.unbrokendome.gradle.plugins.helm.release.spek.propertyMappingTests
import org.unbrokendome.gradle.pluginutils.test.assertions.assertk.cast
import org.unbrokendome.gradle.pluginutils.test.assertions.assertk.containsTask
import org.unbrokendome.gradle.pluginutils.test.assertions.assertk.doesNotContainItem
import org.unbrokendome.gradle.pluginutils.test.assertions.assertk.doesNotHaveTaskDependency
import org.unbrokendome.gradle.pluginutils.test.assertions.assertk.hasExtension
import org.unbrokendome.gradle.pluginutils.test.assertions.assertk.hasExtensionNamed
import org.unbrokendome.gradle.pluginutils.test.assertions.assertk.hasOnlyTaskDependency
import org.unbrokendome.gradle.pluginutils.test.assertions.assertk.hasTaskDependency
import org.unbrokendome.gradle.pluginutils.test.assertions.assertk.hasValueEqualTo
import org.unbrokendome.gradle.pluginutils.test.assertions.assertk.*
import org.unbrokendome.gradle.pluginutils.test.evaluate
import org.unbrokendome.gradle.pluginutils.test.spek.applyPlugin
import org.unbrokendome.gradle.pluginutils.test.spek.setupGradleProject
Expand Down Expand Up @@ -220,7 +208,9 @@ object HelmReleasesPluginTest : Spek({
propertyMappingInfo(HelmRelease::password, HelmInstallOrUpgrade::password, "topsecret"),
propertyMappingInfo(HelmRelease::caFile, HelmInstallOrUpgrade::caFile, "ca.pem"),
propertyMappingInfo(HelmRelease::certFile, HelmInstallOrUpgrade::certFile, "cert.pem"),
propertyMappingInfo(HelmRelease::keyFile, HelmInstallOrUpgrade::keyFile, "key.pem")
propertyMappingInfo(HelmRelease::keyFile, HelmInstallOrUpgrade::keyFile, "key.pem"),
propertyMappingInfo(HelmRelease::replace, HelmInstallOrUpgrade::replace, true),
propertyMappingInfo(HelmRelease::historyMax, HelmInstallOrUpgrade::historyMax, 42)
)
}

Expand Down