mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Add (stopgap) support for an experimental API prefix.
This commit is contained in:
@@ -32,10 +32,13 @@ import (
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
|
||||
explatest "github.com/GoogleCloudPlatform/kubernetes/pkg/expapi/latest"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/master/ports"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/storage"
|
||||
@@ -71,7 +74,9 @@ type APIServer struct {
|
||||
TLSPrivateKeyFile string
|
||||
CertDirectory string
|
||||
APIPrefix string
|
||||
ExpAPIPrefix string
|
||||
StorageVersion string
|
||||
ExpStorageVersion string
|
||||
CloudProvider string
|
||||
CloudConfigFile string
|
||||
EventTTL time.Duration
|
||||
@@ -115,6 +120,7 @@ func NewAPIServer() *APIServer {
|
||||
APIRate: 10.0,
|
||||
APIBurst: 200,
|
||||
APIPrefix: "/api",
|
||||
ExpAPIPrefix: "/experimental",
|
||||
EventTTL: 1 * time.Hour,
|
||||
AuthorizationMode: "AlwaysAllow",
|
||||
AdmissionControl: "AlwaysAdmit",
|
||||
@@ -172,6 +178,7 @@ func (s *APIServer) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&s.CertDirectory, "cert-dir", s.CertDirectory, "The directory where the TLS certs are located (by default /var/run/kubernetes). "+
|
||||
"If --tls-cert-file and --tls-private-key-file are provided, this flag will be ignored.")
|
||||
fs.StringVar(&s.APIPrefix, "api-prefix", s.APIPrefix, "The prefix for API requests on the server. Default '/api'.")
|
||||
fs.StringVar(&s.ExpAPIPrefix, "experimental-prefix", s.ExpAPIPrefix, "The prefix for experimental API requests on the server. Default '/experimental'.")
|
||||
fs.StringVar(&s.StorageVersion, "storage-version", s.StorageVersion, "The version to store resources with. Defaults to server preferred")
|
||||
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. Empty string for no provider.")
|
||||
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
|
||||
@@ -217,7 +224,7 @@ func (s *APIServer) verifyClusterIPFlags() {
|
||||
}
|
||||
}
|
||||
|
||||
func newEtcd(etcdConfigFile string, etcdServerList util.StringList, storageVersion string, pathPrefix string) (etcdStorage storage.Interface, err error) {
|
||||
func newEtcd(etcdConfigFile string, etcdServerList util.StringList, interfacesFunc meta.VersionInterfacesFunc, defaultVersion, storageVersion, pathPrefix string) (etcdStorage storage.Interface, err error) {
|
||||
var client tools.EtcdClient
|
||||
if etcdConfigFile != "" {
|
||||
client, err = etcd.NewClientFromFile(etcdConfigFile)
|
||||
@@ -237,7 +244,10 @@ func newEtcd(etcdConfigFile string, etcdServerList util.StringList, storageVersi
|
||||
client = etcdClient
|
||||
}
|
||||
|
||||
return master.NewEtcdStorage(client, storageVersion, pathPrefix)
|
||||
if storageVersion == "" {
|
||||
storageVersion = defaultVersion
|
||||
}
|
||||
return master.NewEtcdStorage(client, interfacesFunc, storageVersion, pathPrefix)
|
||||
}
|
||||
|
||||
// Run runs the specified APIServer. This should never exit.
|
||||
@@ -292,6 +302,10 @@ func (s *APIServer) Run(_ []string) error {
|
||||
disableV1 := disableAllAPIs
|
||||
disableV1 = !s.getRuntimeConfigValue("api/v1", !disableV1)
|
||||
|
||||
// "experimental/v1={true|false} allows users to enable/disable the experimental API.
|
||||
// This takes preference over api/all, if specified.
|
||||
enableExp := s.getRuntimeConfigValue("experimental/v1", false)
|
||||
|
||||
// TODO: expose same flags as client.BindClientConfigFlags but for a server
|
||||
clientConfig := &client.Config{
|
||||
Host: net.JoinHostPort(s.InsecureBindAddress.String(), strconv.Itoa(s.InsecurePort)),
|
||||
@@ -302,10 +316,14 @@ func (s *APIServer) Run(_ []string) error {
|
||||
glog.Fatalf("Invalid server address: %v", err)
|
||||
}
|
||||
|
||||
etcdStorage, err := newEtcd(s.EtcdConfigFile, s.EtcdServerList, s.StorageVersion, s.EtcdPathPrefix)
|
||||
etcdStorage, err := newEtcd(s.EtcdConfigFile, s.EtcdServerList, latest.InterfacesFor, latest.Version, s.StorageVersion, s.EtcdPathPrefix)
|
||||
if err != nil {
|
||||
glog.Fatalf("Invalid storage version or misconfigured etcd: %v", err)
|
||||
}
|
||||
expEtcdStorage, err := newEtcd(s.EtcdConfigFile, s.EtcdServerList, explatest.InterfacesFor, explatest.Version, s.ExpStorageVersion, s.EtcdPathPrefix)
|
||||
if err != nil {
|
||||
glog.Fatalf("Invalid experimental storage version or misconfigured etcd: %v", err)
|
||||
}
|
||||
|
||||
n := net.IPNet(s.ServiceClusterIPRange)
|
||||
|
||||
@@ -360,7 +378,9 @@ func (s *APIServer) Run(_ []string) error {
|
||||
}
|
||||
}
|
||||
config := &master.Config{
|
||||
DatabaseStorage: etcdStorage,
|
||||
DatabaseStorage: etcdStorage,
|
||||
ExpDatabaseStorage: expEtcdStorage,
|
||||
|
||||
EventTTL: s.EventTTL,
|
||||
KubeletClient: kubeletClient,
|
||||
ServiceClusterIPRange: &n,
|
||||
@@ -371,6 +391,7 @@ func (s *APIServer) Run(_ []string) error {
|
||||
EnableProfiling: s.EnableProfiling,
|
||||
EnableIndex: true,
|
||||
APIPrefix: s.APIPrefix,
|
||||
ExpAPIPrefix: s.ExpAPIPrefix,
|
||||
CorsAllowedOriginList: s.CorsAllowedOriginList,
|
||||
ReadWritePort: s.SecurePort,
|
||||
PublicAddress: net.IP(s.AdvertiseAddress),
|
||||
@@ -379,6 +400,7 @@ func (s *APIServer) Run(_ []string) error {
|
||||
Authorizer: authorizer,
|
||||
AdmissionControl: admissionController,
|
||||
DisableV1: disableV1,
|
||||
EnableExp: enableExp,
|
||||
MasterServiceNamespace: s.MasterServiceNamespace,
|
||||
ClusterName: s.ClusterName,
|
||||
ExternalHost: s.ExternalHost,
|
||||
|
||||
Reference in New Issue
Block a user