From 752c850a4d5e30874e8963b016269a404128ac9a Mon Sep 17 00:00:00 2001 From: Nick Schuch Date: Tue, 21 Aug 2018 20:35:21 +1000 Subject: [PATCH] Adds 'Annotations' field to Release --- pkg/hapi/release/release.go | 4 ++++ pkg/hapi/tiller.go | 4 ++++ pkg/helm/client.go | 2 ++ pkg/helm/option.go | 16 ++++++++++++++++ pkg/tiller/release_install.go | 18 ++++++++++-------- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/pkg/hapi/release/release.go b/pkg/hapi/release/release.go index f8b739468..83d5d452d 100644 --- a/pkg/hapi/release/release.go +++ b/pkg/hapi/release/release.go @@ -22,6 +22,10 @@ import "k8s.io/helm/pkg/hapi/chart" type Release struct { // Name is the name of the release Name string `json:"name,omitempty"` + // Annotations is an unstructured key value map stored with a resource that may be + // set by external tools to store and retrieve arbitrary metadata. They are not + // queryable and should be preserved when modifying objects. + Annotations map[string]string `json:"annotations,omitempty"` // Info provides information about a release Info *Info `json:"info,omitempty"` // Chart is the chart that was released. diff --git a/pkg/hapi/tiller.go b/pkg/hapi/tiller.go index ee30f5619..4971e9450 100644 --- a/pkg/hapi/tiller.go +++ b/pkg/hapi/tiller.go @@ -93,6 +93,8 @@ type GetReleaseContentRequest struct { // UpdateReleaseRequest updates a release. type UpdateReleaseRequest struct { + // Annotations used by external tools. + Annotations map[string]string // The name of the release Name string `json:"name,omitempty"` // Chart is the protobuf representation of a chart. @@ -143,6 +145,8 @@ type RollbackReleaseRequest struct { // InstallReleaseRequest is the request for an installation of a chart. type InstallReleaseRequest struct { + // Annotations used by external tools. + Annotations map[string]string // Chart is the protobuf representation of a chart. Chart *chart.Chart `json:"chart,omitempty"` // Values is a string containing (unparsed) YAML values. diff --git a/pkg/helm/client.go b/pkg/helm/client.go index 8925b6043..a50c91909 100644 --- a/pkg/helm/client.go +++ b/pkg/helm/client.go @@ -90,6 +90,7 @@ func (c *Client) InstallReleaseFromChart(chart *chart.Chart, ns string, opts ... req.DryRun = reqOpts.dryRun req.DisableHooks = reqOpts.disableHooks req.ReuseName = reqOpts.reuseName + req.Annotations = reqOpts.annotations if err := reqOpts.runBefore(req); err != nil { return nil, err @@ -160,6 +161,7 @@ func (c *Client) UpdateReleaseFromChart(rlsName string, chart *chart.Chart, opts req.Force = reqOpts.force req.ResetValues = reqOpts.resetValues req.ReuseValues = reqOpts.reuseValues + req.Annotations = reqOpts.annotations if err := reqOpts.runBefore(req); err != nil { return nil, err diff --git a/pkg/helm/option.go b/pkg/helm/option.go index 476f00262..f2428e266 100644 --- a/pkg/helm/option.go +++ b/pkg/helm/option.go @@ -31,6 +31,8 @@ type Option func(*options) // options specify optional settings used by the helm client. type options struct { + // if set, annotations will be applied to a release + annotations map[string]string // if set dry-run helm client calls dryRun bool // if set, re-use an existing name @@ -268,6 +270,13 @@ func InstallReuseName(reuse bool) InstallOption { } } +// InstallAnnotations will add annotations to a Helm release. +func InstallAnnotations(annoations map[string]string) InstallOption { + return func(opts *options) { + opts.annotations = annoations + } +} + // RollbackDisableHooks will disable hooks for a rollback operation func RollbackDisableHooks(disable bool) RollbackOption { return func(opts *options) { @@ -346,6 +355,13 @@ func UpgradeForce(force bool) UpdateOption { } } +// UpdateAnnotations will assign annotations to a Helm release. +func UpdateAnnotations(annoations map[string]string) UpdateOption { + return func(opts *options) { + opts.annotations = annoations + } +} + // UninstallOption allows setting optional attributes when // performing a UninstallRelease tiller rpc. type UninstallOption func(*options) diff --git a/pkg/tiller/release_install.go b/pkg/tiller/release_install.go index db07249f5..8e1a9ce63 100644 --- a/pkg/tiller/release_install.go +++ b/pkg/tiller/release_install.go @@ -81,10 +81,11 @@ func (s *ReleaseServer) prepareRelease(req *hapi.InstallReleaseRequest) (*releas // Return a release with partial data so that client can show debugging // information. rel := &release.Release{ - Name: name, - Namespace: req.Namespace, - Chart: req.Chart, - Config: req.Values, + Name: name, + Namespace: req.Namespace, + Annotations: req.Annotations, + Chart: req.Chart, + Config: req.Values, Info: &release.Info{ FirstDeployed: ts, LastDeployed: ts, @@ -101,10 +102,11 @@ func (s *ReleaseServer) prepareRelease(req *hapi.InstallReleaseRequest) (*releas // Store a release. rel := &release.Release{ - Name: name, - Namespace: req.Namespace, - Chart: req.Chart, - Config: req.Values, + Name: name, + Namespace: req.Namespace, + Annotations: req.Annotations, + Chart: req.Chart, + Config: req.Values, Info: &release.Info{ FirstDeployed: ts, LastDeployed: ts,