Skip to content

Commit

Permalink
Fixes helm#10566
Browse files Browse the repository at this point in the history
Signed-off-by: alexandr.danilin <[email protected]>
  • Loading branch information
Noksa committed Feb 17, 2022
1 parent 9bf3a14 commit c598a22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/helm/release_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func newReleaseTestCmd(cfg *action.Configuration, out io.Writer) *cobra.Command
notName := regexp.MustCompile(`^!\s?name=`)
for _, f := range filter {
if strings.HasPrefix(f, "name=") {
client.Filters["name"] = append(client.Filters["name"], strings.TrimPrefix(f, "name="))
client.Filters[action.IncludeNameFilter] = append(client.Filters[action.IncludeNameFilter], strings.TrimPrefix(f, "name="))
} else if notName.MatchString(f) {
client.Filters["!name"] = append(client.Filters["!name"], notName.ReplaceAllLiteralString(f, ""))
client.Filters[action.ExcludeNameFilter] = append(client.Filters[action.ExcludeNameFilter], notName.ReplaceAllLiteralString(f, ""))
}
}
rel, runErr := client.Run(args[0])
Expand Down
19 changes: 15 additions & 4 deletions pkg/action/release_testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ import (
"helm.sh/helm/v3/pkg/release"
)

const (
ExcludeNameFilter = "!name"
IncludeNameFilter = "name"
)

// ReleaseTesting is the action for testing a release.
//
// It provides the implementation of 'helm test'.
Expand Down Expand Up @@ -66,20 +71,20 @@ func (r *ReleaseTesting) Run(name string) (*release.Release, error) {

skippedHooks := []*release.Hook{}
executingHooks := []*release.Hook{}
if len(r.Filters["!name"]) != 0 {
if len(r.Filters[ExcludeNameFilter]) != 0 {
for _, h := range rel.Hooks {
if contains(r.Filters["!name"], h.Name) {
if contains(r.Filters[ExcludeNameFilter], h.Name) {
skippedHooks = append(skippedHooks, h)
} else {
executingHooks = append(executingHooks, h)
}
}
rel.Hooks = executingHooks
}
if len(r.Filters["name"]) != 0 {
if len(r.Filters[IncludeNameFilter]) != 0 {
executingHooks = nil
for _, h := range rel.Hooks {
if contains(r.Filters["name"], h.Name) {
if contains(r.Filters[IncludeNameFilter], h.Name) {
executingHooks = append(executingHooks, h)
} else {
skippedHooks = append(skippedHooks, h)
Expand Down Expand Up @@ -110,6 +115,12 @@ func (r *ReleaseTesting) GetPodLogs(out io.Writer, rel *release.Release) error {
for _, h := range rel.Hooks {
for _, e := range h.Events {
if e == release.HookTest {
if contains(r.Filters[ExcludeNameFilter], h.Name) {
continue
}
if len(r.Filters[IncludeNameFilter]) > 0 && !contains(r.Filters[IncludeNameFilter], h.Name) {
continue
}
req := client.CoreV1().Pods(r.Namespace).GetLogs(h.Name, &v1.PodLogOptions{})
logReader, err := req.Stream(context.Background())
if err != nil {
Expand Down

0 comments on commit c598a22

Please sign in to comment.