mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-04-28 03:17:00 +00:00
Merge pull request #62 from jrnt30/default-home-resolution
Allow default kubeconfig resolution
This commit is contained in:
@@ -24,8 +24,11 @@ import (
|
||||
// Config returns a *rest.Config, using either the kubeconfig (if specified) or an in-cluster
|
||||
// configuration.
|
||||
func Config(kubeconfig string) (*rest.Config, error) {
|
||||
if len(kubeconfig) > 0 {
|
||||
return clientcmd.BuildConfigFromFlags("", kubeconfig)
|
||||
loader := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
loader.ExplicitPath = kubeconfig
|
||||
clientConfig, err := clientcmd.BuildConfigFromKubeconfigGetter("", loader.Load)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return rest.InClusterConfig()
|
||||
return clientConfig, nil
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ limitations under the License.
|
||||
package client
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
"github.com/heptio/ark/pkg/generated/clientset"
|
||||
@@ -53,13 +51,7 @@ func (f *factory) BindFlags(flags *pflag.FlagSet) {
|
||||
}
|
||||
|
||||
func (f *factory) Client() (clientset.Interface, error) {
|
||||
kubeconfig := f.kubeconfig
|
||||
if kubeconfig == "" {
|
||||
// if the command line flag was not specified, try the environment variable
|
||||
kubeconfig = os.Getenv("KUBECONFIG")
|
||||
}
|
||||
|
||||
clientConfig, err := Config(kubeconfig)
|
||||
clientConfig, err := Config(f.kubeconfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user