Make ks-apiserver be easier to run locally with kube config

Signed-off-by: rick <linuxsuren@users.noreply.github.com>
This commit is contained in:
rick
2021-06-10 21:01:38 +08:00
parent c2c5348f9b
commit 90f5a44911

View File

@@ -18,6 +18,9 @@ package k8s
import (
"os"
"path"
"k8s.io/client-go/util/homedir"
"github.com/spf13/pflag"
@@ -44,12 +47,18 @@ 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
userHomeConfig := path.Join(homedir.HomeDir(), ".kube/config")
if _, err := os.Stat(userHomeConfig); !os.IsNotExist(err) {
option.KubeConfig = userHomeConfig
}
return
}
func (k *KubernetesOptions) Validate() []error {