mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
Merge pull request #30939 from TerryHowe/action-hooks-delete-policy-mutex
fix: action hooks delete policy mutex
This commit is contained in:
commit
e2630d1aba
2 changed files with 22 additions and 9 deletions
|
|
@ -26,6 +26,7 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"text/template"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
|
|
@ -86,6 +87,8 @@ type Configuration struct {
|
|||
|
||||
// HookOutputFunc called with container name and returns and expects writer that will receive the log output.
|
||||
HookOutputFunc func(namespace, pod, container string) io.Writer
|
||||
|
||||
mutex sync.Mutex
|
||||
}
|
||||
|
||||
// renderResources renders the templates in a chart
|
||||
|
|
|
|||
|
|
@ -49,13 +49,7 @@ func (cfg *Configuration) execHook(rl *release.Release, hook release.HookEvent,
|
|||
|
||||
for i, h := range executingHooks {
|
||||
// Set default delete policy to before-hook-creation
|
||||
if len(h.DeletePolicies) == 0 {
|
||||
// TODO(jlegrone): Only apply before-hook-creation delete policy to run to completion
|
||||
// resources. For all other resource types update in place if a
|
||||
// resource with the same name already exists and is owned by the
|
||||
// current release.
|
||||
h.DeletePolicies = []release.HookDeletePolicy{release.HookBeforeHookCreation}
|
||||
}
|
||||
cfg.hookSetDeletePolicy(h)
|
||||
|
||||
if err := cfg.deleteHookByPolicy(h, release.HookBeforeHookCreation, waitStrategy, timeout); err != nil {
|
||||
return err
|
||||
|
|
@ -154,7 +148,7 @@ func (cfg *Configuration) deleteHookByPolicy(h *release.Hook, policy release.Hoo
|
|||
if h.Kind == "CustomResourceDefinition" {
|
||||
return nil
|
||||
}
|
||||
if hookHasDeletePolicy(h, policy) {
|
||||
if cfg.hookHasDeletePolicy(h, policy) {
|
||||
resources, err := cfg.KubeClient.Build(bytes.NewBufferString(h.Manifest), false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to build kubernetes object for deleting hook %s: %w", h.Path, err)
|
||||
|
|
@ -188,10 +182,26 @@ func (cfg *Configuration) deleteHooksByPolicy(hooks []*release.Hook, policy rele
|
|||
|
||||
// hookHasDeletePolicy determines whether the defined hook deletion policy matches the hook deletion polices
|
||||
// supported by helm. If so, mark the hook as one should be deleted.
|
||||
func hookHasDeletePolicy(h *release.Hook, policy release.HookDeletePolicy) bool {
|
||||
func (cfg *Configuration) hookHasDeletePolicy(h *release.Hook, policy release.HookDeletePolicy) bool {
|
||||
cfg.mutex.Lock()
|
||||
defer cfg.mutex.Unlock()
|
||||
return slices.Contains(h.DeletePolicies, policy)
|
||||
}
|
||||
|
||||
// hookClearDeletePolicy determines whether the defined hook deletion policy matches the hook deletion polices
|
||||
// supported by helm. If so, mark the hook as one should be deleted.
|
||||
func (cfg *Configuration) hookSetDeletePolicy(h *release.Hook) {
|
||||
cfg.mutex.Lock()
|
||||
defer cfg.mutex.Unlock()
|
||||
if len(h.DeletePolicies) == 0 {
|
||||
// TODO(jlegrone): Only apply before-hook-creation delete policy to run to completion
|
||||
// resources. For all other resource types update in place if a
|
||||
// resource with the same name already exists and is owned by the
|
||||
// current release.
|
||||
h.DeletePolicies = []release.HookDeletePolicy{release.HookBeforeHookCreation}
|
||||
}
|
||||
}
|
||||
|
||||
// outputLogsByPolicy outputs a pods logs if the hook policy instructs it to
|
||||
func (cfg *Configuration) outputLogsByPolicy(h *release.Hook, releaseNamespace string, policy release.HookOutputLogPolicy) error {
|
||||
if !hookHasOutputLogPolicy(h, policy) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue