diff --git a/Makefile b/Makefile index f29e5ed2..0492ee43 100644 --- a/Makefile +++ b/Makefile @@ -26,15 +26,15 @@ integration: .PHONY: integration cross: - env CGO_ENABLED=0 gox -os '!openbsd !freebsd !netbsd' -arch '!arm !mips !mipsle !mips64 !mips64le !s390x' -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags '-X main.Version=${TAG}' ${TARGETS} + env CGO_ENABLED=0 gox -os '!openbsd !freebsd !netbsd' -arch '!arm !mips !mipsle !mips64 !mips64le !s390x' -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags '-X github.com/roboll/helmfile/pkg/app/version.Version=${TAG}' ${TARGETS} .PHONY: cross static-linux: - env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOFLAGS=-mod=vendor go build -o "dist/helmfile_linux_amd64" -ldflags '-X main.Version=${TAG}' ${TARGETS} + env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOFLAGS=-mod=vendor go build -o "dist/helmfile_linux_amd64" -ldflags '-X github.com/roboll/helmfile/pkg/app/version.Version=${TAG}' ${TARGETS} .PHONY: static-linux install: - env CGO_ENABLED=0 go install -ldflags '-X main.Version=${TAG}' ${TARGETS} + env CGO_ENABLED=0 go install -ldflags '-X github.com/roboll/helmfile/pkg/app/version.Version=${TAG}' ${TARGETS} .PHONY: install clean: diff --git a/go.mod b/go.mod index 52e9ad84..4fb2b55f 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/gosuri/uitable v0.0.3 github.com/hashicorp/go-getter v1.3.0 github.com/hashicorp/go-retryablehttp v0.6.3 // indirect + github.com/hashicorp/go-version v1.2.0 github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c // indirect github.com/huandu/xstrings v1.2.0 // indirect github.com/imdario/mergo v0.3.6 diff --git a/go.sum b/go.sum index 80c0b12a..baa3e772 100644 --- a/go.sum +++ b/go.sum @@ -941,6 +941,7 @@ google.golang.org/api v0.11.0 h1:n/qM3q0/rV2F0pox7o0CvNhlPvZAo7pLbef122cbLJ0= google.golang.org/api v0.11.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= google.golang.org/api v0.13.0 h1:Q3Ui3V3/CVinFWFiW39Iw0kMuVrRzYX0wN6OPFp0lTA= google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/api v0.14.0 h1:uMf5uLi4eQMRrMKhCplNik4U4H8Z6C1br3zOtAa/aDE= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.3.0 h1:FBSsiFRMz3LBeXIomRnVzrQwSDj4ibvcRexLG0LZGQk= diff --git a/main.go b/main.go index 25cf6b7b..cdeebf16 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "github.com/roboll/helmfile/pkg/app/version" "os" "strings" @@ -14,8 +15,6 @@ import ( "go.uber.org/zap/zapcore" ) -var Version string - var logger *zap.SugaredLogger func configureLogging(c *cli.Context) error { @@ -45,7 +44,7 @@ func main() { cliApp := cli.NewApp() cliApp.Name = "helmfile" cliApp.Usage = "" - cliApp.Version = Version + cliApp.Version = version.Version cliApp.Flags = []cli.Flag{ cli.StringFlag{ Name: "helm-binary, b", diff --git a/pkg/app/version/version.go b/pkg/app/version/version.go new file mode 100644 index 00000000..7f6928ef --- /dev/null +++ b/pkg/app/version/version.go @@ -0,0 +1,3 @@ +package version + +var Version string diff --git a/pkg/state/chart_dependency.go b/pkg/state/chart_dependency.go index ccd649a6..3ed1eb47 100644 --- a/pkg/state/chart_dependency.go +++ b/pkg/state/chart_dependency.go @@ -3,7 +3,9 @@ package state import ( "fmt" "github.com/Masterminds/semver" + goversion "github.com/hashicorp/go-version" "github.com/r3labs/diff" + "github.com/roboll/helmfile/pkg/app/version" "github.com/roboll/helmfile/pkg/helmexec" "go.uber.org/zap" "gopkg.in/yaml.v2" @@ -50,6 +52,7 @@ type ChartRequirements struct { } type ChartLockedRequirements struct { + Version string `yaml:"version"` ResolvedDependencies []ResolvedChartDependency `yaml:"dependencies"` Digest string `yaml:"digest"` Generated string `yaml:"generated"` @@ -374,6 +377,8 @@ func (m *chartDependencyManager) doUpdate(chartLockFile string, unresolved *Unre } } + lockedReqs.Version = version.Version + updatedLockFileContent, err = yaml.Marshal(lockedReqs) if err != nil { @@ -404,6 +409,25 @@ func (m *chartDependencyManager) Resolve(unresolved *UnresolvedDependencies) (*R return nil, false, err } + // Make sure go run main.go works and compatible with old lock files. + if version.Version != "" && lockedReqs.Version != "" { + lockedVersion, err := goversion.NewVersion(lockedReqs.Version) + + if err != nil { + return nil, false, err + } + + currentVersion, err := goversion.NewVersion(version.Version) + + if err != nil { + return nil, false, err + } + + if currentVersion.LessThan(lockedVersion) { + return nil, false, fmt.Errorf("the lockfile was created by Helmfile %s, which is newer than current %s; Please upgrade to Helmfile %s or greater", lockedVersion.Original(), currentVersion.Original(), lockedVersion.Original()) + } + } + resolved := &ResolvedDependencies{deps: map[string][]ResolvedChartDependency{}} for _, d := range lockedReqs.ResolvedDependencies { if err := resolved.add(d); err != nil {