Skip to content

Commit

Permalink
Merge pull request #55 from PremiereGlobal/helm_version_fixes
Browse files Browse the repository at this point in the history
Helm version fixes
  • Loading branch information
bartlettc22 authored May 16, 2020
2 parents c298207 + 7ec589a commit 4ebb760
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion pkg/vault/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 17 additions & 2 deletions stimpacks/deploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {

Expand All @@ -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 {

Expand All @@ -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 == "" {
Expand Down Expand Up @@ -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 {

Expand Down
25 changes: 22 additions & 3 deletions stimpacks/deploy/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,9 +33,27 @@ 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 := ""
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 = e.Value
}
envs = append(envs, fmt.Sprintf("%s=%s", e.Name, e.Value))
}

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 of '{}' is taking precedence", deprecatedHelmVersionSet)
}
} 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")
}

// Since we're using Docker, we need to mount the Linux binaries
Expand Down

0 comments on commit 4ebb760

Please sign in to comment.