github.com/cloudposse/helm@v2.2.3+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, performs pod restart during upgrade/rollback 44 recreate bool 45 // if set, skip running hooks 46 disableHooks bool 47 // name of release 48 releaseName string 49 // release list options are applied directly to the list releases request 50 listReq rls.ListReleasesRequest 51 // release install options are applied directly to the install release request 52 instReq rls.InstallReleaseRequest 53 // release update options are applied directly to the update release request 54 updateReq rls.UpdateReleaseRequest 55 // release uninstall options are applied directly to the uninstall release request 56 uninstallReq rls.UninstallReleaseRequest 57 // release get status options are applied directly to the get release status request 58 statusReq rls.GetReleaseStatusRequest 59 // release get content options are applied directly to the get release content request 60 contentReq rls.GetReleaseContentRequest 61 // release rollback options are applied directly to the rollback release request 62 rollbackReq rls.RollbackReleaseRequest 63 // before intercepts client calls before sending 64 before func(context.Context, proto.Message) error 65 // release history options are applied directly to the get release history request 66 histReq rls.GetHistoryRequest 67 // resetValues instructs Tiller to reset values to their defaults. 68 resetValues bool 69 // release test options are applied directly to the test release history request 70 testReq rls.TestReleaseRequest 71 } 72 73 // Host specifies the host address of the Tiller release server, (default = ":44134"). 74 func Host(host string) Option { 75 return func(opts *options) { 76 opts.host = host 77 } 78 } 79 80 // BeforeCall returns an option that allows intercepting a helm client rpc 81 // before being sent OTA to tiller. The intercepting function should return 82 // an error to indicate that the call should not proceed or nil otherwise. 83 func BeforeCall(fn func(context.Context, proto.Message) error) Option { 84 return func(opts *options) { 85 opts.before = fn 86 } 87 } 88 89 // ReleaseListOption allows specifying various settings 90 // configurable by the helm client user for overriding 91 // the defaults used when running the `helm list` command. 92 type ReleaseListOption func(*options) 93 94 // ReleaseListOffset specifies the offset into a list of releases. 95 func ReleaseListOffset(offset string) ReleaseListOption { 96 return func(opts *options) { 97 opts.listReq.Offset = offset 98 } 99 } 100 101 // ReleaseListFilter specifies a filter to apply a list of releases. 102 func ReleaseListFilter(filter string) ReleaseListOption { 103 return func(opts *options) { 104 opts.listReq.Filter = filter 105 } 106 } 107 108 // ReleaseListLimit set an upper bound on the number of releases returned. 109 func ReleaseListLimit(limit int) ReleaseListOption { 110 return func(opts *options) { 111 opts.listReq.Limit = int64(limit) 112 } 113 } 114 115 // ReleaseListOrder specifies how to order a list of releases. 116 func ReleaseListOrder(order int32) ReleaseListOption { 117 return func(opts *options) { 118 opts.listReq.SortOrder = rls.ListSort_SortOrder(order) 119 } 120 } 121 122 // ReleaseListSort specifies how to sort a release list. 123 func ReleaseListSort(sort int32) ReleaseListOption { 124 return func(opts *options) { 125 opts.listReq.SortBy = rls.ListSort_SortBy(sort) 126 } 127 } 128 129 // ReleaseListStatuses specifies which status codes should be returned. 130 func ReleaseListStatuses(statuses []release.Status_Code) ReleaseListOption { 131 return func(opts *options) { 132 if len(statuses) == 0 { 133 statuses = []release.Status_Code{release.Status_DEPLOYED} 134 } 135 opts.listReq.StatusCodes = statuses 136 } 137 } 138 139 // ReleaseListNamespace specifies the namespace to list releases from 140 func ReleaseListNamespace(namespace string) ReleaseListOption { 141 return func(opts *options) { 142 opts.listReq.Namespace = namespace 143 } 144 } 145 146 // InstallOption allows specifying various settings 147 // configurable by the helm client user for overriding 148 // the defaults used when running the `helm install` command. 149 type InstallOption func(*options) 150 151 // ValueOverrides specifies a list of values to include when installing. 152 func ValueOverrides(raw []byte) InstallOption { 153 return func(opts *options) { 154 opts.instReq.Values = &cpb.Config{Raw: string(raw)} 155 } 156 } 157 158 // ReleaseName specifies the name of the release when installing. 159 func ReleaseName(name string) InstallOption { 160 return func(opts *options) { 161 opts.instReq.Name = name 162 } 163 } 164 165 // InstallTimeout specifies the number of seconds before kubernetes calls timeout 166 func InstallTimeout(timeout int64) InstallOption { 167 return func(opts *options) { 168 opts.instReq.Timeout = timeout 169 } 170 } 171 172 // UpgradeTimeout specifies the number of seconds before kubernetes calls timeout 173 func UpgradeTimeout(timeout int64) UpdateOption { 174 return func(opts *options) { 175 opts.updateReq.Timeout = timeout 176 } 177 } 178 179 // DeleteTimeout specifies the number of seconds before kubernetes calls timeout 180 func DeleteTimeout(timeout int64) DeleteOption { 181 return func(opts *options) { 182 opts.uninstallReq.Timeout = timeout 183 } 184 } 185 186 // ReleaseTestTimeout specifies the number of seconds before kubernetes calls timeout 187 func ReleaseTestTimeout(timeout int64) ReleaseTestOption { 188 return func(opts *options) { 189 opts.testReq.Timeout = timeout 190 } 191 } 192 193 // ReleaseTestCleanup is a boolean value representing whether to cleanup test pods 194 func ReleaseTestCleanup(cleanup bool) ReleaseTestOption { 195 return func(opts *options) { 196 opts.testReq.Cleanup = cleanup 197 } 198 } 199 200 // RollbackTimeout specifies the number of seconds before kubernetes calls timeout 201 func RollbackTimeout(timeout int64) RollbackOption { 202 return func(opts *options) { 203 opts.rollbackReq.Timeout = timeout 204 } 205 } 206 207 // InstallWait specifies whether or not to wait for all resources to be ready 208 func InstallWait(wait bool) InstallOption { 209 return func(opts *options) { 210 opts.instReq.Wait = wait 211 } 212 } 213 214 // UpgradeWait specifies whether or not to wait for all resources to be ready 215 func UpgradeWait(wait bool) UpdateOption { 216 return func(opts *options) { 217 opts.updateReq.Wait = wait 218 } 219 } 220 221 // RollbackWait specifies whether or not to wait for all resources to be ready 222 func RollbackWait(wait bool) RollbackOption { 223 return func(opts *options) { 224 opts.rollbackReq.Wait = wait 225 } 226 } 227 228 // UpdateValueOverrides specifies a list of values to include when upgrading 229 func UpdateValueOverrides(raw []byte) UpdateOption { 230 return func(opts *options) { 231 opts.updateReq.Values = &cpb.Config{Raw: string(raw)} 232 } 233 } 234 235 // DeleteDisableHooks will disable hooks for a deletion operation. 236 func DeleteDisableHooks(disable bool) DeleteOption { 237 return func(opts *options) { 238 opts.disableHooks = disable 239 } 240 } 241 242 // DeleteDryRun will (if true) execute a deletion as a dry run. 243 func DeleteDryRun(dry bool) DeleteOption { 244 return func(opts *options) { 245 opts.dryRun = dry 246 } 247 } 248 249 // DeletePurge removes the release from the store and make its name free for later use. 250 func DeletePurge(purge bool) DeleteOption { 251 return func(opts *options) { 252 opts.uninstallReq.Purge = purge 253 } 254 } 255 256 // InstallDryRun will (if true) execute an installation as a dry run. 257 func InstallDryRun(dry bool) InstallOption { 258 return func(opts *options) { 259 opts.dryRun = dry 260 } 261 } 262 263 // InstallDisableHooks disables hooks during installation. 264 func InstallDisableHooks(disable bool) InstallOption { 265 return func(opts *options) { 266 opts.disableHooks = disable 267 } 268 } 269 270 // InstallReuseName will (if true) instruct Tiller to re-use an existing name. 271 func InstallReuseName(reuse bool) InstallOption { 272 return func(opts *options) { 273 opts.reuseName = reuse 274 } 275 } 276 277 // RollbackDisableHooks will disable hooks for a rollback operation 278 func RollbackDisableHooks(disable bool) RollbackOption { 279 return func(opts *options) { 280 opts.disableHooks = disable 281 } 282 } 283 284 // RollbackDryRun will (if true) execute a rollback as a dry run. 285 func RollbackDryRun(dry bool) RollbackOption { 286 return func(opts *options) { 287 opts.dryRun = dry 288 } 289 } 290 291 // RollbackRecreate will (if true) recreate pods after rollback. 292 func RollbackRecreate(recreate bool) RollbackOption { 293 return func(opts *options) { 294 opts.recreate = recreate 295 } 296 } 297 298 // RollbackVersion sets the version of the release to deploy. 299 func RollbackVersion(ver int32) RollbackOption { 300 return func(opts *options) { 301 opts.rollbackReq.Version = ver 302 } 303 } 304 305 // UpgradeDisableHooks will disable hooks for an upgrade operation. 306 func UpgradeDisableHooks(disable bool) UpdateOption { 307 return func(opts *options) { 308 opts.disableHooks = disable 309 } 310 } 311 312 // UpgradeDryRun will (if true) execute an upgrade as a dry run. 313 func UpgradeDryRun(dry bool) UpdateOption { 314 return func(opts *options) { 315 opts.dryRun = dry 316 } 317 } 318 319 // ResetValues will (if true) trigger resetting the values to their original state. 320 func ResetValues(reset bool) UpdateOption { 321 return func(opts *options) { 322 opts.resetValues = reset 323 } 324 } 325 326 // UpgradeRecreate will (if true) recreate pods after upgrade. 327 func UpgradeRecreate(recreate bool) UpdateOption { 328 return func(opts *options) { 329 opts.recreate = recreate 330 } 331 } 332 333 // ContentOption allows setting optional attributes when 334 // performing a GetReleaseContent tiller rpc. 335 type ContentOption func(*options) 336 337 // ContentReleaseVersion will instruct Tiller to retrieve the content 338 // of a paritcular version of a release. 339 func ContentReleaseVersion(version int32) ContentOption { 340 return func(opts *options) { 341 opts.contentReq.Version = version 342 } 343 } 344 345 // StatusOption allows setting optional attributes when 346 // performing a GetReleaseStatus tiller rpc. 347 type StatusOption func(*options) 348 349 // StatusReleaseVersion will instruct Tiller to retrieve the status 350 // of a particular version of a release. 351 func StatusReleaseVersion(version int32) StatusOption { 352 return func(opts *options) { 353 opts.statusReq.Version = version 354 } 355 } 356 357 // DeleteOption allows setting optional attributes when 358 // performing a UninstallRelease tiller rpc. 359 type DeleteOption func(*options) 360 361 // VersionOption -- TODO 362 type VersionOption func(*options) 363 364 // UpdateOption allows specifying various settings 365 // configurable by the helm client user for overriding 366 // the defaults used when running the `helm upgrade` command. 367 type UpdateOption func(*options) 368 369 // RollbackOption allows specififying various settings configurable 370 // by the helm client user for overriding the defaults used when 371 // running the `helm rollback` command. 372 type RollbackOption func(*options) 373 374 // HistoryOption allows configuring optional request data for 375 // issuing a GetHistory rpc. 376 type HistoryOption func(*options) 377 378 // WithMaxHistory sets the max number of releases to return 379 // in a release history query. 380 func WithMaxHistory(max int32) HistoryOption { 381 return func(opts *options) { 382 opts.histReq.Max = max 383 } 384 } 385 386 // NewContext creates a versioned context. 387 func NewContext() context.Context { 388 md := metadata.Pairs("x-helm-api-client", version.Version) 389 return metadata.NewContext(context.TODO(), md) 390 } 391 392 // ReleaseTestOption allows configuring optional request data for 393 // issuing a TestRelease rpc. 394 type ReleaseTestOption func(*options)