github.com/uhthomas/helm@v3.0.0-beta.3+incompatible/pkg/action/history.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 action
    18  
    19  import (
    20  	"github.com/pkg/errors"
    21  
    22  	"helm.sh/helm/pkg/release"
    23  )
    24  
    25  // History is the action for checking the release's ledger.
    26  //
    27  // It provides the implementation of 'helm history'.
    28  type History struct {
    29  	cfg *Configuration
    30  
    31  	Max          int
    32  	OutputFormat string
    33  }
    34  
    35  // NewHistory creates a new History object with the given configuration.
    36  func NewHistory(cfg *Configuration) *History {
    37  	return &History{
    38  		cfg: cfg,
    39  	}
    40  }
    41  
    42  // Run executes 'helm history' against the given release.
    43  func (h *History) Run(name string) ([]*release.Release, error) {
    44  	if err := h.cfg.KubeClient.IsReachable(); err != nil {
    45  		return nil, err
    46  	}
    47  
    48  	if err := validateReleaseName(name); err != nil {
    49  		return nil, errors.Errorf("release name is invalid: %s", name)
    50  	}
    51  
    52  	h.cfg.Log("getting history for release %s", name)
    53  	return h.cfg.Releases.History(name)
    54  }