github.com/koderover/helm@v2.17.0+incompatible/pkg/hooks/hooks.go (about)

     1  /*
     2  Copyright The Helm Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package hooks
    18  
    19  import (
    20  	"k8s.io/helm/pkg/proto/hapi/release"
    21  )
    22  
    23  const (
    24  	// HookAnno is the label name for a hook
    25  	HookAnno = "helm.sh/hook"
    26  	// HookWeightAnno is the label name for a hook weight
    27  	HookWeightAnno = "helm.sh/hook-weight"
    28  	// HookDeleteAnno is the label name for the delete policy for a hook
    29  	HookDeleteAnno = "helm.sh/hook-delete-policy"
    30  	// HookDeleteTimeoutAnno is the label name for the timeout value for delete policies
    31  	HookDeleteTimeoutAnno = "helm.sh/hook-delete-timeout"
    32  )
    33  
    34  // Types of hooks
    35  const (
    36  	PreInstall         = "pre-install"
    37  	PostInstall        = "post-install"
    38  	PreDelete          = "pre-delete"
    39  	PostDelete         = "post-delete"
    40  	PreUpgrade         = "pre-upgrade"
    41  	PostUpgrade        = "post-upgrade"
    42  	PreRollback        = "pre-rollback"
    43  	PostRollback       = "post-rollback"
    44  	ReleaseTestSuccess = "test-success"
    45  	ReleaseTestFailure = "test-failure"
    46  	CRDInstall         = "crd-install"
    47  )
    48  
    49  // Type of policy for deleting the hook
    50  const (
    51  	HookSucceeded      = "hook-succeeded"
    52  	HookFailed         = "hook-failed"
    53  	BeforeHookCreation = "before-hook-creation"
    54  )
    55  
    56  // FilterTestHooks filters the list of hooks are returns only testing hooks.
    57  func FilterTestHooks(hooks []*release.Hook) []*release.Hook {
    58  	testHooks := []*release.Hook{}
    59  
    60  	for _, h := range hooks {
    61  		for _, e := range h.Events {
    62  			if e == release.Hook_RELEASE_TEST_SUCCESS || e == release.Hook_RELEASE_TEST_FAILURE {
    63  				testHooks = append(testHooks, h)
    64  				continue
    65  			}
    66  		}
    67  	}
    68  
    69  	return testHooks
    70  }