Skip to content

Commit

Permalink
Remove old state upgrader code (#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhouston authored Oct 23, 2024
1 parent 3663c68 commit 895ce22
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 72 deletions.
50 changes: 3 additions & 47 deletions helm-framework/helm/resource_helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ import (
)

var (
_ resource.Resource = &HelmRelease{}
_ resource.ResourceWithUpgradeState = &HelmRelease{}
_ resource.ResourceWithModifyPlan = &HelmRelease{}
_ resource.ResourceWithImportState = &HelmRelease{}
_ resource.Resource = &HelmRelease{}
_ resource.ResourceWithModifyPlan = &HelmRelease{}
_ resource.ResourceWithImportState = &HelmRelease{}
)

type HelmRelease struct {
Expand Down Expand Up @@ -590,7 +589,6 @@ func (r *HelmRelease) Schema(ctx context.Context, req resource.SchemaRequest, re
},
},
},
// Indicating schema has undergone changes
Version: 1,
}
}
Expand All @@ -614,35 +612,6 @@ func (r *HelmRelease) Configure(ctx context.Context, req resource.ConfigureReque
r.meta = meta
}

// maps version 0 state to the upgrade function.
// If terraform detects data with version 0, we call upgrade to upgrade the state to the current schema version "1"
func (r *HelmRelease) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
0: {
StateUpgrader: stateUpgradeV0toV1,
},
}
}

func stateUpgradeV0toV1(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
var priorState map[string]interface{}
diags := req.State.Get(ctx, &priorState)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}

if priorState["pass_credentials"] == nil {
priorState["pass_credentials"] = false
}
if priorState["wait_for_jobs"] == nil {
priorState["wait_for_jobs"] = false
}

diags = resp.State.Set(ctx, priorState)
resp.Diagnostics.Append(diags...)
}

const sensitiveContentValue = "(sensitive value)"

func cloakSetValue(values map[string]interface{}, valuePath string) {
Expand Down Expand Up @@ -1664,19 +1633,6 @@ func checkChartDependencies(ctx context.Context, model *HelmReleaseModel, c *cha
return false, diags
}

func (r *HelmRelease) StateUpgrade(ctx context.Context, version int, state map[string]interface{}, meta interface{}) (map[string]interface{}, diag.Diagnostics) {
var diags diag.Diagnostics

if state["pass_credentials"] == nil {
state["pass_credentials"] = false
}
if state["wait_for_jobs"] == nil {
state["wait_for_jobs"] = false
}

return state, diags
}

func (r *HelmRelease) ModifyPlan(ctx context.Context, req resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
if req.Plan.Raw.IsNull() {
// resource is being destroyed
Expand Down
25 changes: 0 additions & 25 deletions helm-framework/helm/resource_helm_release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2098,31 +2098,6 @@ func removeSubcharts(chartName string) error {
return os.RemoveAll(chartsPath)
}

// func TestResourceExampleInstanceStateUpgradeV0(t *testing.T) {
// expected := map[string]any{
// "wait_for_jobs": false,
// "pass_credentials": false,
// }
// states := []map[string]any{
// {
// "wait_for_jobs": nil,
// "pass_credentials": nil,
// },
// {},
// }

// for _, state := range states {
// actual, err := stateUpgradeV0toV1(context.Background(), state, nil)
// if err != nil {
// t.Fatalf("error migrating state: %s", err)
// }

// if !reflect.DeepEqual(expected, actual) {
// t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", expected, actual)
// }
// }
// }

func testAccHelmReleaseSetListValues(resource, ns, name string) string {
return fmt.Sprintf(`
resource "helm_release" "%s" {
Expand Down

0 comments on commit 895ce22

Please sign in to comment.