github.com/strongmonkey/helm@v2.7.2+incompatible/cmd/helm/installer/options.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 installer // import "k8s.io/helm/cmd/helm/installer"
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"k8s.io/api/core/v1"
    23  	"k8s.io/helm/pkg/strvals"
    24  	"k8s.io/helm/pkg/version"
    25  )
    26  
    27  const defaultImage = "gcr.io/kubernetes-helm/tiller"
    28  
    29  // Options control how to install Tiller into a cluster, upgrade, and uninstall Tiller from a cluster.
    30  type Options struct {
    31  	// EnableTLS instructs Tiller to serve with TLS enabled.
    32  	//
    33  	// Implied by VerifyTLS. If set the TLSKey and TLSCert are required.
    34  	EnableTLS bool
    35  
    36  	// VerifyTLS instructs Tiller to serve with TLS enabled verify remote certificates.
    37  	//
    38  	// If set TLSKey, TLSCert, TLSCaCert are required.
    39  	VerifyTLS bool
    40  
    41  	// UseCanary indicates that Tiller should deploy using the latest Tiller image.
    42  	UseCanary bool
    43  
    44  	// Namespace is the Kubernetes namespace to use to deploy Tiller.
    45  	Namespace string
    46  
    47  	// ServiceAccount is the Kubernetes service account to add to Tiller.
    48  	ServiceAccount string
    49  
    50  	// ImageSpec indentifies the image Tiller will use when deployed.
    51  	//
    52  	// Valid if and only if UseCanary is false.
    53  	ImageSpec string
    54  
    55  	// TLSKeyFile identifies the file containing the pem encoded TLS private
    56  	// key Tiller should use.
    57  	//
    58  	// Required and valid if and only if EnableTLS or VerifyTLS is set.
    59  	TLSKeyFile string
    60  
    61  	// TLSCertFile identifies the file containing the pem encoded TLS
    62  	// certificate Tiller should use.
    63  	//
    64  	// Required and valid if and only if EnableTLS or VerifyTLS is set.
    65  	TLSCertFile string
    66  
    67  	// TLSCaCertFile identifies the file containing the pem encoded TLS CA
    68  	// certificate Tiller should use to verify remotes certificates.
    69  	//
    70  	// Required and valid if and only if VerifyTLS is set.
    71  	TLSCaCertFile string
    72  
    73  	// EnableHostNetwork installs Tiller with net=host.
    74  	EnableHostNetwork bool
    75  
    76  	// MaxHistory sets the maximum number of release versions stored per release.
    77  	//
    78  	// Less than or equal to zero means no limit.
    79  	MaxHistory int
    80  
    81  	// NodeSelectors determine which nodes Tiller can land on.
    82  	NodeSelectors string
    83  
    84  	// Output dumps the Tiller manifest in the specified format (e.g. JSON) but skips Helm/Tiller installation.
    85  	Output OutputFormat
    86  
    87  	// Set merges additional values into the Tiller Deployment manifest.
    88  	Values []string
    89  }
    90  
    91  func (opts *Options) selectImage() string {
    92  	switch {
    93  	case opts.UseCanary:
    94  		return defaultImage + ":canary"
    95  	case opts.ImageSpec == "":
    96  		return fmt.Sprintf("%s:%s", defaultImage, version.Version)
    97  	default:
    98  		return opts.ImageSpec
    99  	}
   100  }
   101  
   102  func (opts *Options) pullPolicy() v1.PullPolicy {
   103  	if opts.UseCanary {
   104  		return v1.PullAlways
   105  	}
   106  	return v1.PullIfNotPresent
   107  }
   108  
   109  func (opts *Options) tls() bool { return opts.EnableTLS || opts.VerifyTLS }
   110  
   111  // valuesMap returns user set values in map format
   112  func (opts *Options) valuesMap(m map[string]interface{}) (map[string]interface{}, error) {
   113  	for _, skv := range opts.Values {
   114  		if err := strvals.ParseInto(skv, m); err != nil {
   115  			return nil, err
   116  		}
   117  	}
   118  	return m, nil
   119  }
   120  
   121  // OutputFormat defines valid values for init output (json, yaml)
   122  type OutputFormat string
   123  
   124  // String returns the string value of the OutputFormat
   125  func (f *OutputFormat) String() string {
   126  	return string(*f)
   127  }
   128  
   129  // Type returns the string value of the OutputFormat
   130  func (f *OutputFormat) Type() string {
   131  	return "OutputFormat"
   132  }
   133  
   134  const (
   135  	fmtJSON OutputFormat = "json"
   136  	fmtYAML OutputFormat = "yaml"
   137  )
   138  
   139  // Set validates and sets the value of the OutputFormat
   140  func (f *OutputFormat) Set(s string) error {
   141  	for _, of := range []OutputFormat{fmtJSON, fmtYAML} {
   142  		if s == string(of) {
   143  			*f = of
   144  			return nil
   145  		}
   146  	}
   147  	return fmt.Errorf("unknown output format %q", s)
   148  }