github.com/koderover/helm@v2.17.0+incompatible/pkg/tiller/release_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 tiller 18 19 import ( 20 "golang.org/x/net/context" 21 22 tpb "k8s.io/helm/pkg/proto/hapi/services" 23 relutil "k8s.io/helm/pkg/releaseutil" 24 ) 25 26 // GetHistory gets the history for a given release. 27 func (s *ReleaseServer) GetHistory(ctx context.Context, req *tpb.GetHistoryRequest) (*tpb.GetHistoryResponse, error) { 28 if err := validateReleaseName(req.Name); err != nil { 29 s.Log("getHistory: Release name is invalid: %s", req.Name) 30 return nil, err 31 } 32 33 s.Log("getting history for release %s", req.Name) 34 h, err := s.env.Releases.History(req.Name) 35 if err != nil { 36 return nil, err 37 } 38 39 relutil.Reverse(h, relutil.SortByRevision) 40 41 var resp tpb.GetHistoryResponse 42 for i := 0; i < min(len(h), int(req.Max)); i++ { 43 resp.Releases = append(resp.Releases, h[i]) 44 } 45 46 return &resp, nil 47 } 48 49 func min(x, y int) int { 50 if x < y { 51 return x 52 } 53 return y 54 }