Skip to content

Commit 35c9114

Browse files
committed
feat: helm dry run server parameter
1 parent 11c63a0 commit 35c9114

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

docs/resources/release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ A Chart is a Helm package. It contains all of the resource definitions necessary
3131
- `disable_crd_hooks` (Boolean) Prevent CRD hooks from, running, but run other hooks. See helm install --no-crd-hook
3232
- `disable_openapi_validation` (Boolean) If set, the installation process will not validate rendered templates against the Kubernetes OpenAPI Schema. Defaults to `false`.
3333
- `disable_webhooks` (Boolean) Prevent hooks from running.Defaults to `false`.
34+
- `dry_run_option` (String) Use "server" to interact with remote apiserver while creating plan. Only used in experimental manifest mode.
3435
- `force_update` (Boolean) Force resource update through delete/recreate if needed. Defaults to `false`.
3536
- `keyring` (String) Location of public keys used for verification. Used only if `verify` is true. Defaults to `/.gnupg/pubring.gpg` in the location set by `home`.
3637
- `lint` (Boolean) Run helm lint when planning. Defaults to `false`.

helm/resource_release.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var defaultAttributes = map[string]interface{}{
4444
"render_subchart_notes": true,
4545
"disable_openapi_validation": false,
4646
"disable_crd_hooks": false,
47+
"dry_run_option": "",
4748
"force_update": false,
4849
"reset_values": false,
4950
"reuse_values": false,
@@ -250,6 +251,12 @@ func resourceRelease() *schema.Resource {
250251
Default: defaultAttributes["disable_crd_hooks"],
251252
Description: "Prevent CRD hooks from, running, but run other hooks. See helm install --no-crd-hook",
252253
},
254+
"dry_run_option": {
255+
Type: schema.TypeString,
256+
Optional: true,
257+
Default: defaultAttributes["dry_run_option"],
258+
Description: "When executing a dry run to render manifest in experiment mode, render manifest with remote interaction. See helm install --dry-run=server",
259+
},
253260
"reuse_values": {
254261
Type: schema.TypeBool,
255262
Optional: true,
@@ -942,6 +949,7 @@ func resourceDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{})
942949
install := action.NewInstall(actionConfig)
943950
install.ChartPathOptions = *cpo
944951
install.DryRun = true
952+
install.DryRunOption = d.Get("dry_run_option").(string)
945953
install.DisableHooks = d.Get("disable_webhooks").(bool)
946954
install.Wait = d.Get("wait").(bool)
947955
install.WaitForJobs = d.Get("wait_for_jobs").(bool)
@@ -1008,6 +1016,7 @@ func resourceDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{})
10081016
upgrade.Timeout = time.Duration(d.Get("timeout").(int)) * time.Second
10091017
upgrade.Wait = d.Get("wait").(bool)
10101018
upgrade.DryRun = true // do not apply changes
1019+
upgrade.DryRunOption = d.Get("dry_run_option").(string)
10111020
upgrade.DisableHooks = d.Get("disable_webhooks").(bool)
10121021
upgrade.Atomic = d.Get("atomic").(bool)
10131022
upgrade.SubNotes = d.Get("render_subchart_notes").(bool)

helm/resource_release_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,43 @@ func TestAccResourceRelease_manifest(t *testing.T) {
16281628
})
16291629
}
16301630

1631+
func TestAccResourceRelease_manifest_dry_run_enabled(t *testing.T) {
1632+
name := randName("diff")
1633+
namespace := createRandomNamespace(t)
1634+
defer deleteNamespace(t, namespace)
1635+
1636+
resource.Test(t, resource.TestCase{
1637+
PreCheck: func() {
1638+
testAccPreCheck(t)
1639+
},
1640+
ProviderFactories: map[string]func() (*schema.Provider, error){
1641+
"helm": func() (*schema.Provider, error) {
1642+
return Provider(), nil
1643+
},
1644+
},
1645+
CheckDestroy: testAccCheckHelmReleaseDestroy(namespace),
1646+
Steps: []resource.TestStep{
1647+
{
1648+
Config: testAccHelmReleaseConfigManifestExperimentEnabledDryRunServer(testResourceName, namespace, name, "1.2.3", "server"),
1649+
Check: resource.ComposeAggregateTestCheckFunc(
1650+
resource.TestCheckResourceAttr("helm_release.test", "metadata.0.name", name),
1651+
resource.TestCheckResourceAttr("helm_release.test", "metadata.0.namespace", namespace),
1652+
resource.TestCheckResourceAttr("helm_release.test", "metadata.0.version", "1.2.3"),
1653+
func(state *terraform.State) error {
1654+
// FIXME this is bordering on testing the implementation
1655+
t.Logf("getting JSON manifest for release %q", name)
1656+
m, err := getReleaseJSONManifest(namespace, name)
1657+
if err != nil {
1658+
t.Fatal(err.Error())
1659+
}
1660+
return resource.TestCheckResourceAttr("helm_release.test", "manifest", m)(state)
1661+
},
1662+
),
1663+
},
1664+
},
1665+
})
1666+
}
1667+
16311668
func TestAccResourceRelease_manifestUnknownValues(t *testing.T) {
16321669
name := "example"
16331670
namespace := createRandomNamespace(t)
@@ -2099,6 +2136,24 @@ func testAccHelmReleaseConfigManifestExperimentEnabled(resource, ns, name, versi
20992136
`, resource, name, ns, testRepositoryURL, version)
21002137
}
21012138

2139+
func testAccHelmReleaseConfigManifestExperimentEnabledDryRunServer(resource, ns, name, version string, dry_run_option string) string {
2140+
return fmt.Sprintf(`
2141+
provider helm {
2142+
experiments {
2143+
manifest = true
2144+
}
2145+
}
2146+
resource "helm_release" "%s" {
2147+
name = %q
2148+
namespace = %q
2149+
repository = %q
2150+
version = %q
2151+
chart = "test-chart"
2152+
dry_run_option = "%s"
2153+
}
2154+
`, resource, name, ns, testRepositoryURL, version, dry_run_option)
2155+
}
2156+
21022157
func testAccHelmReleaseConfigManifestUnknownValues(resource, ns, name, version string) string {
21032158
return fmt.Sprintf(`
21042159
provider helm {

0 commit comments

Comments
 (0)