Skip to content

Commit

Permalink
if no kubeconfig use inclusterconfig test (#5603)
Browse files Browse the repository at this point in the history
* if no kubeconfig use inclusterconfig test

* use default if not given
  • Loading branch information
vaikas authored Jul 22, 2021
1 parent 003a8a2 commit 7251c1b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions test/lib/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"knative.dev/pkg/test"
configtracing "knative.dev/pkg/tracing/config"

Expand Down Expand Up @@ -69,9 +70,20 @@ func NewClient(configPath string, clusterName string, namespace string, t *testi
var err error

client := &Client{}
client.Config, err = test.BuildClientConfig(configPath, clusterName)
if err != nil {
return nil, err
if configPath != "" {
client.Config, err = test.BuildClientConfig(configPath, clusterName)
if err != nil {
return nil, err
}
} else {
client.Config, err = rest.InClusterConfig()
if err != nil {
// If no in-cluster config, try the default location in the user's home directory.
client.Config, err = test.BuildClientConfig(clientcmd.RecommendedHomeFile, clusterName)
if err != nil {
return nil, err
}
}
}
client.Kube, err = kubernetes.NewForConfig(client.Config)
if err != nil {
Expand Down

0 comments on commit 7251c1b

Please sign in to comment.