mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-17 22:29:56 +02:00
Make a few helmfile sub-commands consistently support needs-related flags (#78)
* Make a few helmfile sub-commands to consistently support needs-related flags * helmfile-diff adds support for --include-transitive-needs * helmfile-template adds support for --skip-needs * helmfile-lint adds support for --skip-needs, --include-needs, and --include-transitive-needs Ref https://github.com/roboll/helmfile/issues/2055 Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Fix a few helmfile-lint needs related bugs and add tests Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Is include-transitive-needs realy working as intended? 🤔 Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Confirm that it does fail on unselected need by default Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Add missing testdata Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Test helmfile-template for include/skip needs support Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Fix a few terms Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Add more tests to better know the current helmfile-diff behavior around needs Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Fix failing tests Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Fix helmfile-diff to consistently handle skip/include-needs Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Extract testhelper.RequireLog for reusing Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Fix all bugs and test cases for TestDiff and TestDiff_2 Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Fix TestDiff_2 Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Fix TestDiff Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Fix TestDiffWithNeeds Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Unify behavior on including disabled releases as needs for lint and template Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com> * Fix bug that --include-transitive-needs does not imply include-needs Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
+29
-1
@@ -15,6 +15,10 @@ type ListKey struct {
|
||||
Flags string
|
||||
}
|
||||
|
||||
func (k ListKey) String() string {
|
||||
return fmt.Sprintf("listkey(filter=%s,flags=%s)", k.Filter, k.Flags)
|
||||
}
|
||||
|
||||
type DiffKey struct {
|
||||
Name string
|
||||
Chart string
|
||||
@@ -26,6 +30,8 @@ type Helm struct {
|
||||
Repo []string
|
||||
Releases []Release
|
||||
Deleted []Release
|
||||
Linted []Release
|
||||
Templated []Release
|
||||
Lists map[ListKey]string
|
||||
Diffs map[DiffKey]error
|
||||
Diffed []Release
|
||||
@@ -113,6 +119,11 @@ func (helm *Helm) DiffRelease(context helmexec.HelmContext, name, chart string,
|
||||
if helm.DiffMutex != nil {
|
||||
helm.DiffMutex.Unlock()
|
||||
}
|
||||
|
||||
if helm.Diffs == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
key := DiffKey{Name: name, Chart: chart, Flags: strings.Join(flags, "")}
|
||||
err, ok := helm.Diffs[key]
|
||||
if !ok && helm.FailOnUnexpectedDiff {
|
||||
@@ -136,9 +147,18 @@ func (helm *Helm) DeleteRelease(context helmexec.HelmContext, name string, flags
|
||||
}
|
||||
func (helm *Helm) List(context helmexec.HelmContext, filter string, flags ...string) (string, error) {
|
||||
key := ListKey{Filter: filter, Flags: strings.Join(flags, "")}
|
||||
|
||||
if helm.Lists == nil {
|
||||
return "dummy non-empty helm-list output", nil
|
||||
}
|
||||
|
||||
res, ok := helm.Lists[key]
|
||||
if !ok && helm.FailOnUnexpectedList {
|
||||
return "", fmt.Errorf("unexpected list key: %v", key)
|
||||
var keys []string
|
||||
for k := range helm.Lists {
|
||||
keys = append(keys, k.String())
|
||||
}
|
||||
return "", fmt.Errorf("unexpected list key: %v in %v", key, strings.Join(keys, ", "))
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
@@ -156,9 +176,17 @@ func (helm *Helm) Fetch(chart string, flags ...string) error {
|
||||
return nil
|
||||
}
|
||||
func (helm *Helm) Lint(name, chart string, flags ...string) error {
|
||||
if strings.Contains(name, "error") {
|
||||
return errors.New("error")
|
||||
}
|
||||
helm.Linted = append(helm.Linted, Release{Name: name, Flags: flags})
|
||||
return nil
|
||||
}
|
||||
func (helm *Helm) TemplateRelease(name, chart string, flags ...string) error {
|
||||
if strings.Contains(name, "error") {
|
||||
return errors.New("error")
|
||||
}
|
||||
helm.Templated = append(helm.Templated, Release{Name: name, Flags: flags})
|
||||
return nil
|
||||
}
|
||||
func (helm *Helm) ChartPull(chart string, flags ...string) error {
|
||||
|
||||
Reference in New Issue
Block a user