add kubectl/kubeconfig/quota/terminal api, but quota api is tempoary, will be changed as soon
This commit is contained in:
@@ -20,8 +20,20 @@ package options
|
||||
import (
|
||||
goflag "flag"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
const (
|
||||
// High enough QPS to fit all expected use cases. QPS=0 is not set here, because
|
||||
// client code is overriding it.
|
||||
DefaultQPS = 1e6
|
||||
// High enough Burst to fit all expected use cases. Burst=0 is not set here, because
|
||||
// client code is overriding it.
|
||||
DefaultBurst = 1e6
|
||||
)
|
||||
|
||||
// ServerRunOptions runs a kubernetes api server.
|
||||
@@ -34,6 +46,11 @@ type ServerRunOptions struct {
|
||||
certFile string
|
||||
keyFile string
|
||||
kubeConfigFile string
|
||||
etcdEndpoints string
|
||||
etcdCertFile string
|
||||
etcdKeyFile string
|
||||
etcdCaFile string
|
||||
kubectlImage string
|
||||
}
|
||||
|
||||
// NewServerRunOptions creates a new ServerRunOptions object with default parameters
|
||||
@@ -66,6 +83,20 @@ func (s *ServerRunOptions) addFlags(fs *pflag.FlagSet) {
|
||||
|
||||
fs.StringVar(&s.kubeConfigFile, "kubeconfig", "",
|
||||
"Path to kubeconfig file with authorization and master location information.")
|
||||
|
||||
fs.StringVar(&s.etcdEndpoints, "etcd-endpoints", "",
|
||||
"Server addresses of etcd")
|
||||
fs.StringVar(&s.etcdCertFile, "etcd-tls-cert-file", "",
|
||||
"Cert File use to connect etcd in https mode.")
|
||||
|
||||
fs.StringVar(&s.etcdKeyFile, "etcd-tls-key-file", "",
|
||||
"Privatekey File use to connect etcd in https mode.")
|
||||
|
||||
fs.StringVar(&s.etcdCaFile, "etcd-tls-ca-file", "",
|
||||
"CA Fileuse to connect etcd in https mode.")
|
||||
|
||||
fs.StringVar(&s.kubectlImage, "kubectl-image", "kubectl:1.0",
|
||||
"kubectl pod's image")
|
||||
}
|
||||
|
||||
func (s *ServerRunOptions) GetApiServerHost() string {
|
||||
@@ -100,6 +131,56 @@ func (s *ServerRunOptions) GetKubeConfigFile() string {
|
||||
return s.kubeConfigFile
|
||||
}
|
||||
|
||||
func (s *ServerRunOptions) GetKubeConfig() (kubeConfig *rest.Config, err error) {
|
||||
|
||||
kubeConfigFile := s.kubeConfigFile
|
||||
|
||||
if len(kubeConfigFile) > 0 {
|
||||
|
||||
kubeConfig, err = clientcmd.BuildConfigFromFlags("", kubeConfigFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
kubeConfig, err = rest.InClusterConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
kubeConfig.QPS = DefaultQPS
|
||||
kubeConfig.Burst = DefaultBurst
|
||||
|
||||
return kubeConfig, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *ServerRunOptions) GetEtcdEndPoints() []string {
|
||||
endpoints := strings.Split(s.etcdEndpoints, ",")
|
||||
for k, v := range endpoints {
|
||||
endpoints[k] = strings.TrimSpace(v)
|
||||
}
|
||||
return endpoints
|
||||
}
|
||||
|
||||
func (s *ServerRunOptions) GetEtcdCertFile() string {
|
||||
return s.etcdCertFile
|
||||
}
|
||||
|
||||
func (s *ServerRunOptions) GetEtcdKeyFile() string {
|
||||
return s.etcdKeyFile
|
||||
}
|
||||
|
||||
func (s *ServerRunOptions) GetEtcdCaFile() string {
|
||||
return s.etcdCaFile
|
||||
}
|
||||
|
||||
func (s *ServerRunOptions) GetKubectlImage() string {
|
||||
return s.kubectlImage
|
||||
}
|
||||
|
||||
var ServerOptions = NewServerRunOptions()
|
||||
|
||||
func AddFlags(fs *pflag.FlagSet) {
|
||||
|
||||
Reference in New Issue
Block a user