Signed-off-by: Lyndon Shi <shilyndon@outlook.com>
pull/12495/head
Lyndon Shi 2 years ago
parent fe595b69d7
commit 8d7ba82f1a

@ -23,6 +23,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"helm.sh/helm/v3/pkg/release" "helm.sh/helm/v3/pkg/release"
"helm.sh/helm/v3/pkg/releaseutil"
helmtime "helm.sh/helm/v3/pkg/time" helmtime "helm.sh/helm/v3/pkg/time"
) )
@ -119,6 +120,45 @@ func (x hookByWeight) Less(i, j int) bool {
return x[i].Weight < x[j].Weight return x[i].Weight < x[j].Weight
} }
func (x hookByWeight) LessFixed(i, j int) bool {
if x[i].Weight == x[j].Weight {
ordering := make(map[string]int, len(releaseutil.InstallOrder))
for v, k := range releaseutil.InstallOrder {
ordering[k] = v
}
first, iok := ordering[x[i].Kind]
second, jok := ordering[x[j].Kind]
// As in https://github.com/helm/helm/blob/fe595b69d78b213ab181d98ce24dde2454a56f9d/pkg/releaseutil/kind_sorter.go#L145C15-L145C15
if !iok && !jok {
// If both are unknown then sort alphabetically by kind.
if x[i].Kind != x[j].Kind {
return x[i].Kind < x[j].Kind
}
// Otherwise, let Stable() preserve the original order.
return false
}
// Unknown kind is last.
if !iok {
return false
}
if !jok {
return true
}
if first == second {
// According to the documentation, name is the last tiebreaker.
return x[i].Name < x[j].Name
}
return first < second
}
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