Skip to content

Commit

Permalink
Merge pull request #4 from kitagry/fix-only-name
Browse files Browse the repository at this point in the history
Fix default namespace
  • Loading branch information
kitagry authored Jul 7, 2021
2 parents 992c795 + 53da769 commit 4d95a4c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/kitagry/kj
go 1.16

require (
github.com/goccy/go-yaml v1.8.9
github.com/goccy/go-yaml v1.8.10
github.com/mattn/go-tty v0.0.3
k8s.io/api v0.21.1
k8s.io/apimachinery v0.21.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/goccy/go-yaml v1.8.9 h1:4AEXg2qx+/w29jXnXpMY6mTckmYu1TMoHteKuMf0HFg=
github.com/goccy/go-yaml v1.8.9/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA=
github.com/goccy/go-yaml v1.8.10 h1:XpBOLD8cmOZlLYjUFPqSZZ+Ubi4/UKxO2eXyhg5WuAA=
github.com/goccy/go-yaml v1.8.10/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down
9 changes: 7 additions & 2 deletions kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ func loadKubeconfig(path string) (k Kubeconfig, err error) {
func (k Kubeconfig) CurrentNamespace() string {
kc, ok := k.currentContext()
if !ok {
return ""
return "default"
}

if kc.Namespace == "" {
return "default"
}
return kc.Namespace
}

Expand All @@ -47,5 +50,7 @@ func (k Kubeconfig) currentContext() (KubeContext, bool) {
return kc.Context, true
}
}
return KubeContext{}, false
return KubeContext{
Namespace: "default",
}, false
}
4 changes: 2 additions & 2 deletions kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func TestKubeconfig_CurrentNamespace(t *testing.T) {
},
"Context has no namespace": {
currentContext: "a",
expect: "",
expect: "default",
},
"Context doesn't exist": {
currentContext: "not exist context",
expect: "",
expect: "default",
},
}

Expand Down

0 comments on commit 4d95a4c

Please sign in to comment.