Skip to content

Commit

Permalink
Merge pull request kubesphere#3961 from LinuxSuRen/feat-k8s-local-client
Browse files Browse the repository at this point in the history
Make ks-apiserver be easier to run locally with kube config
  • Loading branch information
ks-ci-bot authored Jun 21, 2021
2 parents 9eed338 + 8e40702 commit d4be6d7
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions pkg/simple/client/k8s/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ package k8s

import (
"os"
"os/user"
"path"

"k8s.io/client-go/util/homedir"

"github.com/spf13/pflag"

Expand All @@ -44,12 +48,26 @@ type KubernetesOptions struct {
}

// NewKubernetesOptions returns a `zero` instance
func NewKubernetesOptions() *KubernetesOptions {
return &KubernetesOptions{
KubeConfig: "",
QPS: 1e6,
Burst: 1e6,
func NewKubernetesOptions() (option *KubernetesOptions) {
option = &KubernetesOptions{
QPS: 1e6,
Burst: 1e6,
}

// make it be easier for those who wants to run api-server locally
homePath := homedir.HomeDir()
if homePath == "" {
// try os/user.HomeDir when $HOME is unset.
if u, err := user.Current(); err == nil {
homePath = u.HomeDir
}
}

userHomeConfig := path.Join(homePath, ".kube/config")
if _, err := os.Stat(userHomeConfig); err == nil {
option.KubeConfig = userHomeConfig
}
return
}

func (k *KubernetesOptions) Validate() []error {
Expand Down

0 comments on commit d4be6d7

Please sign in to comment.