github.com/flant/helm@v2.8.1+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 // Force allows to force upgrading tiller if deployed version is greater than current version 51 ForceUpgrade bool 52 53 // ImageSpec indentifies the image Tiller will use when deployed. 54 // 55 // Valid if and only if UseCanary is false. 56 ImageSpec string 57 58 // TLSKeyFile identifies the file containing the pem encoded TLS private 59 // key Tiller should use. 60 // 61 // Required and valid if and only if EnableTLS or VerifyTLS is set. 62 TLSKeyFile string 63 64 // TLSCertFile identifies the file containing the pem encoded TLS 65 // certificate Tiller should use. 66 // 67 // Required and valid if and only if EnableTLS or VerifyTLS is set. 68 TLSCertFile string 69 70 // TLSCaCertFile identifies the file containing the pem encoded TLS CA 71 // certificate Tiller should use to verify remotes certificates. 72 // 73 // Required and valid if and only if VerifyTLS is set. 74 TLSCaCertFile string 75 76 // EnableHostNetwork installs Tiller with net=host. 77 EnableHostNetwork bool 78 79 // MaxHistory sets the maximum number of release versions stored per release. 80 // 81 // Less than or equal to zero means no limit. 82 MaxHistory int 83 84 // NodeSelectors determine which nodes Tiller can land on. 85 NodeSelectors string 86 87 // Output dumps the Tiller manifest in the specified format (e.g. JSON) but skips Helm/Tiller installation. 88 Output OutputFormat 89 90 // Set merges additional values into the Tiller Deployment manifest. 91 Values []string 92 } 93 94 func (opts *Options) selectImage() string { 95 switch { 96 case opts.UseCanary: 97 return defaultImage + ":canary" 98 case opts.ImageSpec == "": 99 return fmt.Sprintf("%s:%s", defaultImage, version.Version) 100 default: 101 return opts.ImageSpec 102 } 103 } 104 105 func (opts *Options) pullPolicy() v1.PullPolicy { 106 if opts.UseCanary { 107 return v1.PullAlways 108 } 109 return v1.PullIfNotPresent 110 } 111 112 func (opts *Options) tls() bool { return opts.EnableTLS || opts.VerifyTLS } 113 114 // valuesMap returns user set values in map format 115 func (opts *Options) valuesMap(m map[string]interface{}) (map[string]interface{}, error) { 116 for _, skv := range opts.Values { 117 if err := strvals.ParseInto(skv, m); err != nil { 118 return nil, err 119 } 120 } 121 return m, nil 122 } 123 124 // OutputFormat defines valid values for init output (json, yaml) 125 type OutputFormat string 126 127 // String returns the string value of the OutputFormat 128 func (f *OutputFormat) String() string { 129 return string(*f) 130 } 131 132 // Type returns the string value of the OutputFormat 133 func (f *OutputFormat) Type() string { 134 return "OutputFormat" 135 } 136 137 const ( 138 fmtJSON OutputFormat = "json" 139 fmtYAML OutputFormat = "yaml" 140 ) 141 142 // Set validates and sets the value of the OutputFormat 143 func (f *OutputFormat) Set(s string) error { 144 for _, of := range []OutputFormat{fmtJSON, fmtYAML} { 145 if s == string(of) { 146 *f = of 147 return nil 148 } 149 } 150 return fmt.Errorf("unknown output format %q", s) 151 }