From 8d7ba82f1a2c7891c761ce4d90128765eb900f8a Mon Sep 17 00:00:00 2001 From: Lyndon Shi Date: Fri, 13 Oct 2023 22:41:41 -0700 Subject: [PATCH] new logic Signed-off-by: Lyndon Shi --- pkg/action/hooks.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pkg/action/hooks.go b/pkg/action/hooks.go index 40c1ffdb6..35a12f411 100644 --- a/pkg/action/hooks.go +++ b/pkg/action/hooks.go @@ -23,6 +23,7 @@ import ( "github.com/pkg/errors" "helm.sh/helm/v3/pkg/release" + "helm.sh/helm/v3/pkg/releaseutil" 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 } +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 func (cfg *Configuration) deleteHookByPolicy(h *release.Hook, policy release.HookDeletePolicy) error { // Never delete CustomResourceDefinitions; this could cause lots of