mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #93951 from eddiezane/ez/update-client-go-out-of-cluster-example
client-go: update out of cluster example with HomeDir func
This commit is contained in:
commit
9d3a8a0b96
@ -21,6 +21,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",
|
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",
|
||||||
|
"//staging/src/k8s.io/client-go/util/homedir:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -29,6 +28,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
|
"k8s.io/client-go/util/homedir"
|
||||||
//
|
//
|
||||||
// Uncomment to load all auth plugins
|
// Uncomment to load all auth plugins
|
||||||
// _ "k8s.io/client-go/plugin/pkg/client/auth"
|
// _ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||||
@ -42,7 +42,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var kubeconfig *string
|
var kubeconfig *string
|
||||||
if home := homeDir(); home != "" {
|
if home := homedir.HomeDir(); home != "" {
|
||||||
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
|
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
|
||||||
} else {
|
} else {
|
||||||
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
|
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
|
||||||
@ -87,10 +87,3 @@ func main() {
|
|||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func homeDir() string {
|
|
||||||
if h := os.Getenv("HOME"); h != "" {
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
return os.Getenv("USERPROFILE") // windows
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user