github.com/felipejfc/helm@v2.1.2+incompatible/pkg/helm/option.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 helm 18 19 import ( 20 "github.com/golang/protobuf/proto" 21 "golang.org/x/net/context" 22 "google.golang.org/grpc/metadata" 23 24 cpb "k8s.io/helm/pkg/proto/hapi/chart" 25 "k8s.io/helm/pkg/proto/hapi/release" 26 rls "k8s.io/helm/pkg/proto/hapi/services" 27 "k8s.io/helm/pkg/version" 28 ) 29 30 // Option allows specifying various settings configurable by 31 // the helm client user for overriding the defaults used when 32 // issuing rpc's to the Tiller release server. 33 type Option func(*options) 34 35 // options specify optional settings used by the helm client. 36 type options struct { 37 // value of helm home override 38 host string 39 // if set dry-run helm client calls 40 dryRun bool 41 // if set, re-use an existing name 42 reuseName bool 43 // if set, skip running hooks 44 disableHooks bool 45 // name of release 46 releaseName string 47 // release list options are applied directly to the list releases request 48 listReq rls.ListReleasesRequest 49 // release install options are applied directly to the install release request 50 instReq rls.InstallReleaseRequest 51 // release update options are applied directly to the update release request 52 updateReq rls.UpdateReleaseRequest 53 // release uninstall options are applied directly to the uninstall release request 54 uninstallReq rls.UninstallReleaseRequest 55 // release get status options are applied directly to the get release status request 56 statusReq rls.GetReleaseStatusRequest 57 // release get content options are applied directly to the get release content request 58 contentReq rls.GetReleaseContentRequest 59 // release rollback options are applied directly to the rollback release request 60 rollbackReq rls.RollbackReleaseRequest 61 // before intercepts client calls before sending 62 before func(context.Context, proto.Message) error 63 // release history options are applied directly to the get release history request 64 histReq rls.GetHistoryRequest 65 } 66 67 // Host specifies the host address of the Tiller release server, (default = ":44134"). 68 func Host(host string) Option { 69 return func(opts *options) { 70 opts.host = host 71 } 72 } 73 74 // BeforeCall returns an option that allows intercepting a helm client rpc 75 // before being sent OTA to tiller. The intercepting function should return 76 // an error to indicate that the call should not proceed or nil otherwise. 77 func BeforeCall(fn func(context.Context, proto.Message) error) Option { 78 return func(opts *options) { 79 opts.before = fn 80 } 81 } 82 83 // ReleaseListOption allows specifying various settings 84 // configurable by the helm client user for overriding 85 // the defaults used when running the `helm list` command. 86 type ReleaseListOption func(*options) 87 88 // ReleaseListOffset specifies the offset into a list of releases. 89 func ReleaseListOffset(offset string) ReleaseListOption { 90 return func(opts *options) { 91 opts.listReq.Offset = offset 92 } 93 } 94 95 // ReleaseListFilter specifies a filter to apply a list of releases. 96 func ReleaseListFilter(filter string) ReleaseListOption { 97 return func(opts *options) { 98 opts.listReq.Filter = filter 99 } 100 } 101 102 // ReleaseListLimit set an upper bound on the number of releases returned. 103 func ReleaseListLimit(limit int) ReleaseListOption { 104 return func(opts *options) { 105 opts.listReq.Limit = int64(limit) 106 } 107 } 108 109 // ReleaseListOrder specifies how to order a list of releases. 110 func ReleaseListOrder(order int32) ReleaseListOption { 111 return func(opts *options) { 112 opts.listReq.SortOrder = rls.ListSort_SortOrder(order) 113 } 114 } 115 116 // ReleaseListSort specifies how to sort a release list. 117 func ReleaseListSort(sort int32) ReleaseListOption { 118 return func(opts *options) { 119 opts.listReq.SortBy = rls.ListSort_SortBy(sort) 120 } 121 } 122 123 // ReleaseListStatuses specifies which status codes should be returned. 124 func ReleaseListStatuses(statuses []release.Status_Code) ReleaseListOption { 125 return func(opts *options) { 126 if len(statuses) == 0 { 127 statuses = []release.Status_Code{release.Status_DEPLOYED} 128 } 129 opts.listReq.StatusCodes = statuses 130 } 131 } 132 133 // InstallOption allows specifying various settings 134 // configurable by the helm client user for overriding 135 // the defaults used when running the `helm install` command. 136 type InstallOption func(*options) 137 138 // ValueOverrides specifies a list of values to include when installing. 139 func ValueOverrides(raw []byte) InstallOption { 140 return func(opts *options) { 141 opts.instReq.Values = &cpb.Config{Raw: string(raw)} 142 } 143 } 144 145 // ReleaseName specifies the name of the release when installing. 146 func ReleaseName(name string) InstallOption { 147 return func(opts *options) { 148 opts.instReq.Name = name 149 } 150 } 151 152 // UpdateValueOverrides specifies a list of values to include when upgrading 153 func UpdateValueOverrides(raw []byte) UpdateOption { 154 return func(opts *options) { 155 opts.updateReq.Values = &cpb.Config{Raw: string(raw)} 156 } 157 } 158 159 // DeleteDisableHooks will disable hooks for a deletion operation. 160 func DeleteDisableHooks(disable bool) DeleteOption { 161 return func(opts *options) { 162 opts.disableHooks = disable 163 } 164 } 165 166 // DeleteDryRun will (if true) execute a deletion as a dry run. 167 func DeleteDryRun(dry bool) DeleteOption { 168 return func(opts *options) { 169 opts.dryRun = dry 170 } 171 } 172 173 // DeletePurge removes the release from the store and make its name free for later use. 174 func DeletePurge(purge bool) DeleteOption { 175 return func(opts *options) { 176 opts.uninstallReq.Purge = purge 177 } 178 } 179 180 // InstallDryRun will (if true) execute an installation as a dry run. 181 func InstallDryRun(dry bool) InstallOption { 182 return func(opts *options) { 183 opts.dryRun = dry 184 } 185 } 186 187 // InstallDisableHooks disables hooks during installation. 188 func InstallDisableHooks(disable bool) InstallOption { 189 return func(opts *options) { 190 opts.disableHooks = disable 191 } 192 } 193 194 // InstallReuseName will (if true) instruct Tiller to re-use an existing name. 195 func InstallReuseName(reuse bool) InstallOption { 196 return func(opts *options) { 197 opts.reuseName = reuse 198 } 199 } 200 201 // RollbackDisableHooks will disable hooks for a rollback operation 202 func RollbackDisableHooks(disable bool) RollbackOption { 203 return func(opts *options) { 204 opts.disableHooks = disable 205 } 206 } 207 208 // RollbackDryRun will (if true) execute a rollback as a dry run. 209 func RollbackDryRun(dry bool) RollbackOption { 210 return func(opts *options) { 211 opts.dryRun = dry 212 } 213 } 214 215 // RollbackVersion sets the version of the release to deploy. 216 func RollbackVersion(ver int32) RollbackOption { 217 return func(opts *options) { 218 opts.rollbackReq.Version = ver 219 } 220 } 221 222 // UpgradeDisableHooks will disable hooks for an upgrade operation. 223 func UpgradeDisableHooks(disable bool) UpdateOption { 224 return func(opts *options) { 225 opts.disableHooks = disable 226 } 227 } 228 229 // UpgradeDryRun will (if true) execute an upgrade as a dry run. 230 func UpgradeDryRun(dry bool) UpdateOption { 231 return func(opts *options) { 232 opts.dryRun = dry 233 } 234 } 235 236 // ContentOption allows setting optional attributes when 237 // performing a GetReleaseContent tiller rpc. 238 type ContentOption func(*options) 239 240 // ContentReleaseVersion will instruct Tiller to retrieve the content 241 // of a paritcular version of a release. 242 func ContentReleaseVersion(version int32) ContentOption { 243 return func(opts *options) { 244 opts.contentReq.Version = version 245 } 246 } 247 248 // StatusOption allows setting optional attributes when 249 // performing a GetReleaseStatus tiller rpc. 250 type StatusOption func(*options) 251 252 // StatusReleaseVersion will instruct Tiller to retrieve the status 253 // of a particular version of a release. 254 func StatusReleaseVersion(version int32) StatusOption { 255 return func(opts *options) { 256 opts.statusReq.Version = version 257 } 258 } 259 260 // DeleteOption allows setting optional attributes when 261 // performing a UninstallRelease tiller rpc. 262 type DeleteOption func(*options) 263 264 // VersionOption -- TODO 265 type VersionOption func(*options) 266 267 // UpdateOption allows specifying various settings 268 // configurable by the helm client user for overriding 269 // the defaults used when running the `helm upgrade` command. 270 type UpdateOption func(*options) 271 272 // RollbackOption allows specififying various settings configurable 273 // by the helm client user for overriding the defaults used when 274 // running the `helm rollback` command. 275 type RollbackOption func(*options) 276 277 // HistoryOption allows configuring optional request data for 278 // issuing a GetHistory rpc. 279 type HistoryOption func(*options) 280 281 // WithMaxHistory sets the max number of releases to return 282 // in a release history query. 283 func WithMaxHistory(max int32) HistoryOption { 284 return func(opts *options) { 285 opts.histReq.Max = max 286 } 287 } 288 289 // NewContext creates a versioned context. 290 func NewContext() context.Context { 291 md := metadata.Pairs("x-helm-api-client", version.Version) 292 return metadata.NewContext(context.TODO(), md) 293 }