Skip to content

Commit

Permalink
Warn about namespace error (instead of aborting)
Browse files Browse the repository at this point in the history
Mock namespace in orphans test, add test for image only case

Add test cache cleanup to Makefile
  • Loading branch information
bittner authored and zugao committed May 19, 2020
1 parent 4767599 commit f208dd8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
6 changes: 2 additions & 4 deletions cfg/types.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions cmd/orphans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f208dd8

Please sign in to comment.