github.com/verrazzano/verrazzano@v1.7.0/pkg/helm/testhelper.go (about)

     1  // Copyright (c) 2023, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package helm
     5  
     6  import (
     7  	"github.com/verrazzano/verrazzano/pkg/log/vzlog"
     8  	"helm.sh/helm/v3/pkg/action"
     9  	"helm.sh/helm/v3/pkg/chartutil"
    10  	"helm.sh/helm/v3/pkg/kube/fake"
    11  	"helm.sh/helm/v3/pkg/registry"
    12  	"helm.sh/helm/v3/pkg/release"
    13  	"helm.sh/helm/v3/pkg/storage"
    14  	"helm.sh/helm/v3/pkg/storage/driver"
    15  	"io"
    16  )
    17  
    18  type CreateReleaseFnType func(name string, releaseStatus release.Status) *release.Release
    19  
    20  func CreateActionConfig(includeRelease bool, releaseName string, releaseStatus release.Status, log vzlog.VerrazzanoLogger, createReleaseFn CreateReleaseFnType) (*action.Configuration, error) {
    21  
    22  	registryClient, err := registry.NewClient()
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  
    27  	cfg := &action.Configuration{
    28  		Releases:       storage.Init(driver.NewMemory()),
    29  		KubeClient:     &fake.FailingKubeClient{PrintingKubeClient: fake.PrintingKubeClient{Out: io.Discard}},
    30  		Capabilities:   chartutil.DefaultCapabilities,
    31  		RegistryClient: registryClient,
    32  		Log:            log.Infof,
    33  	}
    34  	if includeRelease {
    35  		testRelease := createReleaseFn(releaseName, releaseStatus)
    36  		err = cfg.Releases.Create(testRelease)
    37  		if err != nil {
    38  			return nil, err
    39  		}
    40  	}
    41  	return cfg, nil
    42  }