github.com/swisspost/terratest@v0.0.0-20230214120104-7ec6de2e1ae0/modules/helm/install.go (about)

     1  package helm
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/gruntwork-io/go-commons/errors"
     7  	"github.com/stretchr/testify/require"
     8  
     9  	"github.com/gruntwork-io/terratest/modules/files"
    10  	"github.com/gruntwork-io/terratest/modules/testing"
    11  )
    12  
    13  // Install will install the selected helm chart with the provided options under the given release name. This will fail
    14  // the test if there is an error.
    15  func Install(t testing.TestingT, options *Options, chart string, releaseName string) {
    16  	require.NoError(t, InstallE(t, options, chart, releaseName))
    17  }
    18  
    19  // InstallE will install the selected helm chart with the provided options under the given release name.
    20  func InstallE(t testing.TestingT, options *Options, chart string, releaseName string) error {
    21  	// If the chart refers to a path, convert to absolute path. Otherwise, pass straight through as it may be a remote
    22  	// chart.
    23  	if files.FileExists(chart) {
    24  		absChartDir, err := filepath.Abs(chart)
    25  		if err != nil {
    26  			return errors.WithStackTrace(err)
    27  		}
    28  		chart = absChartDir
    29  	}
    30  
    31  	// Now call out to helm install to install the charts with the provided options
    32  	// Declare err here so that we can update args later
    33  	var err error
    34  	args := []string{}
    35  	if options.ExtraArgs != nil {
    36  		if installArgs, ok := options.ExtraArgs["install"]; ok {
    37  			args = append(args, installArgs...)
    38  		}
    39  	}
    40  	if options.Version != "" {
    41  		args = append(args, "--version", options.Version)
    42  	}
    43  	args, err = getValuesArgsE(t, options, args...)
    44  	if err != nil {
    45  		return err
    46  	}
    47  	args = append(args, releaseName, chart)
    48  	_, err = RunHelmCommandAndGetOutputE(t, options, "install", args...)
    49  	return err
    50  }