github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/modules/helm/upgrade.go (about) 1 package helm 2 3 import ( 4 "path/filepath" 5 6 "github.com/gruntwork-io/go-commons/errors" 7 "github.com/gruntwork-io/terratest/modules/files" 8 "github.com/gruntwork-io/terratest/modules/testing" 9 "github.com/stretchr/testify/require" 10 ) 11 12 // Upgrade will upgrade the release and chart will be deployed with the lastest configuration. This will fail 13 // the test if there is an error. 14 func Upgrade(t testing.TestingT, options *Options, chart string, releaseName string) { 15 require.NoError(t, UpgradeE(t, options, chart, releaseName)) 16 } 17 18 // UpgradeE will upgrade the release and chart will be deployed with the lastest configuration. 19 func UpgradeE(t testing.TestingT, options *Options, chart string, releaseName string) error { 20 // If the chart refers to a path, convert to absolute path. Otherwise, pass straight through as it may be a remote 21 // chart. 22 if files.FileExists(chart) { 23 absChartDir, err := filepath.Abs(chart) 24 if err != nil { 25 return errors.WithStackTrace(err) 26 } 27 chart = absChartDir 28 } 29 30 var err error 31 args := []string{} 32 if options.ExtraArgs != nil { 33 if upgradeArgs, ok := options.ExtraArgs["upgrade"]; ok { 34 args = append(args, upgradeArgs...) 35 } 36 } 37 args, err = getValuesArgsE(t, options, args...) 38 if err != nil { 39 return err 40 } 41 42 args = append(args, "--install", releaseName, chart) 43 _, err = RunHelmCommandAndGetOutputE(t, options, "upgrade", args...) 44 return err 45 }