github.com/darkowlzz/helm@v2.5.1-0.20171213183701-6707fe0468d4+incompatible/cmd/helm/dependency_update.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors All rights reserved.
     3  Licensed under the Apache License, Version 2.0 (the "License");
     4  you may not use this file except in compliance with the License.
     5  You may obtain a copy of the License at
     6  
     7  http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  Unless required by applicable law or agreed to in writing, software
    10  distributed under the License is distributed on an "AS IS" BASIS,
    11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  See the License for the specific language governing permissions and
    13  limitations under the License.
    14  */
    15  
    16  package main
    17  
    18  import (
    19  	"io"
    20  	"path/filepath"
    21  
    22  	"github.com/spf13/cobra"
    23  	"k8s.io/helm/pkg/downloader"
    24  	"k8s.io/helm/pkg/getter"
    25  	"k8s.io/helm/pkg/helm/helmpath"
    26  )
    27  
    28  const dependencyUpDesc = `
    29  Update the on-disk dependencies to mirror the requirements.yaml file.
    30  
    31  This command verifies that the required charts, as expressed in 'requirements.yaml',
    32  are present in 'charts/' and are at an acceptable version. It will pull down
    33  the latest charts that satisfy the dependencies, and clean up old dependencies.
    34  
    35  On successful update, this will generate a lock file that can be used to
    36  rebuild the requirements to an exact version.
    37  
    38  Dependencies are not required to be represented in 'requirements.yaml'. For that
    39  reason, an update command will not remove charts unless they are (a) present
    40  in the requirements.yaml file, but (b) at the wrong version.
    41  `
    42  
    43  // dependencyUpdateCmd describes a 'helm dependency update'
    44  type dependencyUpdateCmd struct {
    45  	out         io.Writer
    46  	chartpath   string
    47  	helmhome    helmpath.Home
    48  	verify      bool
    49  	keyring     string
    50  	skipRefresh bool
    51  }
    52  
    53  // newDependencyUpdateCmd creates a new dependency update command.
    54  func newDependencyUpdateCmd(out io.Writer) *cobra.Command {
    55  	duc := &dependencyUpdateCmd{out: out}
    56  
    57  	cmd := &cobra.Command{
    58  		Use:     "update [flags] CHART",
    59  		Aliases: []string{"up"},
    60  		Short:   "update charts/ based on the contents of requirements.yaml",
    61  		Long:    dependencyUpDesc,
    62  		RunE: func(cmd *cobra.Command, args []string) error {
    63  			cp := "."
    64  			if len(args) > 0 {
    65  				cp = args[0]
    66  			}
    67  
    68  			var err error
    69  			duc.chartpath, err = filepath.Abs(cp)
    70  			if err != nil {
    71  				return err
    72  			}
    73  
    74  			duc.helmhome = settings.Home
    75  
    76  			return duc.run()
    77  		},
    78  	}
    79  
    80  	f := cmd.Flags()
    81  	f.BoolVar(&duc.verify, "verify", false, "verify the packages against signatures")
    82  	f.StringVar(&duc.keyring, "keyring", defaultKeyring(), "keyring containing public keys")
    83  	f.BoolVar(&duc.skipRefresh, "skip-refresh", false, "do not refresh the local repository cache")
    84  
    85  	return cmd
    86  }
    87  
    88  // run runs the full dependency update process.
    89  func (d *dependencyUpdateCmd) run() error {
    90  	man := &downloader.Manager{
    91  		Out:        d.out,
    92  		ChartPath:  d.chartpath,
    93  		HelmHome:   d.helmhome,
    94  		Keyring:    d.keyring,
    95  		SkipUpdate: d.skipRefresh,
    96  		Getters:    getter.All(settings),
    97  	}
    98  	if d.verify {
    99  		man.Verify = downloader.VerifyAlways
   100  	}
   101  	if settings.Debug {
   102  		man.Debug = true
   103  	}
   104  	return man.Update()
   105  }