fix(*): handle unreleased versioning

Adds an `unreleased` flag to the version if not building from HEAD of a
tag. The compatibility check is bypassed if the client or server are
unreleased.

fixes #2110
pull/2366/head
Adam Reese 7 years ago
parent 0ed79d9ae7
commit 2e819e014d
No known key found for this signature in database
GPG Key ID: 06F35E60A7A18DD6

@ -408,7 +408,7 @@ func WithMaxHistory(max int32) HistoryOption {
// NewContext creates a versioned context. // NewContext creates a versioned context.
func NewContext() context.Context { func NewContext() context.Context {
md := metadata.Pairs("x-helm-api-client", version.Version) md := metadata.Pairs("x-helm-api-client", version.GetVersion())
return metadata.NewContext(context.TODO(), md) return metadata.NewContext(context.TODO(), md)
} }

@ -38,6 +38,7 @@ import (
"k8s.io/helm/pkg/storage" "k8s.io/helm/pkg/storage"
"k8s.io/helm/pkg/storage/driver" "k8s.io/helm/pkg/storage/driver"
"k8s.io/helm/pkg/tiller/environment" "k8s.io/helm/pkg/tiller/environment"
"k8s.io/helm/pkg/version"
) )
const notesText = "my notes here" const notesText = "my notes here"
@ -465,6 +466,7 @@ func TestInstallRelease_WithNotesRendered(t *testing.T) {
} }
func TestInstallRelease_TillerVersion(t *testing.T) { func TestInstallRelease_TillerVersion(t *testing.T) {
version.Version = "2.2.0"
c := helm.NewContext() c := helm.NewContext()
rs := rsFixture() rs := rsFixture()
@ -486,6 +488,7 @@ func TestInstallRelease_TillerVersion(t *testing.T) {
} }
func TestInstallRelease_WrongTillerVersion(t *testing.T) { func TestInstallRelease_WrongTillerVersion(t *testing.T) {
version.Version = "2.2.0"
c := helm.NewContext() c := helm.NewContext()
rs := rsFixture() rs := rsFixture()

@ -88,8 +88,8 @@ func versionFromContext(ctx context.Context) string {
func checkClientVersion(ctx context.Context) error { func checkClientVersion(ctx context.Context) error {
clientVersion := versionFromContext(ctx) clientVersion := versionFromContext(ctx)
if !version.IsCompatible(clientVersion, version.Version) { if !version.IsCompatible(clientVersion, version.GetVersion()) {
return fmt.Errorf("incompatible versions client: %s server: %s", clientVersion, version.Version) return fmt.Errorf("incompatible versions client[%s] server[%s]", clientVersion, version.GetVersion())
} }
return nil return nil
} }

@ -18,12 +18,16 @@ package version // import "k8s.io/helm/pkg/version"
import ( import (
"fmt" "fmt"
"strings"
"github.com/Masterminds/semver" "github.com/Masterminds/semver"
) )
// IsCompatible tests if a client and server version are compatible. // IsCompatible tests if a client and server version are compatible.
func IsCompatible(client, server string) bool { func IsCompatible(client, server string) bool {
if isUnreleased(client) || isUnreleased(server) {
return true
}
cv, err := semver.NewVersion(client) cv, err := semver.NewVersion(client)
if err != nil { if err != nil {
return false return false
@ -55,3 +59,7 @@ func IsCompatibleRange(constraint, ver string) bool {
} }
return c.Check(sv) return c.Check(sv)
} }
func isUnreleased(v string) bool {
return strings.HasSuffix(v, "unreleased")
}

@ -26,10 +26,10 @@ var (
// Increment major number for new feature additions and behavioral changes. // Increment major number for new feature additions and behavioral changes.
// Increment minor number for bug fixes and performance enhancements. // Increment minor number for bug fixes and performance enhancements.
// Increment patch number for critical fixes to existing releases. // Increment patch number for critical fixes to existing releases.
Version = "v2.3.0" Version = "v2.3.x"
// BuildMetadata is extra build time data // BuildMetadata is extra build time data
BuildMetadata = "" BuildMetadata = "unreleased"
// GitCommit is the git sha1 // GitCommit is the git sha1
GitCommit = "" GitCommit = ""
// GitTreeState is the state of the git tree // GitTreeState is the state of the git tree

@ -1,9 +1,9 @@
MUTABLE_VERSION ?= canary MUTABLE_VERSION := canary
GIT_COMMIT ?= $(shell git rev-parse HEAD) GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_SHA ?= $(shell git rev-parse --short HEAD) GIT_SHA = $(shell git rev-parse --short HEAD)
GIT_TAG ?= $(shell git describe --tags --abbrev=0 2>/dev/null) GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
GIT_DIRTY ?= $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean") GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
ifdef VERSION ifdef VERSION
DOCKER_VERSION = $(VERSION) DOCKER_VERSION = $(VERSION)
@ -11,25 +11,38 @@ ifdef VERSION
endif endif
DOCKER_VERSION ?= git-${GIT_SHA} DOCKER_VERSION ?= git-${GIT_SHA}
BINARY_VERSION ?= ${GIT_TAG}-${GIT_SHA} BINARY_VERSION ?= ${GIT_TAG}
IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${SHORT_NAME}:${DOCKER_VERSION} # Only set Version if building a tag or VERSION is set
MUTABLE_IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${SHORT_NAME}:${MUTABLE_VERSION} ifneq ($(BINARY_VERSION),)
LDFLAGS += -X k8s.io/helm/pkg/version.Version=${BINARY_VERSION}
endif
# Clear the "unreleased" string in BuildMetadata
ifneq ($(GIT_TAG),)
LDFLAGS += -X k8s.io/helm/pkg/version.BuildMetadata=
endif
LDFLAGS += -X k8s.io/helm/pkg/version.Version=${GIT_TAG}
LDFLAGS += -X k8s.io/helm/pkg/version.GitCommit=${GIT_COMMIT} LDFLAGS += -X k8s.io/helm/pkg/version.GitCommit=${GIT_COMMIT}
LDFLAGS += -X k8s.io/helm/pkg/version.GitTreeState=${GIT_DIRTY} LDFLAGS += -X k8s.io/helm/pkg/version.GitTreeState=${GIT_DIRTY}
IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${SHORT_NAME}:${DOCKER_VERSION}
MUTABLE_IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${SHORT_NAME}:${MUTABLE_VERSION}
DOCKER_PUSH = docker push DOCKER_PUSH = docker push
ifeq ($(DOCKER_REGISTRY),gcr.io) ifeq ($(DOCKER_REGISTRY),gcr.io)
DOCKER_PUSH = gcloud docker push DOCKER_PUSH = gcloud docker push
endif endif
info: info:
@echo "Build tag: ${DOCKER_VERSION}" @echo "Version: ${VERSION}"
@echo "Registry: ${DOCKER_REGISTRY}" @echo "Git Tag: ${GIT_TAG}"
@echo "Immutable tag: ${IMAGE}" @echo "Git Commit: ${GIT_COMMIT}"
@echo "Mutable tag: ${MUTABLE_IMAGE}" @echo "Git Tree State: ${GIT_DIRTY}"
@echo "Docker Version: ${DOCKER_VERSION}"
@echo "Registry: ${DOCKER_REGISTRY}"
@echo "Immutable Image: ${IMAGE}"
@echo "Mutable Image: ${MUTABLE_IMAGE}"
.PHONY: docker-push .PHONY: docker-push
docker-push: docker-mutable-push docker-immutable-push docker-push: docker-mutable-push docker-immutable-push

Loading…
Cancel
Save