func (i *Install) GetAllReleases() (releases []*release.Release, err error) {
	i.Config.SetNamespace("")
	return i.GetReleases()
}
GetAllReleases obtains the releases in all namespaces that we have access to.
package action
import (
	"bufio"
	"os"
	"strings"
	"github.com/pkg/errors"
	"github.com/Masterminds/log-go"
	logio "github.com/Masterminds/log-go/io"
	"github.com/Masterminds/semver/v3"
	"github.com/jinzhu/copier"
	pkg "github.com/rancher-sandbox/hypper/internal/package"
	"github.com/rancher-sandbox/hypper/internal/solver"
	"github.com/rancher-sandbox/hypper/pkg/cli"
	"github.com/rancher-sandbox/hypper/pkg/eyecandy"
	"github.com/rancher-sandbox/hypper/internal/third-party/helm/resolver"
	"github.com/rancher-sandbox/hypper/pkg/repo"
	"helm.sh/helm/v3/pkg/action"
	helmChart "helm.sh/helm/v3/pkg/chart"
	"helm.sh/helm/v3/pkg/chart/loader"
	"helm.sh/helm/v3/pkg/downloader"
	"helm.sh/helm/v3/pkg/getter"
	"helm.sh/helm/v3/pkg/release"
)
type optionalDepsStrategy int
const (
	OptionalDepsAll optionalDepsStrategy = iota
	OptionalDepsAsk
	OptionalDepsNone
)
type Install struct {
	*action.Install
	NoSharedDeps      bool
	OptionalDeps      optionalDepsStrategy
	NoCreateNamespace bool
	Config *Configuration
}
func NewInstall(cfg *Configuration) *Install {
	return &Install{
		Install: action.NewInstall(cfg.Configuration),
		Config:  cfg,
	}
}
func CheckDependencies(ch *helmChart.Chart, reqs []*helmChart.Dependency) error {
	return action.CheckDependencies(ch, reqs)
}
func (i *Install) Run(strategy solver.SolverStrategy,
	wantedChrt *helmChart.Chart, wantedChrtAbsPath string, vals map[string]interface{},
	settings *cli.EnvSettings, logger log.Logger) ([]*release.Release, error) {
	clientInstallForGetRels := NewInstall(i.Config)
	if err := copier.Copy(&clientInstallForGetRels, &i); err != nil {
		return nil, err
	}
	rels, err := clientInstallForGetRels.GetAllReleases()
	if err != nil {
		return nil, err
	}
	SetNamespace(i, wantedChrt, settings.Namespace(), settings.NamespaceFromFlag)
	if i.ReleaseName == "" {
		var err error
		i.ReleaseName, err = GetName(wantedChrt, i.NameTemplate)
		if err != nil {
			return nil, err
		}
	}
	version := i.ChartPathOptions.Version
	pinnedVer := pkg.Unknown
	if i.Version == "" {
		version = wantedChrt.Metadata.Version
		i.ChartPathOptions.Version = version
	} else {
		pinnedVer = pkg.Present
	}
	wantedPkg := pkg.NewPkg(i.ReleaseName, wantedChrt.Metadata.Name, version, i.Namespace,
		pkg.Unknown, pkg.Present, pinnedVer, i.ChartPathOptions.RepoURL, wantedChrtAbsPath)
	rf, err := repo.LoadFile(settings.EnvSettings.RepositoryConfig)
	if err != nil {
		if !os.IsNotExist(errors.Cause(err)) {
			return nil, err
		}
		logger.Debug("No repository present, continuing…")
	}
	s := solver.New(strategy, logger)
	err = i.BuildWorld(s.PkgDB, rf.Repositories, rels, wantedPkg, wantedChrt, settings, logger)
	if err != nil {
		return nil, err
	}
	s.PkgDB.DebugPrintDB(logger)
	wantedPkgInDB := solver.PkgDBInstance.GetPackageByFingerprint(wantedPkg.GetFingerPrint())
	switch i.OptionalDeps {
	case OptionalDepsAll:
		logger.Debugf("Promoting all optional deps of package %s to normal deps\n", wantedPkgInDB.GetFingerPrint())
		wantedPkgInDB.DependsRel = append(wantedPkgInDB.DependsRel, wantedPkgInDB.DependsOptionalRel...)
	case OptionalDepsNone:
		logger.Debugf("Disregarding all optional deps of package %s\n", wantedPkgInDB.GetFingerPrint())
	case OptionalDepsAsk:
		logger.Debugf("Asking for each optional deps of package %s if they should be promoted\n", wantedPkgInDB.GetFingerPrint())
		for _, rel := range wantedPkgInDB.DependsOptionalRel {
			reader := bufio.NewReader(os.Stdin)
			question := eyecandy.ESPrintf(settings.NoEmojis,
				":red_question_mark:Install optional shared dependency \"%s\" of chart \"%s\"?",
				rel.ReleaseName,
				wantedPkgInDB.ChartName,
			)
			if promptBool(question, reader, logger) {
				wantedPkgInDB.DependsRel = append(wantedPkgInDB.DependsRel, rel)
			}
		}
	}
	s.Solve(wantedPkgInDB)
	if s.IsSAT() {
		if len(s.PkgResultSet.ToInstall.Relations) != 0 {
			logger.Info("The following charts are going to be installed:")
			logger.Infof("%s\n", solver.PrintPkgTree(s.PkgResultSet.ToInstall))
		}
		installedRels, err := i.postOrderInstall(s.PkgResultSet.ToInstall, wantedPkgInDB, wantedChrt, vals, settings, logger)
		if err != nil {
			return installedRels, err
		}
		return installedRels, nil
	} else {
		incons := ""
		for _, incon := range s.PkgResultSet.Inconsistencies {
			incons = incons + incon
		}
		return make([]*release.Release, 0), errors.New(incons)
	}
}
func (i *Install) postOrderInstall(tr *solver.PkgTree,
	wantedPkg *pkg.Pkg, wantedChrt *helmChart.Chart, vals map[string]interface{},
	settings *cli.EnvSettings, logger log.Logger) (installedRels []*release.Release, err error) {
	for _, depTR := range tr.Relations {
		installedDeps, err := i.postOrderInstall(depTR, wantedPkg, wantedChrt, vals, settings, logger)
		if err != nil {
			return installedDeps, err
		}
		installedRels = append(installedRels, installedDeps...)
	}
	if i.NoSharedDeps && tr.Node.GetFingerPrint() != wantedPkg.GetFingerPrint() {
		logger.Infof(eyecandy.ESPrintf(settings.NoEmojis, ":next_track_button: Skipping dependency \"%s\", flag `no-shared-deps` has been set",
			tr.Node.ChartName))
	} else {
		rel, err := i.InstallPkg(tr.Node, wantedPkg, wantedChrt, vals, 0, settings, logger)
		if err != nil {
			return installedRels, err
		}
		installedRels = append(installedRels, rel)
	}
	return installedRels, err
}
func (i *Install) Chart(args []string) (string, error) {
	if len(args) > 2 {
		return args[1], errors.Errorf("expected at most two arguments, unexpected arguments: %v", strings.Join(args[2:], ", "))
	}
	if len(args) == 2 {
		return args[1], nil
	}
	return args[0], nil
}
func (i *Install) NameAndChart(args []string) (string, string, error) {
	return "", "", errors.New("NameAndChart() cannot be used")
}
func CheckIfInstallable(ch *helmChart.Chart) error {
	switch ch.Metadata.Type {
	case "", "application":
		return nil
	}
	return errors.Errorf("%s charts are not installable", ch.Metadata.Type)
}