Skip to content

Commit

Permalink
Fail kudo init if version is unknown. (#1556)
Browse files Browse the repository at this point in the history
Co-authored-by: Ken Sipe <kensipe@gmail.com>
Signed-off-by: Marcin Owsiany <mowsiany@D2iQ.com>
  • Loading branch information
porridge and kensipe committed Jun 24, 2020
1 parent 8b25afa commit 80f5a21
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ DOCKER_IMG ?= kudobuilder/controller
EXECUTABLE := manager
CLI := kubectl-kudo
GIT_VERSION_PATH := github.com/kudobuilder/kudo/pkg/version.gitVersion
GIT_VERSION := $(shell git describe --abbrev=0 --tags | cut -b 2-)
GIT_VERSION := $(shell git describe --abbrev=0 --tags --candidates=0 2>/dev/null || echo not-built-on-release)
GIT_COMMIT_PATH := github.com/kudobuilder/kudo/pkg/version.gitCommit
GIT_COMMIT := $(shell git rev-parse HEAD | cut -b -8)
SOURCE_DATE_EPOCH := $(shell git show -s --format=format:%ct HEAD)
BUILD_DATE_PATH := github.com/kudobuilder/kudo/pkg/version.buildDate
DATE_FMT := "%Y-%m-%dT%H:%M:%SZ"
BUILD_DATE := $(shell date -u -d "@$SOURCE_DATE_EPOCH" "+${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "+${DATE_FMT}" 2>/dev/null || date -u "+${DATE_FMT}")
LDFLAGS := -X ${GIT_VERSION_PATH}=${GIT_VERSION} -X ${GIT_COMMIT_PATH}=${GIT_COMMIT} -X ${BUILD_DATE_PATH}=${BUILD_DATE}
LDFLAGS := -X ${GIT_VERSION_PATH}=${GIT_VERSION:v%=%} -X ${GIT_COMMIT_PATH}=${GIT_COMMIT} -X ${BUILD_DATE_PATH}=${BUILD_DATE}
GOLANGCI_LINT_VER = "1.23.8"
SUPPORTED_PLATFORMS = amd64 arm64

Expand Down
2 changes: 2 additions & 0 deletions pkg/kudoctl/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func (initCmd *initCmd) run() error {
// if image provided switch to it.
if initCmd.image != "" {
opts.Image = initCmd.image
} else if opts.Version == "not-built-on-release" {
return errors.New("cannot infer controller docker image to use - not a released binary; please override with a command-line flag")
}
if initCmd.imagePullPolicy != "" {
switch initCmd.imagePullPolicy {
Expand Down
4 changes: 4 additions & 0 deletions pkg/kudoctl/cmd/init_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func TestIntegInitForCRDs(t *testing.T) {
fs: afero.NewMemMapFs(),
client: kclient,
crdOnly: true,
version: "dev",
}
err = cmd.run()
assert.NoError(t, err)
Expand Down Expand Up @@ -156,6 +157,7 @@ func TestIntegInitWithNameSpace(t *testing.T) {
client: kclient,
ns: namespace,
selfSignedWebhookCA: true,
version: "dev",
}

// On first attempt, the namespace does not exist, so the error is expected.
Expand Down Expand Up @@ -282,6 +284,7 @@ func TestInitWithServiceAccount(t *testing.T) {
ns: namespace,
serviceAccount: "test-account",
selfSignedWebhookCA: true,
version: "dev",
}

ns := testutils.NewResource("v1", "Namespace", namespace, "")
Expand Down Expand Up @@ -368,6 +371,7 @@ func TestNoErrorOnReInit(t *testing.T) {
fs: afero.NewMemMapFs(),
client: kclient,
crdOnly: true,
version: "dev",
}
err = cmd.run()
assert.NoError(t, err)
Expand Down
18 changes: 10 additions & 8 deletions pkg/kudoctl/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestInitCmd_exists(t *testing.T) {
out: &buf,
fs: afero.NewMemMapFs(),
client: &kube.Client{KubeClient: fc, ExtClient: fc2},
image: "fake",
selfSignedWebhookCA: true,
}
clog.InitWithFlags(nil, &buf)
Expand Down Expand Up @@ -81,11 +82,12 @@ func TestInitCmd_output(t *testing.T) {
var buf bytes.Buffer
var errOut bytes.Buffer
cmd := &initCmd{
out: &buf,
errOut: &errOut,
client: client,
output: s,
dryRun: true,
out: &buf,
errOut: &errOut,
client: client,
output: s,
dryRun: true,
version: "dev",
}
// ensure that we can marshal
if err := cmd.run(); err != nil {
Expand Down Expand Up @@ -159,9 +161,9 @@ func TestInitCmd_yamlOutput(t *testing.T) {
goldenFile string
flags map[string]string
}{
{"custom namespace", "deploy-kudo-ns.yaml", map[string]string{"dry-run": "true", "output": "yaml", "namespace": "foo"}},
{"yaml output", "deploy-kudo.yaml", map[string]string{"dry-run": "true", "output": "yaml"}},
{"service account", "deploy-kudo-sa.yaml", map[string]string{"dry-run": "true", "output": "yaml", "service-account": "safoo", "namespace": "foo"}},
{"custom namespace", "deploy-kudo-ns.yaml", map[string]string{"dry-run": "true", "output": "yaml", "namespace": "foo", "version": "dev"}},
{"yaml output", "deploy-kudo.yaml", map[string]string{"dry-run": "true", "output": "yaml", "version": "dev"}},
{"service account", "deploy-kudo-sa.yaml", map[string]string{"dry-run": "true", "output": "yaml", "service-account": "safoo", "namespace": "foo", "version": "dev"}},
}

for _, tt := range tests {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kudoctl/cmd/testdata/newop/operator.yaml.golden
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: kudo.dev/v1beta1
kudoVersion: dev
kudoVersion: not-built-on-release
name: newop
operatorVersion: 0.1.0
plans: {}
Expand Down
3 changes: 1 addition & 2 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ func Get() Info {
// on dev box, lets use a env var for version
gitVersion = os.Getenv("KUDO_DEV_VERSION")
if gitVersion == "" {
gitVersion = "dev"
gitVersion = "not-built-on-release"
}
gitCommit = "dev"
//TODO (kensipe): add debug message!
}

return Info{
Expand Down

0 comments on commit 80f5a21

Please sign in to comment.