gitlab.azmi.pl/azmi-open-source/helm@v3.0.0-beta.3+incompatible/pkg/release/hook.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 release 18 19 import ( 20 "time" 21 ) 22 23 // HookEvent specifies the hook event 24 type HookEvent string 25 26 // Hook event types 27 const ( 28 HookPreInstall HookEvent = "pre-install" 29 HookPostInstall HookEvent = "post-install" 30 HookPreDelete HookEvent = "pre-delete" 31 HookPostDelete HookEvent = "post-delete" 32 HookPreUpgrade HookEvent = "pre-upgrade" 33 HookPostUpgrade HookEvent = "post-upgrade" 34 HookPreRollback HookEvent = "pre-rollback" 35 HookPostRollback HookEvent = "post-rollback" 36 HookTest HookEvent = "test" 37 ) 38 39 func (x HookEvent) String() string { return string(x) } 40 41 // HookDeletePolicy specifies the hook delete policy 42 type HookDeletePolicy string 43 44 // Hook delete policy types 45 const ( 46 HookSucceeded HookDeletePolicy = "hook-succeeded" 47 HookFailed HookDeletePolicy = "hook-failed" 48 HookBeforeHookCreation HookDeletePolicy = "before-hook-creation" 49 ) 50 51 func (x HookDeletePolicy) String() string { return string(x) } 52 53 // HookAnnotation is the label name for a hook 54 const HookAnnotation = "helm.sh/hook" 55 56 // HookWeightAnnotation is the label name for a hook weight 57 const HookWeightAnnotation = "helm.sh/hook-weight" 58 59 // HookDeleteAnnotation is the label name for the delete policy for a hook 60 const HookDeleteAnnotation = "helm.sh/hook-delete-policy" 61 62 // Hook defines a hook object. 63 type Hook struct { 64 Name string `json:"name,omitempty"` 65 // Kind is the Kubernetes kind. 66 Kind string `json:"kind,omitempty"` 67 // Path is the chart-relative path to the template. 68 Path string `json:"path,omitempty"` 69 // Manifest is the manifest contents. 70 Manifest string `json:"manifest,omitempty"` 71 // Events are the events that this hook fires on. 72 Events []HookEvent `json:"events,omitempty"` 73 // LastRun indicates the date/time this was last run. 74 LastRun HookExecution `json:"last_run,omitempty"` 75 // Weight indicates the sort order for execution among similar Hook type 76 Weight int `json:"weight,omitempty"` 77 // DeletePolicies are the policies that indicate when to delete the hook 78 DeletePolicies []HookDeletePolicy `json:"delete_policies,omitempty"` 79 } 80 81 // A HookExecution records the result for the last execution of a hook for a given release. 82 type HookExecution struct { 83 // StartedAt indicates the date/time this hook was started 84 StartedAt time.Time `json:"started_at,omitempty"` 85 // CompletedAt indicates the date/time this hook was completed. 86 CompletedAt time.Time `json:"completed_at,omitempty"` 87 // Phase indicates whether the hook completed successfully 88 Phase HookPhase `json:"phase"` 89 } 90 91 // A HookPhase indicates the state of a hook execution 92 type HookPhase string 93 94 const ( 95 // HookPhaseUnknown indicates that a hook is in an unknown state 96 HookPhaseUnknown HookPhase = "Unknown" 97 // HookPhaseRunning indicates that a hook is currently executing 98 HookPhaseRunning HookPhase = "Running" 99 // HookPhaseSucceeded indicates that hook execution succeeded 100 HookPhaseSucceeded HookPhase = "Succeeded" 101 // HookPhaseFailed indicates that hook execution failed 102 HookPhaseFailed HookPhase = "Failed" 103 ) 104 105 // Strng converts a hook phase to a printable string 106 func (x HookPhase) String() string { return string(x) }