Skip to content

Commit a6a5ca4

Browse files
Remove parameter from installation if parameter is removed from bundle (getporter#3012)
Remove installation parameter if parameter is removed from bundle 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 <kimworking@gmail.com>
1 parent d249b12 commit a6a5ca4

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

pkg/porter/parameters.go

+11
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,17 @@ func (p *Porter) applyActionOptionsToInstallation(ctx context.Context, ba Bundle
795795
inst.TrackBundle(bundleRef.Reference)
796796
inst.Status.Modified = time.Now()
797797

798+
// Remove installation parameters no longer present in the bundle
799+
if inst.Parameters.Parameters != nil {
800+
updatedInstParams := make(secrets.StrategyList, 0, len(inst.Parameters.Parameters))
801+
for _, param := range inst.Parameters.Parameters {
802+
if _, ok := bun.Parameters[param.Name]; ok {
803+
updatedInstParams = append(updatedInstParams, param)
804+
}
805+
}
806+
inst.Parameters.Parameters = updatedInstParams
807+
}
808+
798809
//
799810
// 1. Record the parameter and credential sets used on the installation
800811
// if none were specified, reuse the previous sets from the installation

pkg/porter/parameters_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"get.porter.sh/porter/pkg/cnab"
10+
"get.porter.sh/porter/pkg/config"
1011
"get.porter.sh/porter/pkg/printer"
1112
"get.porter.sh/porter/pkg/secrets"
1213
"get.porter.sh/porter/pkg/storage"
@@ -884,3 +885,35 @@ func TestPorter_ParametersApply(t *testing.T) {
884885
assert.Equal(t, "foo_secret", ps.Parameters[0].Source.Hint, "expected the foo parameter mapping to use foo_secret")
885886
})
886887
}
888+
889+
func TestParameterRemovedFromBundle(t *testing.T) {
890+
ctx := context.Background()
891+
p := NewTestPorter(t)
892+
p.TestConfig.TestContext.AddTestFile("testdata/porter.yaml", "porter.yaml")
893+
opts := InstallOptions{
894+
BundleExecutionOptions: &BundleExecutionOptions{
895+
Driver: "docker",
896+
BundleReferenceOptions: &BundleReferenceOptions{
897+
installationOptions: installationOptions{
898+
BundleDefinitionOptions: BundleDefinitionOptions{
899+
File: config.Name,
900+
},
901+
Name: "MyInstallation",
902+
},
903+
},
904+
},
905+
}
906+
907+
installation := storage.NewInstallation(opts.Namespace, opts.Name)
908+
installation.Parameters.Parameters = make([]secrets.SourceMap, 1)
909+
installation.Parameters.Parameters[0] = secrets.SourceMap{
910+
Name: "removedParam",
911+
Source: secrets.Source{
912+
Strategy: "value",
913+
Hint: "1",
914+
},
915+
}
916+
917+
err := p.applyActionOptionsToInstallation(ctx, opts, &installation)
918+
require.NoError(t, err)
919+
}

0 commit comments

Comments
 (0)