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

feat: helm dry run server parameter #1400

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/resources/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ A Chart is a Helm package. It contains all of the resource definitions necessary
- `disable_crd_hooks` (Boolean) Prevent CRD hooks from, running, but run other hooks. See helm install --no-crd-hook
- `disable_openapi_validation` (Boolean) If set, the installation process will not validate rendered templates against the Kubernetes OpenAPI Schema. Defaults to `false`.
- `disable_webhooks` (Boolean) Prevent hooks from running.Defaults to `false`.
- `dry_run_option` (String) Use "server" to interact with remote apiserver while creating plan. Only used in experimental manifest mode.
- `force_update` (Boolean) Force resource update through delete/recreate if needed. Defaults to `false`.
- `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`.
- `lint` (Boolean) Run helm lint when planning. Defaults to `false`.
Expand Down
9 changes: 9 additions & 0 deletions helm/resource_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var defaultAttributes = map[string]interface{}{
"render_subchart_notes": true,
"disable_openapi_validation": false,
"disable_crd_hooks": false,
"dry_run_option": "",
"force_update": false,
"reset_values": false,
"reuse_values": false,
Expand Down Expand Up @@ -250,6 +251,12 @@ func resourceRelease() *schema.Resource {
Default: defaultAttributes["disable_crd_hooks"],
Description: "Prevent CRD hooks from, running, but run other hooks. See helm install --no-crd-hook",
},
"dry_run_option": {
Type: schema.TypeString,
Optional: true,
Default: defaultAttributes["dry_run_option"],
Description: "When executing a dry run to render manifest in experiment mode, render manifest with remote interaction. See helm install --dry-run=server",
},
"reuse_values": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -942,6 +949,7 @@ func resourceDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{})
install := action.NewInstall(actionConfig)
install.ChartPathOptions = *cpo
install.DryRun = true
install.DryRunOption = d.Get("dry_run_option").(string)
install.DisableHooks = d.Get("disable_webhooks").(bool)
install.Wait = d.Get("wait").(bool)
install.WaitForJobs = d.Get("wait_for_jobs").(bool)
Expand Down Expand Up @@ -1008,6 +1016,7 @@ func resourceDiff(ctx context.Context, d *schema.ResourceDiff, meta interface{})
upgrade.Timeout = time.Duration(d.Get("timeout").(int)) * time.Second
upgrade.Wait = d.Get("wait").(bool)
upgrade.DryRun = true // do not apply changes
upgrade.DryRunOption = d.Get("dry_run_option").(string)
upgrade.DisableHooks = d.Get("disable_webhooks").(bool)
upgrade.Atomic = d.Get("atomic").(bool)
upgrade.SubNotes = d.Get("render_subchart_notes").(bool)
Expand Down
55 changes: 55 additions & 0 deletions helm/resource_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,43 @@ func TestAccResourceRelease_manifest(t *testing.T) {
})
}

func TestAccResourceRelease_manifest_dry_run_enabled(t *testing.T) {
name := randName("diff")
namespace := createRandomNamespace(t)
defer deleteNamespace(t, namespace)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
ProviderFactories: map[string]func() (*schema.Provider, error){
"helm": func() (*schema.Provider, error) {
return Provider(), nil
},
},
CheckDestroy: testAccCheckHelmReleaseDestroy(namespace),
Steps: []resource.TestStep{
{
Config: testAccHelmReleaseConfigManifestExperimentEnabledDryRunServer(testResourceName, namespace, name, "1.2.3", "server"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("helm_release.test", "metadata.0.name", name),
resource.TestCheckResourceAttr("helm_release.test", "metadata.0.namespace", namespace),
resource.TestCheckResourceAttr("helm_release.test", "metadata.0.version", "1.2.3"),
func(state *terraform.State) error {
// FIXME this is bordering on testing the implementation
t.Logf("getting JSON manifest for release %q", name)
m, err := getReleaseJSONManifest(namespace, name)
if err != nil {
t.Fatal(err.Error())
}
return resource.TestCheckResourceAttr("helm_release.test", "manifest", m)(state)
},
),
},
},
})
}

func TestAccResourceRelease_manifestUnknownValues(t *testing.T) {
name := "example"
namespace := createRandomNamespace(t)
Expand Down Expand Up @@ -2099,6 +2136,24 @@ func testAccHelmReleaseConfigManifestExperimentEnabled(resource, ns, name, versi
`, resource, name, ns, testRepositoryURL, version)
}

func testAccHelmReleaseConfigManifestExperimentEnabledDryRunServer(resource, ns, name, version string, dry_run_option string) string {
return fmt.Sprintf(`
provider helm {
experiments {
manifest = true
}
}
resource "helm_release" "%s" {
name = %q
namespace = %q
repository = %q
version = %q
chart = "test-chart"
dry_run_option = "%s"
}
`, resource, name, ns, testRepositoryURL, version, dry_run_option)
}

func testAccHelmReleaseConfigManifestUnknownValues(resource, ns, name, version string) string {
return fmt.Sprintf(`
provider helm {
Expand Down
Loading