Skip to content

Commit

Permalink
Add --force-update to helm repo add command (breaking change in 3.3.2…
Browse files Browse the repository at this point in the history
… helm)
  • Loading branch information
Mateusz Kubaczyk committed Sep 21, 2020
1 parent 46e1ae4 commit 4b83bf8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
12 changes: 2 additions & 10 deletions internal/app/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"strings"

version "github.com/hashicorp/go-version"
"github.com/imdario/mergo"
"github.com/joho/godotenv"
)
Expand Down Expand Up @@ -144,15 +143,8 @@ func (c *cli) parse() {
c.parallel = 1
}

helmVersion := strings.TrimSpace(getHelmVersion())
extractedHelmVersion := helmVersion
if !strings.HasPrefix(helmVersion, "v") {
extractedHelmVersion = strings.TrimSpace(strings.Split(helmVersion, ":")[1])
}
log.Verbose("Helm client version: " + extractedHelmVersion)
v1, _ := version.NewVersion(extractedHelmVersion)
jsonConstraint, _ := version.NewConstraint(">=3.0.0")
if !jsonConstraint.Check(v1) {
log.Verbose("Helm client version: " + strings.TrimSpace(getHelmVersion()))
if checkHelmVersion("<3.0.0") {
log.Fatal("this version of Helmsman does not work with helm releases older than 3.0.0")
}

Expand Down
21 changes: 20 additions & 1 deletion internal/app/helm_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/hashicorp/go-version"
"net/url"
"strings"

Expand Down Expand Up @@ -57,6 +58,20 @@ func getHelmVersion() string {
return result.output
}

func checkHelmVersion(constraint string) bool {
helmVersion := strings.TrimSpace(getHelmVersion())
extractedHelmVersion := helmVersion
if !strings.HasPrefix(helmVersion, "v") {
extractedHelmVersion = strings.TrimSpace(strings.Split(helmVersion, ":")[1])
}
v, _ := version.NewVersion(extractedHelmVersion)
jsonConstraint, _ := version.NewConstraint(constraint)
if jsonConstraint.Check(v) {
return true
}
return false
}

// helmPluginExists returns true if the plugin is present in the environment and false otherwise.
// It takes as input the plugin's name to check if it is recognizable or not. e.g. diff
func helmPluginExists(plugin string) bool {
Expand Down Expand Up @@ -132,7 +147,11 @@ func addHelmRepos(repos map[string]string) error {
repoLink = u.String()
}

cmd := helmCmd(concat([]string{"repo", "add", repoName, repoLink}, basicAuthArgs), "Adding helm repository [ "+repoName+" ]")
repoAddFlags := ""
if checkHelmVersion(">=3.3.2") {
repoAddFlags += "--force-update"
}
cmd := helmCmd(concat([]string{"repo", "add", repoAddFlags, repoName, repoLink}, basicAuthArgs), "Adding helm repository [ "+repoName+" ]")
// check current repository against existing repositories map in order to make sure it's missing and needs to be added
if existingRepoUrl, ok := existingRepos[repoName]; ok {
if repoLink == existingRepoUrl {
Expand Down

0 comments on commit 4b83bf8

Please sign in to comment.