github.com/zoumo/helm@v2.5.0+incompatible/pkg/hooks/hooks.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors All rights reserved.
     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  // HookAnno is the label name for a hook
    24  const HookAnno = "helm.sh/hook"
    25  
    26  // HookWeightAnno is the label name for a hook weight
    27  const HookWeightAnno = "helm.sh/hook-weight"
    28  
    29  // Types of hooks
    30  const (
    31  	PreInstall         = "pre-install"
    32  	PostInstall        = "post-install"
    33  	PreDelete          = "pre-delete"
    34  	PostDelete         = "post-delete"
    35  	PreUpgrade         = "pre-upgrade"
    36  	PostUpgrade        = "post-upgrade"
    37  	PreRollback        = "pre-rollback"
    38  	PostRollback       = "post-rollback"
    39  	ReleaseTestSuccess = "test-success"
    40  	ReleaseTestFailure = "test-failure"
    41  )
    42  
    43  // FilterTestHooks filters the list of hooks are returns only testing hooks.
    44  func FilterTestHooks(hooks []*release.Hook) []*release.Hook {
    45  	testHooks := []*release.Hook{}
    46  
    47  	for _, h := range hooks {
    48  		for _, e := range h.Events {
    49  			if e == release.Hook_RELEASE_TEST_SUCCESS || e == release.Hook_RELEASE_TEST_FAILURE {
    50  				testHooks = append(testHooks, h)
    51  				continue
    52  			}
    53  		}
    54  	}
    55  
    56  	return testHooks
    57  }