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 action 18 19 import ( 20 "github.com/pkg/errors" 21 22 "helm.sh/helm/v3/pkg/chartutil" 23 "helm.sh/helm/v3/pkg/release" 24 ) 25 26 // History is the action for checking the release's ledger. 27 // 28 // It provides the implementation of 'helm history'. 29 // It returns all the revisions for a specific release. 30 // To list up to one revision of every release in one specific, or in all, 31 // namespaces, see the List action. 32 type History struct { 33 cfg *Configuration 34 35 Max int 36 Version int 37 } 38 39 // NewHistory creates a new History object with the given configuration. 40 func NewHistory(cfg *Configuration) *History { 41 return &History{ 42 cfg: cfg, 43 } 44 } 45 46 // Run executes 'helm history' against the given release. 47 func (h *History) Run(name string) ([]*release.Release, error) { 48 if err := h.cfg.KubeClient.IsReachable(); err != nil { 49 return nil, err 50 } 51 52 if err := chartutil.ValidateReleaseName(name); err != nil { 53 return nil, errors.Errorf("release name is invalid: %s", name) 54 } 55 56 h.cfg.Log("getting history for release %s", name) 57 return h.cfg.Releases.History(name) 58 } 59