Skip to content

Commit 9d3a8a0

Browse files
authored
Merge pull request kubernetes#93951 from eddiezane/ez/update-client-go-out-of-cluster-example
client-go: update out of cluster example with HomeDir func
2 parents 88fb266 + 522cba4 commit 9d3a8a0

File tree

2 files changed

+3
-9
lines changed
  • staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration

2 files changed

+3
-9
lines changed

staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ go_library(
2121
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
2222
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
2323
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",
24+
"//staging/src/k8s.io/client-go/util/homedir:go_default_library",
2425
],
2526
)
2627

staging/src/k8s.io/client-go/examples/out-of-cluster-client-configuration/main.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import (
2121
"context"
2222
"flag"
2323
"fmt"
24-
"os"
2524
"path/filepath"
2625
"time"
2726

2827
"k8s.io/apimachinery/pkg/api/errors"
2928
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3029
"k8s.io/client-go/kubernetes"
3130
"k8s.io/client-go/tools/clientcmd"
31+
"k8s.io/client-go/util/homedir"
3232
//
3333
// Uncomment to load all auth plugins
3434
// _ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -42,7 +42,7 @@ import (
4242

4343
func main() {
4444
var kubeconfig *string
45-
if home := homeDir(); home != "" {
45+
if home := homedir.HomeDir(); home != "" {
4646
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
4747
} else {
4848
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
@@ -87,10 +87,3 @@ func main() {
8787
time.Sleep(10 * time.Second)
8888
}
8989
}
90-
91-
func homeDir() string {
92-
if h := os.Getenv("HOME"); h != "" {
93-
return h
94-
}
95-
return os.Getenv("USERPROFILE") // windows
96-
}

0 commit comments

Comments
 (0)