From f208dd805c4e6c87e977350575f2cafc5fa4bef0 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Tue, 19 May 2020 17:13:17 +0200 Subject: [PATCH] Warn about namespace error (instead of aborting) Mock namespace in orphans test, add test for image only case Add test cache cleanup to Makefile --- Makefile | 3 ++- cfg/types.go | 6 ++---- cmd/common.go | 6 +----- cmd/orphans_test.go | 9 +++++++++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 8e919c9..a335b17 100644 --- a/Makefile +++ b/Makefile @@ -27,5 +27,6 @@ dist: goreleaser release --snapshot --rm-dist --skip-sign clean: - @echo 'Clean up build artifacts ...' + @echo 'Clean up test cache and build artifacts ...' + go clean -testcache rm -rf seiso dist/ diff --git a/cfg/types.go b/cfg/types.go index 99f22de..ca3d82f 100644 --- a/cfg/types.go +++ b/cfg/types.go @@ -1,8 +1,6 @@ package cfg import ( - "os" - log "github.com/sirupsen/logrus" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" core "k8s.io/client-go/kubernetes/typed/core/v1" @@ -55,8 +53,8 @@ type ( func NewDefaultConfig() *Configuration { namespace, err := kubernetes.Namespace() if err != nil { - log.Error("Unable to determine default namespace. Aborting.") - os.Exit(1) + log.Warning("Unable to determine default namespace. Falling back to: default") + namespace = "default" } return &Configuration{ Namespace: namespace, diff --git a/cmd/common.go b/cmd/common.go index 12e2820..30ae0ed 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -6,7 +6,6 @@ import ( "github.com/appuio/seiso/cfg" "github.com/appuio/seiso/pkg/git" - "github.com/appuio/seiso/pkg/kubernetes" "github.com/appuio/seiso/pkg/openshift" log "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -86,10 +85,7 @@ func addCommonFlagsForGit(cmd *cobra.Command, defaults *cfg.Configuration) { } func listImages() error { - namespace, err := kubernetes.Namespace() - if err != nil { - return err - } + namespace := config.Namespace imageStreams, err := openshift.ListImageStreams(namespace) if err != nil { return err diff --git a/cmd/orphans_test.go b/cmd/orphans_test.go index b44ded5..eac493e 100644 --- a/cmd/orphans_test.go +++ b/cmd/orphans_test.go @@ -27,6 +27,14 @@ func Test_splitNamespaceAndImagestream(t *testing.T) { expectedNamespace: "namespace", expectedImage: "image", }, + { + name: "ShouldReturnActiveNamespace_IfRepoDoesNotContainNamespace", + args: args{ + repo: "image", + }, + expectedNamespace: "currently-active-ns", + expectedImage: "image", + }, { name: "ShouldThrowError_IfRepoDoesNotContainImage", args: args{ @@ -57,6 +65,7 @@ func Test_splitNamespaceAndImagestream(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + config.Namespace = "currently-active-ns" namespace, image, err := splitNamespaceAndImagestream(tt.args.repo) if tt.wantErr { assert.Error(t, err)