func ListReleases(namespaces ...string) ([]*release.Release, error) {
	if namespaces == nil {
		namespaces = append(namespaces, "")
	}
	var arr []*release.Release
	config := new(action.Configuration)
	for _, namespace := range namespaces {
		if err := config.Init(nil, namespace, os.Getenv("HELM_DRIVER"), debug); err != nil {
			return nil, err
		}
		client := action.NewList(config)
		client.Deployed = true
		releases, err := client.Run()
		if err != nil {
			return nil, err
		}
		arr = append(arr, releases...)
	}
	return arr, nil
}
ListReleases returns a list of all the releases for the given namespaces.
Inputs: takes a list of namespaces to search releases in.
If empty string is given as input then returns all releases from all namespaces.
package helm
import (
	"context"
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"sync"
	"time"
	"github.com/gofrs/flock"
	"github.com/pkg/errors"
	"gopkg.in/yaml.v2"
	"helm.sh/helm/v3/pkg/action"
	"helm.sh/helm/v3/pkg/chart"
	"helm.sh/helm/v3/pkg/chart/loader"
	"helm.sh/helm/v3/pkg/cli"
	"helm.sh/helm/v3/pkg/downloader"
	"helm.sh/helm/v3/pkg/getter"
	"helm.sh/helm/v3/pkg/release"
	"helm.sh/helm/v3/pkg/repo"
	"helm.sh/helm/v3/pkg/storage/driver"
)
var settings *cli.EnvSettings = cli.New()
func AddRepoIfNotExist(repoName string, repoUrl string) error {
	repoFile := settings.RepositoryConfig
	err := os.MkdirAll(filepath.Dir(repoFile), os.ModePerm)
	if err != nil && !os.IsExist(err) {
		return err
	}
	fileLock := flock.New(strings.Replace(repoFile, filepath.Ext(repoFile), ".lock", 1))
	lockCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()
	locked, err := fileLock.TryLockContext(lockCtx, time.Second)
	if err == nil && locked {
		defer fileLock.Unlock()
	}
	if err != nil {
		return err
	}
	data, err := ioutil.ReadFile(repoFile)
	if err != nil && !os.IsNotExist(err) {
		return err
	}
	var file repo.File
	err = yaml.Unmarshal(data, &file)
	if err != nil {
		return err
	}
	if file.Has(repoName) {
		return nil
	}
	repoEntry := repo.Entry{
		Name: repoName,
		URL:  repoUrl,
	}
	repository, err := repo.NewChartRepository(&repoEntry, getter.All(settings))
	if err != nil {
		return err
	}
	if _, err := repository.DownloadIndexFile(); err != nil {
		err = errors.Wrap(err, "looks like "+repoUrl+" is not a valid chart repository or cannot be reached")
		return err
	}
	file.Update(&repoEntry)
	if err := file.WriteFile(repoFile, 0644); err != nil {
		return err
	}
	return nil
}