2015-01-30 17:04:39 +00:00
|
|
|
/*
|
2015-05-01 16:19:44 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors All rights reserved.
|
2015-01-30 17:04:39 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-02-07 22:13:22 +00:00
|
|
|
// Package app does all of the work necessary to create a Kubernetes
|
2015-01-30 17:04:39 +00:00
|
|
|
// APIServer by binding together the API, master and APIServer infrastructure.
|
|
|
|
// It can be configured and called directly or via the hyperkube framework.
|
2015-02-07 22:13:22 +00:00
|
|
|
package app
|
2015-01-30 17:04:39 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
2015-09-15 03:55:18 +00:00
|
|
|
"fmt"
|
2015-01-30 17:04:39 +00:00
|
|
|
"net"
|
2015-12-05 02:01:29 +00:00
|
|
|
"net/url"
|
2015-01-30 17:04:39 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2015-12-25 00:08:15 +00:00
|
|
|
"github.com/golang/glog"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
|
|
|
|
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/admission"
|
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-11-13 21:20:54 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
2016-03-22 16:45:23 +00:00
|
|
|
apiv1 "k8s.io/kubernetes/pkg/api/v1"
|
2016-04-15 22:30:15 +00:00
|
|
|
appsapi "k8s.io/kubernetes/pkg/apis/apps/v1alpha1"
|
2016-02-15 14:00:40 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
2016-03-22 16:45:23 +00:00
|
|
|
autoscalingapiv1 "k8s.io/kubernetes/pkg/apis/autoscaling/v1"
|
2016-02-17 17:11:31 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/batch"
|
2016-03-22 16:45:23 +00:00
|
|
|
batchapiv1 "k8s.io/kubernetes/pkg/apis/batch/v1"
|
2015-12-08 14:21:04 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
2016-03-22 16:45:23 +00:00
|
|
|
extensionsapiv1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apiserver"
|
2015-12-24 21:05:04 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apiserver/authenticator"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/capabilities"
|
2016-02-05 21:58:03 +00:00
|
|
|
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
2016-02-12 18:58:43 +00:00
|
|
|
"k8s.io/kubernetes/pkg/client/restclient"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/cloudprovider"
|
2015-12-24 21:54:40 +00:00
|
|
|
serviceaccountcontroller "k8s.io/kubernetes/pkg/controller/serviceaccount"
|
2015-11-16 21:46:00 +00:00
|
|
|
"k8s.io/kubernetes/pkg/genericapiserver"
|
2015-10-27 13:18:45 +00:00
|
|
|
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/master"
|
2016-02-05 07:47:27 +00:00
|
|
|
"k8s.io/kubernetes/pkg/registry/cachesize"
|
2015-12-21 05:27:49 +00:00
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
2015-12-24 21:54:40 +00:00
|
|
|
"k8s.io/kubernetes/pkg/serviceaccount"
|
2015-05-12 02:41:13 +00:00
|
|
|
)
|
|
|
|
|
2015-10-12 14:33:39 +00:00
|
|
|
// NewAPIServerCommand creates a *cobra.Command object with default parameters
|
|
|
|
func NewAPIServerCommand() *cobra.Command {
|
2015-12-25 00:08:15 +00:00
|
|
|
s := options.NewAPIServer()
|
2015-10-12 14:33:39 +00:00
|
|
|
s.AddFlags(pflag.CommandLine)
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "kube-apiserver",
|
|
|
|
Long: `The Kubernetes API server validates and configures data
|
|
|
|
for the api objects which include pods, services, replicationcontrollers, and
|
|
|
|
others. The API Server services REST operations and provides the frontend to the
|
|
|
|
cluster's shared state through which all other components interact.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2015-01-30 17:04:39 +00:00
|
|
|
// Run runs the specified APIServer. This should never exit.
|
2015-12-25 00:08:15 +00:00
|
|
|
func Run(s *options.APIServer) error {
|
2016-04-15 01:01:31 +00:00
|
|
|
genericapiserver.DefaultAndValidateRunOptions(s.ServerRunOptions)
|
2015-05-22 06:12:57 +00:00
|
|
|
|
2015-01-30 17:04:39 +00:00
|
|
|
capabilities.Initialize(capabilities.Capabilities{
|
|
|
|
AllowPrivileged: s.AllowPrivileged,
|
2015-03-24 23:09:16 +00:00
|
|
|
// TODO(vmarmol): Implement support for HostNetworkSources.
|
2015-08-24 17:41:51 +00:00
|
|
|
PrivilegedSources: capabilities.PrivilegedSources{
|
|
|
|
HostNetworkSources: []string{},
|
2015-09-15 16:43:59 +00:00
|
|
|
HostPIDSources: []string{},
|
2015-08-10 08:14:01 +00:00
|
|
|
HostIPCSources: []string{},
|
2015-08-24 17:41:51 +00:00
|
|
|
},
|
2015-07-29 05:00:15 +00:00
|
|
|
PerConnectionBandwidthLimitBytesPerSec: s.MaxConnectionBytesPerSec,
|
2015-01-30 17:04:39 +00:00
|
|
|
})
|
|
|
|
|
2015-10-09 05:18:16 +00:00
|
|
|
// Setup tunneler if needed
|
2016-04-22 00:48:35 +00:00
|
|
|
var tunneler genericapiserver.Tunneler
|
2015-10-09 05:18:16 +00:00
|
|
|
var proxyDialerFn apiserver.ProxyDialerFunc
|
|
|
|
if len(s.SSHUser) > 0 {
|
|
|
|
// Get ssh key distribution func, if supported
|
2016-04-22 00:48:35 +00:00
|
|
|
var installSSH genericapiserver.InstallSSHKey
|
2016-04-27 21:25:59 +00:00
|
|
|
cloud, err := cloudprovider.InitCloudProvider(s.CloudProvider, s.CloudConfigFile)
|
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Cloud provider could not be initialized: %v", err)
|
|
|
|
}
|
2015-10-09 05:18:16 +00:00
|
|
|
if cloud != nil {
|
|
|
|
if instances, supported := cloud.Instances(); supported {
|
|
|
|
installSSH = instances.AddSSHKeyToAllInstances
|
|
|
|
}
|
|
|
|
}
|
2015-12-05 02:01:29 +00:00
|
|
|
if s.KubeletConfig.Port == 0 {
|
|
|
|
glog.Fatalf("Must enable kubelet port if proxy ssh-tunneling is specified.")
|
|
|
|
}
|
2015-10-09 05:18:16 +00:00
|
|
|
// Set up the tunneler
|
2015-12-05 02:01:29 +00:00
|
|
|
// TODO(cjcullen): If we want this to handle per-kubelet ports or other
|
|
|
|
// kubelet listen-addresses, we need to plumb through options.
|
|
|
|
healthCheckPath := &url.URL{
|
|
|
|
Scheme: "https",
|
|
|
|
Host: net.JoinHostPort("127.0.0.1", strconv.FormatUint(uint64(s.KubeletConfig.Port), 10)),
|
|
|
|
Path: "healthz",
|
|
|
|
}
|
2016-04-22 00:48:35 +00:00
|
|
|
tunneler = genericapiserver.NewSSHTunneler(s.SSHUser, s.SSHKeyfile, healthCheckPath, installSSH)
|
2015-10-09 05:18:16 +00:00
|
|
|
|
|
|
|
// Use the tunneler's dialer to connect to the kubelet
|
|
|
|
s.KubeletConfig.Dial = tunneler.Dial
|
|
|
|
// Use the tunneler's dialer when proxying to pods, services, and nodes
|
|
|
|
proxyDialerFn = tunneler.Dial
|
|
|
|
}
|
|
|
|
|
|
|
|
// Proxying to pods and services is IP-based... don't expect to be able to verify the hostname
|
|
|
|
proxyTLSClientConfig := &tls.Config{InsecureSkipVerify: true}
|
|
|
|
|
2015-10-27 13:18:45 +00:00
|
|
|
kubeletClient, err := kubeletclient.NewStaticKubeletClient(&s.KubeletConfig)
|
2015-01-30 17:04:39 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Failure to start kubelet client: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-03-22 16:45:23 +00:00
|
|
|
apiResourceConfigSource, err := parseRuntimeConfig(s)
|
2015-10-13 00:40:37 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("error in parsing runtime-config: %s", err)
|
2015-05-11 23:09:25 +00:00
|
|
|
}
|
2015-07-29 23:15:24 +00:00
|
|
|
|
2016-02-12 18:58:43 +00:00
|
|
|
clientConfig := &restclient.Config{
|
2015-11-13 21:20:54 +00:00
|
|
|
Host: net.JoinHostPort(s.InsecureBindAddress.String(), strconv.Itoa(s.InsecurePort)),
|
2016-03-03 09:45:43 +00:00
|
|
|
// Increase QPS limits. The client is currently passed to all admission plugins,
|
|
|
|
// and those can be throttled in case of higher load on apiserver - see #22340 and #22422
|
|
|
|
// for more details. Once #22422 is fixed, we may want to remove it.
|
|
|
|
QPS: 50,
|
|
|
|
Burst: 100,
|
2015-01-30 17:04:39 +00:00
|
|
|
}
|
2015-11-13 21:20:54 +00:00
|
|
|
if len(s.DeprecatedStorageVersion) != 0 {
|
|
|
|
gv, err := unversioned.ParseGroupVersion(s.DeprecatedStorageVersion)
|
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("error in parsing group version: %s", err)
|
|
|
|
}
|
|
|
|
clientConfig.GroupVersion = &gv
|
|
|
|
}
|
|
|
|
|
2016-02-01 22:30:47 +00:00
|
|
|
client, err := clientset.NewForConfig(clientConfig)
|
2015-01-30 17:04:39 +00:00
|
|
|
if err != nil {
|
2016-02-01 22:30:47 +00:00
|
|
|
glog.Errorf("Failed to create clientset: %v", err)
|
2015-01-30 17:04:39 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 14:17:04 +00:00
|
|
|
resourceEncoding := genericapiserver.NewDefaultResourceEncodingConfig()
|
|
|
|
groupToEncoding, err := s.StorageGroupsToEncodingVersion()
|
2015-09-15 03:55:18 +00:00
|
|
|
if err != nil {
|
2016-03-16 14:17:04 +00:00
|
|
|
glog.Fatalf("error getting group encoding: %s", err)
|
2015-09-15 03:55:18 +00:00
|
|
|
}
|
2016-03-16 14:17:04 +00:00
|
|
|
for group, storageEncodingVersion := range groupToEncoding {
|
|
|
|
resourceEncoding.SetVersionEncoding(group, storageEncodingVersion, unversioned.GroupVersion{Group: group, Version: runtime.APIVersionInternal})
|
2015-01-30 17:04:39 +00:00
|
|
|
}
|
2015-09-11 22:46:18 +00:00
|
|
|
|
2016-04-23 19:00:28 +00:00
|
|
|
storageFactory := genericapiserver.NewDefaultStorageFactory(s.StorageConfig, s.DefaultStorageMediaType, api.Codecs, resourceEncoding, apiResourceConfigSource)
|
|
|
|
// third party resources are always serialized to storage using JSON
|
|
|
|
storageFactory.SetSerializer(extensions.Resource("thirdpartyresources"), "application/json", nil)
|
2016-03-16 14:17:04 +00:00
|
|
|
storageFactory.AddCohabitatingResources(batch.Resource("jobs"), extensions.Resource("jobs"))
|
|
|
|
storageFactory.AddCohabitatingResources(autoscaling.Resource("horizontalpodautoscalers"), extensions.Resource("horizontalpodautoscalers"))
|
|
|
|
for _, override := range s.EtcdServersOverrides {
|
|
|
|
tokens := strings.Split(override, "#")
|
|
|
|
if len(tokens) != 2 {
|
|
|
|
glog.Errorf("invalid value of etcd server overrides: %s", override)
|
|
|
|
continue
|
2016-02-17 17:11:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-16 14:17:04 +00:00
|
|
|
apiresource := strings.Split(tokens[0], "/")
|
|
|
|
if len(apiresource) != 2 {
|
|
|
|
glog.Errorf("invalid resource definition: %s", tokens[0])
|
|
|
|
continue
|
2016-04-15 22:30:15 +00:00
|
|
|
}
|
2016-03-16 14:17:04 +00:00
|
|
|
group := apiresource[0]
|
|
|
|
resource := apiresource[1]
|
|
|
|
groupResource := unversioned.GroupResource{Group: group, Resource: resource}
|
2016-04-15 22:30:15 +00:00
|
|
|
|
2016-03-16 14:17:04 +00:00
|
|
|
servers := strings.Split(tokens[1], ";")
|
|
|
|
storageFactory.SetEtcdLocation(groupResource, servers)
|
2016-04-15 22:30:15 +00:00
|
|
|
}
|
|
|
|
|
2015-05-01 16:02:38 +00:00
|
|
|
// Default to the private server key for service account token signing
|
|
|
|
if s.ServiceAccountKeyFile == "" && s.TLSPrivateKeyFile != "" {
|
2015-12-24 21:05:04 +00:00
|
|
|
if authenticator.IsValidServiceAccountKeyFile(s.TLSPrivateKeyFile) {
|
2015-06-17 03:02:54 +00:00
|
|
|
s.ServiceAccountKeyFile = s.TLSPrivateKeyFile
|
|
|
|
} else {
|
2015-10-01 12:00:46 +00:00
|
|
|
glog.Warning("No RSA key provided, service account token authentication disabled")
|
2015-06-17 03:02:54 +00:00
|
|
|
}
|
2015-05-01 16:02:38 +00:00
|
|
|
}
|
2015-12-24 21:54:40 +00:00
|
|
|
|
|
|
|
var serviceAccountGetter serviceaccount.ServiceAccountTokenGetter
|
|
|
|
if s.ServiceAccountLookup {
|
|
|
|
// If we need to look up service accounts and tokens,
|
|
|
|
// go directly to etcd to avoid recursive auth insanity
|
2016-03-16 14:17:04 +00:00
|
|
|
storage, err := storageFactory.New(api.Resource("serviceaccounts"))
|
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Unable to get serviceaccounts storage: %v", err)
|
|
|
|
}
|
|
|
|
serviceAccountGetter = serviceaccountcontroller.NewGetterFromStorageInterface(storage)
|
2015-12-24 21:54:40 +00:00
|
|
|
}
|
|
|
|
|
2015-12-24 21:05:04 +00:00
|
|
|
authenticator, err := authenticator.New(authenticator.AuthenticatorConfig{
|
2015-12-24 21:54:40 +00:00
|
|
|
BasicAuthFile: s.BasicAuthFile,
|
|
|
|
ClientCAFile: s.ClientCAFile,
|
|
|
|
TokenAuthFile: s.TokenAuthFile,
|
|
|
|
OIDCIssuerURL: s.OIDCIssuerURL,
|
|
|
|
OIDCClientID: s.OIDCClientID,
|
|
|
|
OIDCCAFile: s.OIDCCAFile,
|
|
|
|
OIDCUsernameClaim: s.OIDCUsernameClaim,
|
2016-02-10 21:44:05 +00:00
|
|
|
OIDCGroupsClaim: s.OIDCGroupsClaim,
|
2015-12-24 21:54:40 +00:00
|
|
|
ServiceAccountKeyFile: s.ServiceAccountKeyFile,
|
|
|
|
ServiceAccountLookup: s.ServiceAccountLookup,
|
|
|
|
ServiceAccountTokenGetter: serviceAccountGetter,
|
|
|
|
KeystoneURL: s.KeystoneURL,
|
2015-08-19 00:36:22 +00:00
|
|
|
})
|
|
|
|
|
2015-01-30 17:04:39 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Invalid Authentication Config: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-08-27 23:18:26 +00:00
|
|
|
authorizationModeNames := strings.Split(s.AuthorizationMode, ",")
|
2016-02-18 17:26:36 +00:00
|
|
|
authorizer, err := apiserver.NewAuthorizerFromAuthorizationConfig(authorizationModeNames, s.AuthorizationConfig)
|
2015-01-30 17:04:39 +00:00
|
|
|
if err != nil {
|
|
|
|
glog.Fatalf("Invalid Authorization Config: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
admissionControlPluginNames := strings.Split(s.AdmissionControl, ",")
|
|
|
|
admissionController := admission.NewFromPlugins(client, admissionControlPluginNames, s.AdmissionControlConfigFile)
|
|
|
|
|
2016-04-15 01:01:31 +00:00
|
|
|
genericConfig := genericapiserver.NewConfig(s.ServerRunOptions)
|
|
|
|
// TODO: Move the following to generic api server as well.
|
2016-03-16 14:17:04 +00:00
|
|
|
genericConfig.StorageFactory = storageFactory
|
2016-04-15 01:01:31 +00:00
|
|
|
genericConfig.Authenticator = authenticator
|
|
|
|
genericConfig.SupportsBasicAuth = len(s.BasicAuthFile) > 0
|
|
|
|
genericConfig.Authorizer = authorizer
|
|
|
|
genericConfig.AdmissionControl = admissionController
|
|
|
|
genericConfig.APIResourceConfigSource = apiResourceConfigSource
|
|
|
|
genericConfig.MasterServiceNamespace = s.MasterServiceNamespace
|
|
|
|
genericConfig.ProxyDialer = proxyDialerFn
|
|
|
|
genericConfig.ProxyTLSClientConfig = proxyTLSClientConfig
|
|
|
|
genericConfig.Serializer = api.Codecs
|
|
|
|
|
2015-01-30 17:04:39 +00:00
|
|
|
config := &master.Config{
|
2016-04-15 01:01:31 +00:00
|
|
|
Config: genericConfig,
|
2016-02-18 13:50:43 +00:00
|
|
|
EnableCoreControllers: true,
|
|
|
|
DeleteCollectionWorkers: s.DeleteCollectionWorkers,
|
|
|
|
EventTTL: s.EventTTL,
|
|
|
|
KubeletClient: kubeletClient,
|
2015-11-16 21:46:00 +00:00
|
|
|
|
|
|
|
Tunneler: tunneler,
|
2015-01-30 17:04:39 +00:00
|
|
|
}
|
2016-02-05 07:47:27 +00:00
|
|
|
|
|
|
|
if s.EnableWatchCache {
|
|
|
|
cachesize.SetWatchCacheSizes(s.WatchCacheSizes)
|
|
|
|
}
|
|
|
|
|
2016-02-03 22:26:11 +00:00
|
|
|
m, err := master.New(config)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-05 07:47:27 +00:00
|
|
|
|
2016-01-09 02:30:33 +00:00
|
|
|
m.Run(s.ServerRunOptions)
|
2015-01-30 17:04:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-05-05 23:53:22 +00:00
|
|
|
|
2015-12-25 00:08:15 +00:00
|
|
|
func getRuntimeConfigValue(s *options.APIServer, apiKey string, defaultValue bool) bool {
|
2015-05-05 23:53:22 +00:00
|
|
|
flagValue, ok := s.RuntimeConfig[apiKey]
|
|
|
|
if ok {
|
|
|
|
if flagValue == "" {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
boolValue, err := strconv.ParseBool(flagValue)
|
|
|
|
if err != nil {
|
2015-09-29 09:09:25 +00:00
|
|
|
glog.Fatalf("Invalid value of %s: %s, err: %v", apiKey, flagValue, err)
|
2015-05-05 23:53:22 +00:00
|
|
|
}
|
|
|
|
return boolValue
|
|
|
|
}
|
|
|
|
return defaultValue
|
|
|
|
}
|
2015-10-13 00:40:37 +00:00
|
|
|
|
2016-03-22 16:45:23 +00:00
|
|
|
// Parses the given runtime-config and formats it into genericapiserver.APIResourceConfigSource
|
|
|
|
func parseRuntimeConfig(s *options.APIServer) (genericapiserver.APIResourceConfigSource, error) {
|
|
|
|
v1GroupVersionString := "api/v1"
|
|
|
|
extensionsGroupVersionString := extensionsapiv1beta1.SchemeGroupVersion.String()
|
|
|
|
versionToResourceSpecifier := map[unversioned.GroupVersion]string{
|
|
|
|
apiv1.SchemeGroupVersion: v1GroupVersionString,
|
|
|
|
extensionsapiv1beta1.SchemeGroupVersion: extensionsGroupVersionString,
|
|
|
|
batchapiv1.SchemeGroupVersion: batchapiv1.SchemeGroupVersion.String(),
|
|
|
|
autoscalingapiv1.SchemeGroupVersion: autoscalingapiv1.SchemeGroupVersion.String(),
|
2016-04-15 22:30:15 +00:00
|
|
|
appsapi.SchemeGroupVersion: appsapi.SchemeGroupVersion.String(),
|
2016-03-22 16:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resourceConfig := master.DefaultAPIResourceConfigSource()
|
|
|
|
|
2015-10-13 00:40:37 +00:00
|
|
|
// "api/all=false" allows users to selectively enable specific api versions.
|
2016-03-22 16:45:23 +00:00
|
|
|
enableAPIByDefault := true
|
2015-10-13 00:40:37 +00:00
|
|
|
allAPIFlagValue, ok := s.RuntimeConfig["api/all"]
|
|
|
|
if ok && allAPIFlagValue == "false" {
|
2016-03-22 16:45:23 +00:00
|
|
|
enableAPIByDefault = false
|
2015-10-13 00:40:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// "api/legacy=false" allows users to disable legacy api versions.
|
|
|
|
disableLegacyAPIs := false
|
|
|
|
legacyAPIFlagValue, ok := s.RuntimeConfig["api/legacy"]
|
|
|
|
if ok && legacyAPIFlagValue == "false" {
|
|
|
|
disableLegacyAPIs = true
|
|
|
|
}
|
|
|
|
_ = disableLegacyAPIs // hush the compiler while we don't have legacy APIs to disable.
|
|
|
|
|
2016-03-22 16:45:23 +00:00
|
|
|
// "<resourceSpecifier>={true|false} allows users to enable/disable API.
|
2015-10-13 00:40:37 +00:00
|
|
|
// This takes preference over api/all and api/legacy, if specified.
|
2016-03-22 16:45:23 +00:00
|
|
|
for version, resourceSpecifier := range versionToResourceSpecifier {
|
|
|
|
enableVersion := getRuntimeConfigValue(s, resourceSpecifier, enableAPIByDefault)
|
|
|
|
if enableVersion {
|
|
|
|
resourceConfig.EnableVersions(version)
|
|
|
|
} else {
|
|
|
|
resourceConfig.DisableVersions(version)
|
2015-10-13 00:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-22 16:45:23 +00:00
|
|
|
for key := range s.RuntimeConfig {
|
|
|
|
tokens := strings.Split(key, "/")
|
|
|
|
if len(tokens) != 3 {
|
|
|
|
continue
|
2015-10-13 00:40:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 16:45:23 +00:00
|
|
|
switch {
|
|
|
|
case strings.HasPrefix(key, extensionsGroupVersionString+"/"):
|
|
|
|
if !resourceConfig.AnyResourcesForVersionEnabled(extensionsapiv1beta1.SchemeGroupVersion) {
|
|
|
|
return nil, fmt.Errorf("%v is disabled, you cannot configure its resources individually", extensionsapiv1beta1.SchemeGroupVersion)
|
|
|
|
}
|
2016-02-15 14:00:40 +00:00
|
|
|
|
2016-03-22 16:45:23 +00:00
|
|
|
resource := strings.TrimPrefix(key, extensionsGroupVersionString+"/")
|
|
|
|
if getRuntimeConfigValue(s, key, false) {
|
|
|
|
resourceConfig.EnableResources(extensionsapiv1beta1.SchemeGroupVersion.WithResource(resource))
|
|
|
|
} else {
|
|
|
|
resourceConfig.DisableResources(extensionsapiv1beta1.SchemeGroupVersion.WithResource(resource))
|
2015-10-13 00:40:37 +00:00
|
|
|
}
|
2016-03-22 16:45:23 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// TODO enable individual resource capability for all GroupVersionResources
|
|
|
|
return nil, fmt.Errorf("%v resources cannot be enabled/disabled individually", key)
|
2015-10-13 00:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-22 16:45:23 +00:00
|
|
|
return resourceConfig, nil
|
2015-10-13 00:40:37 +00:00
|
|
|
}
|