Skip to content

Commit

Permalink
Remove installation parameter if parameter is removed from bundle
Browse files Browse the repository at this point in the history
Otherwise it is not possible to upgrade to a version of bundle where
parameters are removed since the last installation.

Signed-off-by: Kim Christensen <[email protected]>
  • Loading branch information
kichristensen committed Mar 10, 2024
1 parent 55a0faa commit fee4f53
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/porter/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,17 @@ func (p *Porter) applyActionOptionsToInstallation(ctx context.Context, ba Bundle
inst.TrackBundle(bundleRef.Reference)
inst.Status.Modified = time.Now()

// Remove installation parameters no longer present in the bundle
if inst.Parameters.Parameters != nil {
updatedInstParams := make(secrets.StrategyList, 0, len(inst.Parameters.Parameters))
for _, param := range inst.Parameters.Parameters {
if _, ok := bun.Parameters[param.Name]; ok {
updatedInstParams = append(updatedInstParams, param)
}
}
inst.Parameters.Parameters = updatedInstParams
}

//
// 1. Record the parameter and credential sets used on the installation
// if none were specified, reuse the previous sets from the installation
Expand Down
33 changes: 33 additions & 0 deletions pkg/porter/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"get.porter.sh/porter/pkg/cnab"
"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/printer"
"get.porter.sh/porter/pkg/secrets"
"get.porter.sh/porter/pkg/storage"
Expand Down Expand Up @@ -884,3 +885,35 @@ func TestPorter_ParametersApply(t *testing.T) {
assert.Equal(t, "foo_secret", ps.Parameters[0].Source.Hint, "expected the foo parameter mapping to use foo_secret")
})
}

func TestParameterRemovedFromBundle(t *testing.T) {
ctx := context.Background()
p := NewTestPorter(t)
p.TestConfig.TestContext.AddTestFile("testdata/porter.yaml", "porter.yaml")
opts := InstallOptions{
BundleExecutionOptions: &BundleExecutionOptions{
Driver: "docker",
BundleReferenceOptions: &BundleReferenceOptions{
installationOptions: installationOptions{
BundleDefinitionOptions: BundleDefinitionOptions{
File: config.Name,
},
Name: "MyInstallation",
},
},
},
}

installation := storage.NewInstallation(opts.Namespace, opts.Name)
installation.Parameters.Parameters = make([]secrets.SourceMap, 1)
installation.Parameters.Parameters[0] = secrets.SourceMap{
Name: "removedParam",
Source: secrets.Source{
Strategy: "value",
Hint: "1",
},
}

err := p.applyActionOptionsToInstallation(ctx, opts, &installation)
require.NoError(t, err)
}

0 comments on commit fee4f53

Please sign in to comment.