github.com/canthefason/helm@v2.2.1-0.20170221172616-16b043b8d505+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  	"errors"
    21  
    22  	"k8s.io/helm/pkg/proto/hapi/release"
    23  )
    24  
    25  // HookAnno is the label name for a hook
    26  const HookAnno = "helm.sh/hook"
    27  
    28  // Types of hooks
    29  const (
    30  	PreInstall         = "pre-install"
    31  	PostInstall        = "post-install"
    32  	PreDelete          = "pre-delete"
    33  	PostDelete         = "post-delete"
    34  	PreUpgrade         = "pre-upgrade"
    35  	PostUpgrade        = "post-upgrade"
    36  	PreRollback        = "pre-rollback"
    37  	PostRollback       = "post-rollback"
    38  	ReleaseTestSuccess = "test-success"
    39  	ReleaseTestFailure = "test-failure"
    40  )
    41  
    42  // FilterTestHooks filters the list of hooks are returns only testing hooks.
    43  func FilterTestHooks(hooks []*release.Hook) ([]*release.Hook, error) {
    44  	testHooks := []*release.Hook{}
    45  	notFoundErr := errors.New("no tests found")
    46  
    47  	if len(hooks) == 0 {
    48  		return nil, notFoundErr
    49  	}
    50  
    51  	for _, h := range hooks {
    52  		for _, e := range h.Events {
    53  			if e == release.Hook_RELEASE_TEST_SUCCESS || e == release.Hook_RELEASE_TEST_FAILURE {
    54  				testHooks = append(testHooks, h)
    55  				continue
    56  			}
    57  		}
    58  	}
    59  
    60  	if len(testHooks) == 0 {
    61  		return nil, notFoundErr
    62  	}
    63  
    64  	return testHooks, nil
    65  }