Skip to content

Commit

Permalink
fix(client): load kubeconfig from client pkg instead of pre-run of ro…
Browse files Browse the repository at this point in the history
…ot cmd
  • Loading branch information
bostrt committed Jun 30, 2022
1 parent 2699f5d commit f0788fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
12 changes: 0 additions & 12 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/vmware-tanzu/sonobuoy/cmd/sonobuoy/app"

"github.com/openshift/provider-certification-tool/pkg/assets"
"github.com/openshift/provider-certification-tool/pkg/client"
"github.com/openshift/provider-certification-tool/pkg/destroy"
"github.com/openshift/provider-certification-tool/pkg/retrieve"
"github.com/openshift/provider-certification-tool/pkg/run"
Expand Down Expand Up @@ -39,17 +38,6 @@ var rootCmd = &cobra.Command{
customFormatter := new(log.TextFormatter)
customFormatter.FullTimestamp = true
log.SetFormatter(customFormatter)

// Save kubeconfig
client.Kubeconfig = viper.GetString("kubeconfig")
if client.Kubeconfig == "" {
log.Fatal("--kubeconfig or KUBECONFIG environment variable must be set")
}

// Check kubeconfig exists
if _, err := os.Stat(client.Kubeconfig); err != nil {
log.Fatal(err)
}
},
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package client

import (
"os"

log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/vmware-tanzu/sonobuoy/pkg/client"
sonodynamic "github.com/vmware-tanzu/sonobuoy/pkg/dynamic"
"k8s.io/client-go/kubernetes"
Expand All @@ -11,6 +15,20 @@ import (
var Kubeconfig string

func CreateRestConfig() (*rest.Config, error) {

// Singleton kubeconfig
if Kubeconfig == "" {
Kubeconfig = viper.GetString("kubeconfig")
if Kubeconfig == "" {
log.Fatal("--kubeconfig or KUBECONFIG environment variable must be set")
}

// Check kubeconfig exists
if _, err := os.Stat(Kubeconfig); err != nil {
log.Fatal(err)
}
}

clientConfig, err := clientcmd.BuildConfigFromFlags("", Kubeconfig)
return clientConfig, err
}
Expand Down

0 comments on commit f0788fb

Please sign in to comment.