github.com/zoumo/helm@v2.5.0+incompatible/pkg/tiller/release_history.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 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  	s.Log("getting history for release %s", req.Name)
    29  	h, err := s.env.Releases.History(req.Name)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	relutil.Reverse(h, relutil.SortByRevision)
    35  
    36  	var resp tpb.GetHistoryResponse
    37  	for i := 0; i < min(len(h), int(req.Max)); i++ {
    38  		resp.Releases = append(resp.Releases, h[i])
    39  	}
    40  
    41  	return &resp, nil
    42  }
    43  
    44  func min(x, y int) int {
    45  	if x < y {
    46  		return x
    47  	}
    48  	return y
    49  }