Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #34 from ericchiang/default-namespace
Browse files Browse the repository at this point in the history
*: use the "default" namespace if another isn't specified
  • Loading branch information
ericchiang authored Mar 4, 2017
2 parents 9fe8b1e + 391fc2e commit a489d24
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
11 changes: 9 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const (
AllNamespaces = allNamespaces
// Actual definition is private in case we want to change it later.
allNamespaces = ""

namespaceDefault = "default"
)

// String returns a pointer to a string. Useful for creating API objects
Expand Down Expand Up @@ -165,7 +167,7 @@ func NewClient(config *Config) (*Client, error) {
return nil, errors.New("multiple users but no current context")
}

return newClient(config.Clusters[0].Cluster, config.AuthInfos[0].AuthInfo, "")
return newClient(config.Clusters[0].Cluster, config.AuthInfos[0].AuthInfo, namespaceDefault)
}

var ctx Context
Expand Down Expand Up @@ -216,7 +218,12 @@ userFound:
return nil, fmt.Errorf("no cluster named %q", ctx.Cluster)
clusterFound:

return newClient(cluster, user, ctx.Namespace)
namespace := ctx.Namespace
if namespace == "" {
namespace = namespaceDefault
}

return newClient(cluster, user, namespace)
}

// NewInClusterClient returns a client that uses the service account bearer token mounted
Expand Down
25 changes: 25 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,28 @@ func TestWatchNamespace(t *testing.T) {
t.Fatalf("delete namespace: %v", err)
}
}

func TestDefaultNamespace(t *testing.T) {
c := &Config{
Clusters: []NamedCluster{
{
Name: "local",
Cluster: Cluster{
Server: "http://localhost:8080",
},
},
},
AuthInfos: []NamedAuthInfo{
{
Name: "local",
},
},
}
cli, err := NewClient(c)
if err != nil {
t.Fatal(err)
}
if cli.Namespace != "default" {
t.Errorf("expected namespace=%q got=%q", "default", cli.Namespace)
}
}

0 comments on commit a489d24

Please sign in to comment.