Go Format fix

Signed-off-by: Vaibhav Sharma <17532va@gmail.com>
pull/11674/head
Vaibhav Sharma 3 years ago
parent 93add79311
commit 55f35060cb

@ -19,7 +19,6 @@ package action
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"log"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -46,17 +45,6 @@ import (
"helm.sh/helm/v3/pkg/time" "helm.sh/helm/v3/pkg/time"
) )
func init() {
log.SetFlags(log.Lshortfile)
}
func debug(format string, v ...interface{}) {
if settings.Debug {
format = fmt.Sprintf("[debug] %s\n", format)
log.Output(2, fmt.Sprintf(format, v...))
}
}
// Timestamper is a function capable of producing a timestamp.Timestamper. // Timestamper is a function capable of producing a timestamp.Timestamper.
// //
// By default, this is a time.Time function from the Helm time package. This can // By default, this is a time.Time function from the Helm time package. This can
@ -113,7 +101,6 @@ type Configuration struct {
// //
// TODO: This function is badly in need of a refactor. // TODO: This function is badly in need of a refactor.
// TODO: As part of the refactor the duplicate code in cmd/helm/template.go should be removed // TODO: As part of the refactor the duplicate code in cmd/helm/template.go should be removed
//
// This code has to do with writing files to disk. // This code has to do with writing files to disk.
func (cfg *Configuration) renderResources(ch *chart.Chart, values chartutil.Values, releaseName, outputDir string, subNotes, useReleaseName, includeCrds bool, pr postrender.PostRenderer, dryRun bool) ([]*release.Hook, *bytes.Buffer, string, error) { func (cfg *Configuration) renderResources(ch *chart.Chart, values chartutil.Values, releaseName, outputDir string, subNotes, useReleaseName, includeCrds bool, pr postrender.PostRenderer, dryRun bool) ([]*release.Hook, *bytes.Buffer, string, error) {
hs := []*release.Hook{} hs := []*release.Hook{}

@ -17,9 +17,9 @@ limitations under the License.
package action package action
import ( import (
"os"
"path" "path"
"regexp" "regexp"
"strings"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
@ -155,9 +155,12 @@ func (l *List) Run() ([]*release.Release, error) {
} }
if l.AllNamespaces { if l.AllNamespaces {
if err := l.cfg.Init(settings.RESTClientGetter(), "", os.Getenv("HELM_DRIVER"), debug); err != nil { // For Empty Namespace the default behavior is to get all namespaces
clonedCfg, err := l.cfg.CloneWithNewNamespace("")
if err != nil {
return nil, err return nil, err
} }
l.cfg = clonedCfg
} }
var filter *regexp.Regexp var filter *regexp.Regexp
@ -332,3 +335,15 @@ func (l *List) SetStateMask() {
l.StateMask = state l.StateMask = state
} }
// Create a clone of the config with a new namespace
func (cfg *Configuration) CloneWithNewNamespace(namespace string) (*Configuration, error) {
newConf := &Configuration{}
newConf.Releases = cfg.Releases
getter := settings.RESTClientGetter()
helmDriver := strings.ToLower(cfg.Releases.Driver.Name()) //note: Driver.Name() returns capitalized driver names.
err := newConf.Init(getter, namespace, helmDriver, cfg.Log)
return newConf, err
}

@ -17,13 +17,14 @@ limitations under the License.
package action package action
import ( import (
"os"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"helm.sh/helm/v3/pkg/release" "helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/storage" "helm.sh/helm/v3/pkg/storage"
"helm.sh/helm/v3/pkg/storage/driver"
) )
func TestListStates(t *testing.T) { func TestListStates(t *testing.T) {
@ -80,13 +81,15 @@ func TestList_OneNamespace(t *testing.T) {
func TestList_AllNamespaces(t *testing.T) { func TestList_AllNamespaces(t *testing.T) {
is := assert.New(t) is := assert.New(t)
lister := newListFixture(t) lister := newListFixture(t)
makeMeSomeReleasesWithDifferentNamespaces(lister.cfg.Releases, t) originalCfg := lister.cfg
lister.cfg.Releases.Driver = driver.NewMemory()
lister.AllNamespaces = true lister.AllNamespaces = true
lister.SetStateMask() makeMeSomeReleasesWithDifferentNamespaces(lister.cfg.Releases, t)
os.Setenv("HELM_DRIVER", "memory")
list, err := lister.Run() list, err := lister.Run()
is.NoError(err) is.NoError(err)
is.Len(list, 3) is.Len(list, 3)
// Checking if the config was cloned
assert.NotEqualValues(t, originalCfg, lister.cfg)
} }
func TestList_Sort(t *testing.T) { func TestList_Sort(t *testing.T) {
@ -294,24 +297,23 @@ func makeMeSomeReleasesWithDifferentNamespaces(store *storage.Storage, t *testin
one.Name = "one" one.Name = "one"
one.Namespace = "default1" one.Namespace = "default1"
one.Version = 1 one.Version = 1
one.SetStatus(release.StatusDeployed, "")
two := releaseStub() two := releaseStub()
two.Name = "two" two.Name = "two"
two.Namespace = "default2" two.Namespace = "default2"
two.Version = 2 two.Version = 2
two.SetStatus(release.StatusDeployed, "")
three := releaseStub() three := releaseStub()
three.Name = "three" three.Name = "three"
three.Namespace = "default3" three.Namespace = "default3"
three.Version = 3 three.Version = 3
three.SetStatus(release.StatusDeployed, "")
for _, rel := range []*release.Release{one, two, three} { for _, rel := range []*release.Release{one, two, three} {
if err := store.Create(rel); err != nil { if err := store.Create(rel); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
_, err := store.ListDeployed()
assert.NoError(t, err)
//assert.Len(t, all, 3, "sanity test: three items added")
} }
func TestFilterLatestReleases(t *testing.T) { func TestFilterLatestReleases(t *testing.T) {

Loading…
Cancel
Save