action/hooks: remove hook sorting, as they already come sorted from earlier

Co-authored-by: Alvaro Cabanas <acabanas@newrelic.com>
Co-authored-by: Paolo Gallina <paologallina1992@gmail.com>
Signed-off-by: Roberto Santalla <roobre@roobre.es>
pull/10787/head
Roberto Santalla 4 years ago
parent 974a6030c8
commit 0d54671263
No known key found for this signature in database
GPG Key ID: 1782D4B0212C2D9C

@ -17,11 +17,9 @@ package action
import ( import (
"bytes" "bytes"
"sort"
"time" "time"
"github.com/pkg/errors" "github.com/pkg/errors"
"helm.sh/helm/v3/pkg/release" "helm.sh/helm/v3/pkg/release"
helmtime "helm.sh/helm/v3/pkg/time" helmtime "helm.sh/helm/v3/pkg/time"
) )
@ -38,9 +36,6 @@ func (cfg *Configuration) execHook(rl *release.Release, hook release.HookEvent,
} }
} }
// hooke are pre-ordered by kind, so keep order stable
sort.Stable(hookByWeight(executingHooks))
for _, h := range executingHooks { for _, h := range executingHooks {
// Set default delete policy to before-hook-creation // Set default delete policy to before-hook-creation
if h.DeletePolicies == nil || len(h.DeletePolicies) == 0 { if h.DeletePolicies == nil || len(h.DeletePolicies) == 0 {
@ -107,18 +102,6 @@ func (cfg *Configuration) execHook(rl *release.Release, hook release.HookEvent,
return nil return nil
} }
// hookByWeight is a sorter for hooks
type hookByWeight []*release.Hook
func (x hookByWeight) Len() int { return len(x) }
func (x hookByWeight) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
func (x hookByWeight) Less(i, j int) bool {
if x[i].Weight == x[j].Weight {
return x[i].Name < x[j].Name
}
return x[i].Weight < x[j].Weight
}
// deleteHookByPolicy deletes a hook if the hook policy instructs it to // deleteHookByPolicy deletes a hook if the hook policy instructs it to
func (cfg *Configuration) deleteHookByPolicy(h *release.Hook, policy release.HookDeletePolicy) error { func (cfg *Configuration) deleteHookByPolicy(h *release.Hook, policy release.HookDeletePolicy) error {
// Never delete CustomResourceDefinitions; this could cause lots of // Never delete CustomResourceDefinitions; this could cause lots of

Loading…
Cancel
Save