From 860e6db2f807598790263db7e8efe3aecdf50473 Mon Sep 17 00:00:00 2001 From: Chris Bartlett Date: Fri, 15 May 2020 14:46:40 -0600 Subject: [PATCH 1/4] deprecating HELM_VERSION env var --- stimpacks/deploy/docker.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/stimpacks/deploy/docker.go b/stimpacks/deploy/docker.go index 9de3b10..a850607 100644 --- a/stimpacks/deploy/docker.go +++ b/stimpacks/deploy/docker.go @@ -32,9 +32,19 @@ func (d *Deploy) startDeployContainer(instance *Instance) { d.log.Debug(scanner.Text()) } - envs := make([]string, len(instance.Spec.EnvironmentVars)) - for i, e := range instance.Spec.EnvironmentVars { - envs[i] = fmt.Sprintf("%s=%s", e.Name, e.Value) + var envs []string + deprecatedHelmVersionSet := false + for _, e := range instance.Spec.EnvironmentVars { + // Using this environment variable for + if e.Name == "HELM_VERSION" { + d.log.Warn("The use of the HELM_VERSION environment variable for specifying Helm versions has been deprecated. This will be removed in the future. Please use the 'tools' config section instead. See https://github.com/PremiereGlobal/stim/blob/master/docs/DEPLOY.md for more details.") + deprecatedHelmVersionSet = true + } + envs = append(envs, fmt.Sprintf("%s=%s", e.Name, e.Value)) + } + + if _, ok := instance.Spec.Tools["helm"]; ok && !deprecatedHelmVersionSet { + envs = append(envs, fmt.Sprintf("HELM_VERSION=%s", instance.Spec.Tools["helm"].Version)) } // Since we're using Docker, we need to mount the Linux binaries From 61fb29ab1d94cf02991f8a092191ff08a43cc9d4 Mon Sep 17 00:00:00 2001 From: Chris Bartlett Date: Fri, 15 May 2020 16:38:36 -0600 Subject: [PATCH 2/4] Fixed versioning for helm --- CHANGELOG.md | 9 +++++++++ stimpacks/deploy/config.go | 19 +++++++++++++++++-- stimpacks/deploy/docker.go | 16 +++++++++++++--- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 781e4fd..196f0ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Stim Changelog +## 0.1.7 + +### **Deprecations** +* For `stim deploy`, the `HELM_VERSION` environment variable for specifying Helm versions is now deprecated. Please use the `.spec.tools.helm` configuration for specifying the helm version to use. See [deploy docs](https://github.com/PremiereGlobal/stim/blob/master/docs/DEPLOY.md) for more details. +* For `stim deploy`, auto-detection of Helm v2 versions is now deprecated. Please use the `.spec.tools.helm` configuration for specifying the helm version to use. See [deploy docs](https://github.com/PremiereGlobal/stim/blob/master/docs/DEPLOY.md) for more details. + +### Bugfix +* Fixed a bug where running `stim deploy` via the default Docker method would not respect the `spec.tools.helm` version. + ## 0.1.6 ### Bugfix diff --git a/stimpacks/deploy/config.go b/stimpacks/deploy/config.go index 38eca03..fb0c5b3 100644 --- a/stimpacks/deploy/config.go +++ b/stimpacks/deploy/config.go @@ -7,11 +7,10 @@ import ( "path/filepath" "strings" - "gopkg.in/yaml.v2" - "github.com/PremiereGlobal/stim/pkg/utils" "github.com/PremiereGlobal/stim/stim" v2e "github.com/PremiereGlobal/vault-to-envs/pkg/vaulttoenvs" + "gopkg.in/yaml.v2" ) const ( @@ -137,6 +136,8 @@ func (d *Deploy) processConfig() { d.config.Global.Spec = &Spec{} } + d.validateSpec(d.config.Global.Spec) + d.config.environmentMap = make(map[string]int) for i, environment := range d.config.Environments { @@ -157,6 +158,8 @@ func (d *Deploy) processConfig() { environment.Spec = &Spec{} } + d.validateSpec(environment.Spec) + environment.instanceMap = make(map[string]int) for j, instance := range environment.Instances { @@ -177,6 +180,8 @@ func (d *Deploy) processConfig() { instance.Spec = &Spec{} } + d.validateSpec(instance.Spec) + // Merge all of the secrets and environment variables // Instance-level specs take precedence, followed by environment-level then global-level if instance.Spec.Kubernetes.ServiceAccount == "" { @@ -294,6 +299,16 @@ func (d *Deploy) finalizeEnv(instance *Instance, stimEnvs []*EnvironmentVar, sti } +// validateSpec validates fields in a config 'spec' section to ensure that it +// meets all requirements +func (d *Deploy) validateSpec(spec *Spec) { + for toolName, toolSpec := range spec.Tools { + if toolName == "helm" && toolSpec.Version == "" { + d.log.Fatal("Version detection not supported for helm, please specify a version in the `spec.tools.helm` config") + } + } +} + // mergeEnvVars is used to merge environment variable configuration at the various levels it can be set at func mergeEnvVars(instance []*EnvironmentVar, environment []*EnvironmentVar, global []*EnvironmentVar) []*EnvironmentVar { diff --git a/stimpacks/deploy/docker.go b/stimpacks/deploy/docker.go index a850607..99ee1c7 100644 --- a/stimpacks/deploy/docker.go +++ b/stimpacks/deploy/docker.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/PremiereGlobal/stim/pkg/docker" + "github.com/PremiereGlobal/stim/pkg/downloader" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/mount" @@ -37,14 +38,23 @@ func (d *Deploy) startDeployContainer(instance *Instance) { for _, e := range instance.Spec.EnvironmentVars { // Using this environment variable for if e.Name == "HELM_VERSION" { - d.log.Warn("The use of the HELM_VERSION environment variable for specifying Helm versions has been deprecated. This will be removed in the future. Please use the 'tools' config section instead. See https://github.com/PremiereGlobal/stim/blob/master/docs/DEPLOY.md for more details.") + d.log.Warn("The use of the HELM_VERSION environment variable for specifying Helm versions has been deprecated. Use the `.spec.tools.helm` configuration for specifying the helm version to use. See https://github.com/PremiereGlobal/stim/blob/master/docs/DEPLOY.md for more details.") deprecatedHelmVersionSet = true } envs = append(envs, fmt.Sprintf("%s=%s", e.Name, e.Value)) } - if _, ok := instance.Spec.Tools["helm"]; ok && !deprecatedHelmVersionSet { - envs = append(envs, fmt.Sprintf("HELM_VERSION=%s", instance.Spec.Tools["helm"].Version)) + if _, ok := instance.Spec.Tools["helm"]; ok { + if !deprecatedHelmVersionSet { + envs = append(envs, fmt.Sprintf("HELM_VERSION=%s", downloader.GetBaseVersion(instance.Spec.Tools["helm"].Version))) + } else { + d.log.Warn("Both `spec.tools.helm` and the deprecated HELM_VERSION environment variable are set. HELM_VERSION is taking precedence") + } + } else if !deprecatedHelmVersionSet { + d.log.Warn("Auto-detection of Helm v2 versions now deprecated. Use the `.spec.tools.helm` configuration for specifying the helm version to use. See https://github.com/PremiereGlobal/stim/blob/master/docs/DEPLOY.md for more details.") + // DEPRECATION: Auto-matching helm version is deprecated and the env variable below should be uncommented + // once this feature is removed + // envs = append(envs, "HELM_MATCH_SERVER=false") } // Since we're using Docker, we need to mount the Linux binaries From 68b7adaa982521d51beb939490879ada5a82b2a3 Mon Sep 17 00:00:00 2001 From: Chris Bartlett Date: Fri, 15 May 2020 16:45:08 -0600 Subject: [PATCH 3/4] removing leftover comment --- stimpacks/deploy/docker.go | 1 - 1 file changed, 1 deletion(-) diff --git a/stimpacks/deploy/docker.go b/stimpacks/deploy/docker.go index 99ee1c7..6077cef 100644 --- a/stimpacks/deploy/docker.go +++ b/stimpacks/deploy/docker.go @@ -36,7 +36,6 @@ func (d *Deploy) startDeployContainer(instance *Instance) { var envs []string deprecatedHelmVersionSet := false for _, e := range instance.Spec.EnvironmentVars { - // Using this environment variable for if e.Name == "HELM_VERSION" { d.log.Warn("The use of the HELM_VERSION environment variable for specifying Helm versions has been deprecated. Use the `.spec.tools.helm` configuration for specifying the helm version to use. See https://github.com/PremiereGlobal/stim/blob/master/docs/DEPLOY.md for more details.") deprecatedHelmVersionSet = true From 7ec589a02b9c9e5fb0bd558fff23a70c1d89a8f0 Mon Sep 17 00:00:00 2001 From: Chris Bartlett Date: Fri, 15 May 2020 17:51:59 -0600 Subject: [PATCH 4/4] fixing typos,etc. --- pkg/vault/token.go | 1 - stimpacks/deploy/docker.go | 12 ++++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/vault/token.go b/pkg/vault/token.go index a2ff21f..871a001 100644 --- a/pkg/vault/token.go +++ b/pkg/vault/token.go @@ -20,7 +20,6 @@ func (v *Vault) GetCurrentTokenTTL() (time.Duration, error) { //We have an unexpiring token return 24 * time.Hour, nil } - v.log.Debug("Data:", secret.Data) if err != nil { return 0, err } diff --git a/stimpacks/deploy/docker.go b/stimpacks/deploy/docker.go index 6077cef..b7c29dc 100644 --- a/stimpacks/deploy/docker.go +++ b/stimpacks/deploy/docker.go @@ -34,23 +34,23 @@ func (d *Deploy) startDeployContainer(instance *Instance) { } var envs []string - deprecatedHelmVersionSet := false + deprecatedHelmVersionSet := "" for _, e := range instance.Spec.EnvironmentVars { if e.Name == "HELM_VERSION" { d.log.Warn("The use of the HELM_VERSION environment variable for specifying Helm versions has been deprecated. Use the `.spec.tools.helm` configuration for specifying the helm version to use. See https://github.com/PremiereGlobal/stim/blob/master/docs/DEPLOY.md for more details.") - deprecatedHelmVersionSet = true + deprecatedHelmVersionSet = e.Value } envs = append(envs, fmt.Sprintf("%s=%s", e.Name, e.Value)) } if _, ok := instance.Spec.Tools["helm"]; ok { - if !deprecatedHelmVersionSet { + if deprecatedHelmVersionSet == "" { envs = append(envs, fmt.Sprintf("HELM_VERSION=%s", downloader.GetBaseVersion(instance.Spec.Tools["helm"].Version))) } else { - d.log.Warn("Both `spec.tools.helm` and the deprecated HELM_VERSION environment variable are set. HELM_VERSION is taking precedence") + d.log.Warn("Both `spec.tools.helm` and the deprecated HELM_VERSION environment variable are set. HELM_VERSION of '{}' is taking precedence", deprecatedHelmVersionSet) } - } else if !deprecatedHelmVersionSet { - d.log.Warn("Auto-detection of Helm v2 versions now deprecated. Use the `.spec.tools.helm` configuration for specifying the helm version to use. See https://github.com/PremiereGlobal/stim/blob/master/docs/DEPLOY.md for more details.") + } else if deprecatedHelmVersionSet == "" { + d.log.Warn("Auto-detection of Helm v2 versions is now deprecated. Use the `.spec.tools.helm` configuration for specifying the helm version to use. See https://github.com/PremiereGlobal/stim/blob/master/docs/DEPLOY.md for more details.") // DEPRECATION: Auto-matching helm version is deprecated and the env variable below should be uncommented // once this feature is removed // envs = append(envs, "HELM_MATCH_SERVER=false")