mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Make master+federation ServerRunOptions embeddings explicit
This commit is contained in:
parent
b798527793
commit
ab3ce27f01
@ -30,7 +30,7 @@ import (
|
|||||||
|
|
||||||
// ServerRunOptions runs a kubernetes api server.
|
// ServerRunOptions runs a kubernetes api server.
|
||||||
type ServerRunOptions struct {
|
type ServerRunOptions struct {
|
||||||
*genericoptions.ServerRunOptions
|
GenericServerRunOptions *genericoptions.ServerRunOptions
|
||||||
AllowPrivileged bool
|
AllowPrivileged bool
|
||||||
EventTTL time.Duration
|
EventTTL time.Duration
|
||||||
KubeletConfig kubeletclient.KubeletClientConfig
|
KubeletConfig kubeletclient.KubeletClientConfig
|
||||||
@ -46,7 +46,7 @@ type ServerRunOptions struct {
|
|||||||
// NewServerRunOptions creates a new ServerRunOptions object with default parameters
|
// NewServerRunOptions creates a new ServerRunOptions object with default parameters
|
||||||
func NewServerRunOptions() *ServerRunOptions {
|
func NewServerRunOptions() *ServerRunOptions {
|
||||||
s := ServerRunOptions{
|
s := ServerRunOptions{
|
||||||
ServerRunOptions: genericoptions.NewServerRunOptions().WithEtcdOptions(),
|
GenericServerRunOptions: genericoptions.NewServerRunOptions().WithEtcdOptions(),
|
||||||
EventTTL: 1 * time.Hour,
|
EventTTL: 1 * time.Hour,
|
||||||
KubeletConfig: kubeletclient.KubeletClientConfig{
|
KubeletConfig: kubeletclient.KubeletClientConfig{
|
||||||
Port: ports.KubeletPort,
|
Port: ports.KubeletPort,
|
||||||
@ -61,9 +61,9 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||||||
// AddFlags adds flags for a specific APIServer to the specified FlagSet
|
// AddFlags adds flags for a specific APIServer to the specified FlagSet
|
||||||
func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
|
func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
|
||||||
// Add the generic flags.
|
// Add the generic flags.
|
||||||
s.ServerRunOptions.AddUniversalFlags(fs)
|
s.GenericServerRunOptions.AddUniversalFlags(fs)
|
||||||
//Add etcd specific flags.
|
//Add etcd specific flags.
|
||||||
s.ServerRunOptions.AddEtcdStorageFlags(fs)
|
s.GenericServerRunOptions.AddEtcdStorageFlags(fs)
|
||||||
// Note: the weird ""+ in below lines seems to be the only way to get gofmt to
|
// Note: the weird ""+ in below lines seems to be the only way to get gofmt to
|
||||||
// arrange these text blocks sensibly. Grrr.
|
// arrange these text blocks sensibly. Grrr.
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ func TestAddFlagsFlag(t *testing.T) {
|
|||||||
f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
|
f := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
|
||||||
s := NewServerRunOptions()
|
s := NewServerRunOptions()
|
||||||
s.AddFlags(f)
|
s.AddFlags(f)
|
||||||
if s.EnableSwaggerUI {
|
if s.GenericServerRunOptions.EnableSwaggerUI {
|
||||||
t.Errorf("Expected s.EnableSwaggerUI to be false by default")
|
t.Errorf("Expected s.EnableSwaggerUI to be false by default")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ func TestAddFlagsFlag(t *testing.T) {
|
|||||||
"--enable-swagger-ui=true",
|
"--enable-swagger-ui=true",
|
||||||
}
|
}
|
||||||
f.Parse(args)
|
f.Parse(args)
|
||||||
if !s.EnableSwaggerUI {
|
if !s.GenericServerRunOptions.EnableSwaggerUI {
|
||||||
t.Errorf("Expected s.EnableSwaggerUI to be true")
|
t.Errorf("Expected s.EnableSwaggerUI to be true")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,10 +80,10 @@ cluster's shared state through which all other components interact.`,
|
|||||||
|
|
||||||
// Run runs the specified APIServer. This should never exit.
|
// Run runs the specified APIServer. This should never exit.
|
||||||
func Run(s *options.ServerRunOptions) error {
|
func Run(s *options.ServerRunOptions) error {
|
||||||
genericvalidation.VerifyEtcdServersList(s.ServerRunOptions)
|
genericvalidation.VerifyEtcdServersList(s.GenericServerRunOptions)
|
||||||
genericapiserver.DefaultAndValidateRunOptions(s.ServerRunOptions)
|
genericapiserver.DefaultAndValidateRunOptions(s.GenericServerRunOptions)
|
||||||
genericConfig := genericapiserver.NewConfig(). // create the new config
|
genericConfig := genericapiserver.NewConfig(). // create the new config
|
||||||
ApplyOptions(s.ServerRunOptions). // apply the options selected
|
ApplyOptions(s.GenericServerRunOptions). // apply the options selected
|
||||||
Complete() // set default values based on the known values
|
Complete() // set default values based on the known values
|
||||||
|
|
||||||
if err := genericConfig.MaybeGenerateServingCerts(); err != nil {
|
if err := genericConfig.MaybeGenerateServingCerts(); err != nil {
|
||||||
@ -107,7 +107,7 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
if len(s.SSHUser) > 0 {
|
if len(s.SSHUser) > 0 {
|
||||||
// Get ssh key distribution func, if supported
|
// Get ssh key distribution func, if supported
|
||||||
var installSSH genericapiserver.InstallSSHKey
|
var installSSH genericapiserver.InstallSSHKey
|
||||||
cloud, err := cloudprovider.InitCloudProvider(s.CloudProvider, s.CloudConfigFile)
|
cloud, err := cloudprovider.InitCloudProvider(s.GenericServerRunOptions.CloudProvider, s.GenericServerRunOptions.CloudConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Cloud provider could not be initialized: %v", err)
|
glog.Fatalf("Cloud provider could not be initialized: %v", err)
|
||||||
}
|
}
|
||||||
@ -138,10 +138,10 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
// Proxying to pods and services is IP-based... don't expect to be able to verify the hostname
|
// Proxying to pods and services is IP-based... don't expect to be able to verify the hostname
|
||||||
proxyTLSClientConfig := &tls.Config{InsecureSkipVerify: true}
|
proxyTLSClientConfig := &tls.Config{InsecureSkipVerify: true}
|
||||||
|
|
||||||
if s.StorageConfig.DeserializationCacheSize == 0 {
|
if s.GenericServerRunOptions.StorageConfig.DeserializationCacheSize == 0 {
|
||||||
// When size of cache is not explicitly set, estimate its size based on
|
// When size of cache is not explicitly set, estimate its size based on
|
||||||
// target memory usage.
|
// target memory usage.
|
||||||
glog.V(2).Infof("Initalizing deserialization cache size based on %dMB limit", s.TargetRAMMB)
|
glog.V(2).Infof("Initalizing deserialization cache size based on %dMB limit", s.GenericServerRunOptions.TargetRAMMB)
|
||||||
|
|
||||||
// This is the heuristics that from memory capacity is trying to infer
|
// This is the heuristics that from memory capacity is trying to infer
|
||||||
// the maximum number of nodes in the cluster and set cache sizes based
|
// the maximum number of nodes in the cluster and set cache sizes based
|
||||||
@ -153,29 +153,29 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
// be used for the deserialization cache and divide it by the max object
|
// be used for the deserialization cache and divide it by the max object
|
||||||
// size to compute its size. We may even go further and measure
|
// size to compute its size. We may even go further and measure
|
||||||
// collective sizes of the objects in the cache.
|
// collective sizes of the objects in the cache.
|
||||||
clusterSize := s.TargetRAMMB / 60
|
clusterSize := s.GenericServerRunOptions.TargetRAMMB / 60
|
||||||
s.StorageConfig.DeserializationCacheSize = 25 * clusterSize
|
s.GenericServerRunOptions.StorageConfig.DeserializationCacheSize = 25 * clusterSize
|
||||||
if s.StorageConfig.DeserializationCacheSize < 1000 {
|
if s.GenericServerRunOptions.StorageConfig.DeserializationCacheSize < 1000 {
|
||||||
s.StorageConfig.DeserializationCacheSize = 1000
|
s.GenericServerRunOptions.StorageConfig.DeserializationCacheSize = 1000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
storageGroupsToEncodingVersion, err := s.StorageGroupsToEncodingVersion()
|
storageGroupsToEncodingVersion, err := s.GenericServerRunOptions.StorageGroupsToEncodingVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("error generating storage version map: %s", err)
|
glog.Fatalf("error generating storage version map: %s", err)
|
||||||
}
|
}
|
||||||
storageFactory, err := genericapiserver.BuildDefaultStorageFactory(
|
storageFactory, err := genericapiserver.BuildDefaultStorageFactory(
|
||||||
s.StorageConfig, s.DefaultStorageMediaType, api.Codecs,
|
s.GenericServerRunOptions.StorageConfig, s.GenericServerRunOptions.DefaultStorageMediaType, api.Codecs,
|
||||||
genericapiserver.NewDefaultResourceEncodingConfig(), storageGroupsToEncodingVersion,
|
genericapiserver.NewDefaultResourceEncodingConfig(), storageGroupsToEncodingVersion,
|
||||||
// FIXME: this GroupVersionResource override should be configurable
|
// FIXME: this GroupVersionResource override should be configurable
|
||||||
[]unversioned.GroupVersionResource{batch.Resource("scheduledjobs").WithVersion("v2alpha1")},
|
[]unversioned.GroupVersionResource{batch.Resource("scheduledjobs").WithVersion("v2alpha1")},
|
||||||
master.DefaultAPIResourceConfigSource(), s.RuntimeConfig)
|
master.DefaultAPIResourceConfigSource(), s.GenericServerRunOptions.RuntimeConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("error in initializing storage factory: %s", err)
|
glog.Fatalf("error in initializing storage factory: %s", err)
|
||||||
}
|
}
|
||||||
storageFactory.AddCohabitatingResources(batch.Resource("jobs"), extensions.Resource("jobs"))
|
storageFactory.AddCohabitatingResources(batch.Resource("jobs"), extensions.Resource("jobs"))
|
||||||
storageFactory.AddCohabitatingResources(autoscaling.Resource("horizontalpodautoscalers"), extensions.Resource("horizontalpodautoscalers"))
|
storageFactory.AddCohabitatingResources(autoscaling.Resource("horizontalpodautoscalers"), extensions.Resource("horizontalpodautoscalers"))
|
||||||
for _, override := range s.EtcdServersOverrides {
|
for _, override := range s.GenericServerRunOptions.EtcdServersOverrides {
|
||||||
tokens := strings.Split(override, "#")
|
tokens := strings.Split(override, "#")
|
||||||
if len(tokens) != 2 {
|
if len(tokens) != 2 {
|
||||||
glog.Errorf("invalid value of etcd server overrides: %s", override)
|
glog.Errorf("invalid value of etcd server overrides: %s", override)
|
||||||
@ -196,9 +196,9 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Default to the private server key for service account token signing
|
// Default to the private server key for service account token signing
|
||||||
if len(s.ServiceAccountKeyFiles) == 0 && s.TLSPrivateKeyFile != "" {
|
if len(s.ServiceAccountKeyFiles) == 0 && s.GenericServerRunOptions.TLSPrivateKeyFile != "" {
|
||||||
if authenticator.IsValidServiceAccountKeyFile(s.TLSPrivateKeyFile) {
|
if authenticator.IsValidServiceAccountKeyFile(s.GenericServerRunOptions.TLSPrivateKeyFile) {
|
||||||
s.ServiceAccountKeyFiles = []string{s.TLSPrivateKeyFile}
|
s.ServiceAccountKeyFiles = []string{s.GenericServerRunOptions.TLSPrivateKeyFile}
|
||||||
} else {
|
} else {
|
||||||
glog.Warning("No TLS key provided, service account token authentication disabled")
|
glog.Warning("No TLS key provided, service account token authentication disabled")
|
||||||
}
|
}
|
||||||
@ -216,23 +216,23 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
apiAuthenticator, securityDefinitions, err := authenticator.New(authenticator.AuthenticatorConfig{
|
apiAuthenticator, securityDefinitions, err := authenticator.New(authenticator.AuthenticatorConfig{
|
||||||
Anonymous: s.AnonymousAuth,
|
Anonymous: s.GenericServerRunOptions.AnonymousAuth,
|
||||||
AnyToken: s.EnableAnyToken,
|
AnyToken: s.GenericServerRunOptions.EnableAnyToken,
|
||||||
BasicAuthFile: s.BasicAuthFile,
|
BasicAuthFile: s.GenericServerRunOptions.BasicAuthFile,
|
||||||
ClientCAFile: s.ClientCAFile,
|
ClientCAFile: s.GenericServerRunOptions.ClientCAFile,
|
||||||
TokenAuthFile: s.TokenAuthFile,
|
TokenAuthFile: s.GenericServerRunOptions.TokenAuthFile,
|
||||||
OIDCIssuerURL: s.OIDCIssuerURL,
|
OIDCIssuerURL: s.GenericServerRunOptions.OIDCIssuerURL,
|
||||||
OIDCClientID: s.OIDCClientID,
|
OIDCClientID: s.GenericServerRunOptions.OIDCClientID,
|
||||||
OIDCCAFile: s.OIDCCAFile,
|
OIDCCAFile: s.GenericServerRunOptions.OIDCCAFile,
|
||||||
OIDCUsernameClaim: s.OIDCUsernameClaim,
|
OIDCUsernameClaim: s.GenericServerRunOptions.OIDCUsernameClaim,
|
||||||
OIDCGroupsClaim: s.OIDCGroupsClaim,
|
OIDCGroupsClaim: s.GenericServerRunOptions.OIDCGroupsClaim,
|
||||||
ServiceAccountKeyFiles: s.ServiceAccountKeyFiles,
|
ServiceAccountKeyFiles: s.ServiceAccountKeyFiles,
|
||||||
ServiceAccountLookup: s.ServiceAccountLookup,
|
ServiceAccountLookup: s.ServiceAccountLookup,
|
||||||
ServiceAccountTokenGetter: serviceAccountGetter,
|
ServiceAccountTokenGetter: serviceAccountGetter,
|
||||||
KeystoneURL: s.KeystoneURL,
|
KeystoneURL: s.GenericServerRunOptions.KeystoneURL,
|
||||||
WebhookTokenAuthnConfigFile: s.WebhookTokenAuthnConfigFile,
|
WebhookTokenAuthnConfigFile: s.WebhookTokenAuthnConfigFile,
|
||||||
WebhookTokenAuthnCacheTTL: s.WebhookTokenAuthnCacheTTL,
|
WebhookTokenAuthnCacheTTL: s.WebhookTokenAuthnCacheTTL,
|
||||||
RequestHeaderConfig: s.AuthenticationRequestHeaderConfig(),
|
RequestHeaderConfig: s.GenericServerRunOptions.AuthenticationRequestHeaderConfig(),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -240,31 +240,31 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
privilegedLoopbackToken := uuid.NewRandom().String()
|
privilegedLoopbackToken := uuid.NewRandom().String()
|
||||||
selfClientConfig, err := s.NewSelfClientConfig(privilegedLoopbackToken)
|
selfClientConfig, err := s.GenericServerRunOptions.NewSelfClientConfig(privilegedLoopbackToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed to create clientset: %v", err)
|
glog.Fatalf("Failed to create clientset: %v", err)
|
||||||
}
|
}
|
||||||
client, err := s.NewSelfClient(privilegedLoopbackToken)
|
client, err := s.GenericServerRunOptions.NewSelfClient(privilegedLoopbackToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to create clientset: %v", err)
|
glog.Errorf("Failed to create clientset: %v", err)
|
||||||
}
|
}
|
||||||
sharedInformers := informers.NewSharedInformerFactory(client, 10*time.Minute)
|
sharedInformers := informers.NewSharedInformerFactory(client, 10*time.Minute)
|
||||||
|
|
||||||
authorizationConfig := authorizer.AuthorizationConfig{
|
authorizationConfig := authorizer.AuthorizationConfig{
|
||||||
PolicyFile: s.AuthorizationPolicyFile,
|
PolicyFile: s.GenericServerRunOptions.AuthorizationPolicyFile,
|
||||||
WebhookConfigFile: s.AuthorizationWebhookConfigFile,
|
WebhookConfigFile: s.GenericServerRunOptions.AuthorizationWebhookConfigFile,
|
||||||
WebhookCacheAuthorizedTTL: s.AuthorizationWebhookCacheAuthorizedTTL,
|
WebhookCacheAuthorizedTTL: s.GenericServerRunOptions.AuthorizationWebhookCacheAuthorizedTTL,
|
||||||
WebhookCacheUnauthorizedTTL: s.AuthorizationWebhookCacheUnauthorizedTTL,
|
WebhookCacheUnauthorizedTTL: s.GenericServerRunOptions.AuthorizationWebhookCacheUnauthorizedTTL,
|
||||||
RBACSuperUser: s.AuthorizationRBACSuperUser,
|
RBACSuperUser: s.GenericServerRunOptions.AuthorizationRBACSuperUser,
|
||||||
InformerFactory: sharedInformers,
|
InformerFactory: sharedInformers,
|
||||||
}
|
}
|
||||||
authorizationModeNames := strings.Split(s.AuthorizationMode, ",")
|
authorizationModeNames := strings.Split(s.GenericServerRunOptions.AuthorizationMode, ",")
|
||||||
apiAuthorizer, err := authorizer.NewAuthorizerFromAuthorizationConfig(authorizationModeNames, authorizationConfig)
|
apiAuthorizer, err := authorizer.NewAuthorizerFromAuthorizationConfig(authorizationModeNames, authorizationConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Invalid Authorization Config: %v", err)
|
glog.Fatalf("Invalid Authorization Config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
admissionControlPluginNames := strings.Split(s.AdmissionControl, ",")
|
admissionControlPluginNames := strings.Split(s.GenericServerRunOptions.AdmissionControl, ",")
|
||||||
|
|
||||||
// TODO(dims): We probably need to add an option "EnableLoopbackToken"
|
// TODO(dims): We probably need to add an option "EnableLoopbackToken"
|
||||||
if apiAuthenticator != nil {
|
if apiAuthenticator != nil {
|
||||||
@ -285,7 +285,7 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
|
|
||||||
pluginInitializer := admission.NewPluginInitializer(sharedInformers, apiAuthorizer)
|
pluginInitializer := admission.NewPluginInitializer(sharedInformers, apiAuthorizer)
|
||||||
|
|
||||||
admissionController, err := admission.NewFromPlugins(client, admissionControlPluginNames, s.AdmissionControlConfigFile, pluginInitializer)
|
admissionController, err := admission.NewFromPlugins(client, admissionControlPluginNames, s.GenericServerRunOptions.AdmissionControlConfigFile, pluginInitializer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed to initialize plugins: %v", err)
|
glog.Fatalf("Failed to initialize plugins: %v", err)
|
||||||
}
|
}
|
||||||
@ -311,9 +311,9 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
GenericConfig: genericConfig.Config,
|
GenericConfig: genericConfig.Config,
|
||||||
|
|
||||||
StorageFactory: storageFactory,
|
StorageFactory: storageFactory,
|
||||||
EnableWatchCache: s.EnableWatchCache,
|
EnableWatchCache: s.GenericServerRunOptions.EnableWatchCache,
|
||||||
EnableCoreControllers: true,
|
EnableCoreControllers: true,
|
||||||
DeleteCollectionWorkers: s.DeleteCollectionWorkers,
|
DeleteCollectionWorkers: s.GenericServerRunOptions.DeleteCollectionWorkers,
|
||||||
EventTTL: s.EventTTL,
|
EventTTL: s.EventTTL,
|
||||||
KubeletClientConfig: s.KubeletConfig,
|
KubeletClientConfig: s.KubeletConfig,
|
||||||
EnableUISupport: true,
|
EnableUISupport: true,
|
||||||
@ -323,10 +323,10 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
Tunneler: tunneler,
|
Tunneler: tunneler,
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.EnableWatchCache {
|
if s.GenericServerRunOptions.EnableWatchCache {
|
||||||
glog.V(2).Infof("Initalizing cache sizes based on %dMB limit", s.TargetRAMMB)
|
glog.V(2).Infof("Initalizing cache sizes based on %dMB limit", s.GenericServerRunOptions.TargetRAMMB)
|
||||||
cachesize.InitializeWatchCacheSizes(s.TargetRAMMB)
|
cachesize.InitializeWatchCacheSizes(s.GenericServerRunOptions.TargetRAMMB)
|
||||||
cachesize.SetWatchCacheSizes(s.WatchCacheSizes)
|
cachesize.SetWatchCacheSizes(s.GenericServerRunOptions.WatchCacheSizes)
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := config.Complete().New()
|
m, err := config.Complete().New()
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestLongRunningRequestRegexp(t *testing.T) {
|
func TestLongRunningRequestRegexp(t *testing.T) {
|
||||||
regexp := regexp.MustCompile(options.NewServerRunOptions().LongRunningRequestRE)
|
regexp := regexp.MustCompile(options.NewServerRunOptions().GenericServerRunOptions.LongRunningRequestRE)
|
||||||
dontMatch := []string{
|
dontMatch := []string{
|
||||||
"/api/v1/watch-namespace/",
|
"/api/v1/watch-namespace/",
|
||||||
"/api/v1/namespace-proxy/",
|
"/api/v1/namespace-proxy/",
|
||||||
|
@ -27,14 +27,14 @@ import (
|
|||||||
|
|
||||||
// Runtime options for the federation-apiserver.
|
// Runtime options for the federation-apiserver.
|
||||||
type ServerRunOptions struct {
|
type ServerRunOptions struct {
|
||||||
*genericoptions.ServerRunOptions
|
GenericServerRunOptions *genericoptions.ServerRunOptions
|
||||||
EventTTL time.Duration
|
EventTTL time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServerRunOptions creates a new ServerRunOptions object with default values.
|
// NewServerRunOptions creates a new ServerRunOptions object with default values.
|
||||||
func NewServerRunOptions() *ServerRunOptions {
|
func NewServerRunOptions() *ServerRunOptions {
|
||||||
s := ServerRunOptions{
|
s := ServerRunOptions{
|
||||||
ServerRunOptions: genericoptions.NewServerRunOptions().WithEtcdOptions(),
|
GenericServerRunOptions: genericoptions.NewServerRunOptions().WithEtcdOptions(),
|
||||||
EventTTL: 1 * time.Hour,
|
EventTTL: 1 * time.Hour,
|
||||||
}
|
}
|
||||||
return &s
|
return &s
|
||||||
@ -43,9 +43,9 @@ func NewServerRunOptions() *ServerRunOptions {
|
|||||||
// AddFlags adds flags for ServerRunOptions fields to be specified via FlagSet.
|
// AddFlags adds flags for ServerRunOptions fields to be specified via FlagSet.
|
||||||
func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
|
func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
|
||||||
// Add the generic flags.
|
// Add the generic flags.
|
||||||
s.ServerRunOptions.AddUniversalFlags(fs)
|
s.GenericServerRunOptions.AddUniversalFlags(fs)
|
||||||
//Add etcd specific flags.
|
//Add etcd specific flags.
|
||||||
s.ServerRunOptions.AddEtcdStorageFlags(fs)
|
s.GenericServerRunOptions.AddEtcdStorageFlags(fs)
|
||||||
|
|
||||||
fs.DurationVar(&s.EventTTL, "event-ttl", s.EventTTL,
|
fs.DurationVar(&s.EventTTL, "event-ttl", s.EventTTL,
|
||||||
"Amount of time to retain events. Default is 1h.")
|
"Amount of time to retain events. Default is 1h.")
|
||||||
|
@ -67,10 +67,10 @@ cluster's shared state through which all other components interact.`,
|
|||||||
|
|
||||||
// Run runs the specified APIServer. This should never exit.
|
// Run runs the specified APIServer. This should never exit.
|
||||||
func Run(s *options.ServerRunOptions) error {
|
func Run(s *options.ServerRunOptions) error {
|
||||||
genericvalidation.VerifyEtcdServersList(s.ServerRunOptions)
|
genericvalidation.VerifyEtcdServersList(s.GenericServerRunOptions)
|
||||||
genericapiserver.DefaultAndValidateRunOptions(s.ServerRunOptions)
|
genericapiserver.DefaultAndValidateRunOptions(s.GenericServerRunOptions)
|
||||||
genericConfig := genericapiserver.NewConfig(). // create the new config
|
genericConfig := genericapiserver.NewConfig(). // create the new config
|
||||||
ApplyOptions(s.ServerRunOptions). // apply the options selected
|
ApplyOptions(s.GenericServerRunOptions). // apply the options selected
|
||||||
Complete() // set default values based on the known values
|
Complete() // set default values based on the known values
|
||||||
|
|
||||||
if err := genericConfig.MaybeGenerateServingCerts(); err != nil {
|
if err := genericConfig.MaybeGenerateServingCerts(); err != nil {
|
||||||
@ -80,23 +80,23 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
// TODO: register cluster federation resources here.
|
// TODO: register cluster federation resources here.
|
||||||
resourceConfig := genericapiserver.NewResourceConfig()
|
resourceConfig := genericapiserver.NewResourceConfig()
|
||||||
|
|
||||||
if s.StorageConfig.DeserializationCacheSize == 0 {
|
if s.GenericServerRunOptions.StorageConfig.DeserializationCacheSize == 0 {
|
||||||
// When size of cache is not explicitly set, set it to 50000
|
// When size of cache is not explicitly set, set it to 50000
|
||||||
s.StorageConfig.DeserializationCacheSize = 50000
|
s.GenericServerRunOptions.StorageConfig.DeserializationCacheSize = 50000
|
||||||
}
|
}
|
||||||
storageGroupsToEncodingVersion, err := s.StorageGroupsToEncodingVersion()
|
storageGroupsToEncodingVersion, err := s.GenericServerRunOptions.StorageGroupsToEncodingVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("error generating storage version map: %s", err)
|
glog.Fatalf("error generating storage version map: %s", err)
|
||||||
}
|
}
|
||||||
storageFactory, err := genericapiserver.BuildDefaultStorageFactory(
|
storageFactory, err := genericapiserver.BuildDefaultStorageFactory(
|
||||||
s.StorageConfig, s.DefaultStorageMediaType, api.Codecs,
|
s.GenericServerRunOptions.StorageConfig, s.GenericServerRunOptions.DefaultStorageMediaType, api.Codecs,
|
||||||
genericapiserver.NewDefaultResourceEncodingConfig(), storageGroupsToEncodingVersion,
|
genericapiserver.NewDefaultResourceEncodingConfig(), storageGroupsToEncodingVersion,
|
||||||
[]unversioned.GroupVersionResource{}, resourceConfig, s.RuntimeConfig)
|
[]unversioned.GroupVersionResource{}, resourceConfig, s.GenericServerRunOptions.RuntimeConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("error in initializing storage factory: %s", err)
|
glog.Fatalf("error in initializing storage factory: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, override := range s.EtcdServersOverrides {
|
for _, override := range s.GenericServerRunOptions.EtcdServersOverrides {
|
||||||
tokens := strings.Split(override, "#")
|
tokens := strings.Split(override, "#")
|
||||||
if len(tokens) != 2 {
|
if len(tokens) != 2 {
|
||||||
glog.Errorf("invalid value of etcd server overrides: %s", override)
|
glog.Errorf("invalid value of etcd server overrides: %s", override)
|
||||||
@ -117,49 +117,49 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
apiAuthenticator, securityDefinitions, err := authenticator.New(authenticator.AuthenticatorConfig{
|
apiAuthenticator, securityDefinitions, err := authenticator.New(authenticator.AuthenticatorConfig{
|
||||||
Anonymous: s.AnonymousAuth,
|
Anonymous: s.GenericServerRunOptions.AnonymousAuth,
|
||||||
AnyToken: s.EnableAnyToken,
|
AnyToken: s.GenericServerRunOptions.EnableAnyToken,
|
||||||
BasicAuthFile: s.BasicAuthFile,
|
BasicAuthFile: s.GenericServerRunOptions.BasicAuthFile,
|
||||||
ClientCAFile: s.ClientCAFile,
|
ClientCAFile: s.GenericServerRunOptions.ClientCAFile,
|
||||||
TokenAuthFile: s.TokenAuthFile,
|
TokenAuthFile: s.GenericServerRunOptions.TokenAuthFile,
|
||||||
OIDCIssuerURL: s.OIDCIssuerURL,
|
OIDCIssuerURL: s.GenericServerRunOptions.OIDCIssuerURL,
|
||||||
OIDCClientID: s.OIDCClientID,
|
OIDCClientID: s.GenericServerRunOptions.OIDCClientID,
|
||||||
OIDCCAFile: s.OIDCCAFile,
|
OIDCCAFile: s.GenericServerRunOptions.OIDCCAFile,
|
||||||
OIDCUsernameClaim: s.OIDCUsernameClaim,
|
OIDCUsernameClaim: s.GenericServerRunOptions.OIDCUsernameClaim,
|
||||||
OIDCGroupsClaim: s.OIDCGroupsClaim,
|
OIDCGroupsClaim: s.GenericServerRunOptions.OIDCGroupsClaim,
|
||||||
KeystoneURL: s.KeystoneURL,
|
KeystoneURL: s.GenericServerRunOptions.KeystoneURL,
|
||||||
RequestHeaderConfig: s.AuthenticationRequestHeaderConfig(),
|
RequestHeaderConfig: s.GenericServerRunOptions.AuthenticationRequestHeaderConfig(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Invalid Authentication Config: %v", err)
|
glog.Fatalf("Invalid Authentication Config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
privilegedLoopbackToken := uuid.NewRandom().String()
|
privilegedLoopbackToken := uuid.NewRandom().String()
|
||||||
selfClientConfig, err := s.NewSelfClientConfig(privilegedLoopbackToken)
|
selfClientConfig, err := s.GenericServerRunOptions.NewSelfClientConfig(privilegedLoopbackToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed to create clientset: %v", err)
|
glog.Fatalf("Failed to create clientset: %v", err)
|
||||||
}
|
}
|
||||||
client, err := s.NewSelfClient(privilegedLoopbackToken)
|
client, err := s.GenericServerRunOptions.NewSelfClient(privilegedLoopbackToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to create clientset: %v", err)
|
glog.Errorf("Failed to create clientset: %v", err)
|
||||||
}
|
}
|
||||||
sharedInformers := informers.NewSharedInformerFactory(client, 10*time.Minute)
|
sharedInformers := informers.NewSharedInformerFactory(client, 10*time.Minute)
|
||||||
|
|
||||||
authorizationConfig := authorizer.AuthorizationConfig{
|
authorizationConfig := authorizer.AuthorizationConfig{
|
||||||
PolicyFile: s.AuthorizationPolicyFile,
|
PolicyFile: s.GenericServerRunOptions.AuthorizationPolicyFile,
|
||||||
WebhookConfigFile: s.AuthorizationWebhookConfigFile,
|
WebhookConfigFile: s.GenericServerRunOptions.AuthorizationWebhookConfigFile,
|
||||||
WebhookCacheAuthorizedTTL: s.AuthorizationWebhookCacheAuthorizedTTL,
|
WebhookCacheAuthorizedTTL: s.GenericServerRunOptions.AuthorizationWebhookCacheAuthorizedTTL,
|
||||||
WebhookCacheUnauthorizedTTL: s.AuthorizationWebhookCacheUnauthorizedTTL,
|
WebhookCacheUnauthorizedTTL: s.GenericServerRunOptions.AuthorizationWebhookCacheUnauthorizedTTL,
|
||||||
RBACSuperUser: s.AuthorizationRBACSuperUser,
|
RBACSuperUser: s.GenericServerRunOptions.AuthorizationRBACSuperUser,
|
||||||
InformerFactory: sharedInformers,
|
InformerFactory: sharedInformers,
|
||||||
}
|
}
|
||||||
authorizationModeNames := strings.Split(s.AuthorizationMode, ",")
|
authorizationModeNames := strings.Split(s.GenericServerRunOptions.AuthorizationMode, ",")
|
||||||
apiAuthorizer, err := authorizer.NewAuthorizerFromAuthorizationConfig(authorizationModeNames, authorizationConfig)
|
apiAuthorizer, err := authorizer.NewAuthorizerFromAuthorizationConfig(authorizationModeNames, authorizationConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Invalid Authorization Config: %v", err)
|
glog.Fatalf("Invalid Authorization Config: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
admissionControlPluginNames := strings.Split(s.AdmissionControl, ",")
|
admissionControlPluginNames := strings.Split(s.GenericServerRunOptions.AdmissionControl, ",")
|
||||||
|
|
||||||
// TODO(dims): We probably need to add an option "EnableLoopbackToken"
|
// TODO(dims): We probably need to add an option "EnableLoopbackToken"
|
||||||
if apiAuthenticator != nil {
|
if apiAuthenticator != nil {
|
||||||
@ -180,7 +180,7 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
|
|
||||||
pluginInitializer := admission.NewPluginInitializer(sharedInformers, apiAuthorizer)
|
pluginInitializer := admission.NewPluginInitializer(sharedInformers, apiAuthorizer)
|
||||||
|
|
||||||
admissionController, err := admission.NewFromPlugins(client, admissionControlPluginNames, s.AdmissionControlConfigFile, pluginInitializer)
|
admissionController, err := admission.NewFromPlugins(client, admissionControlPluginNames, s.GenericServerRunOptions.AdmissionControlConfigFile, pluginInitializer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed to initialize plugins: %v", err)
|
glog.Fatalf("Failed to initialize plugins: %v", err)
|
||||||
}
|
}
|
||||||
@ -197,9 +197,9 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
genericConfig.OpenAPIConfig.SecurityDefinitions = securityDefinitions
|
genericConfig.OpenAPIConfig.SecurityDefinitions = securityDefinitions
|
||||||
|
|
||||||
// TODO: Move this to generic api server (Need to move the command line flag).
|
// TODO: Move this to generic api server (Need to move the command line flag).
|
||||||
if s.EnableWatchCache {
|
if s.GenericServerRunOptions.EnableWatchCache {
|
||||||
cachesize.InitializeWatchCacheSizes(s.TargetRAMMB)
|
cachesize.InitializeWatchCacheSizes(s.GenericServerRunOptions.TargetRAMMB)
|
||||||
cachesize.SetWatchCacheSizes(s.WatchCacheSizes)
|
cachesize.SetWatchCacheSizes(s.GenericServerRunOptions.WatchCacheSizes)
|
||||||
}
|
}
|
||||||
|
|
||||||
m, err := genericConfig.New()
|
m, err := genericConfig.New()
|
||||||
@ -212,9 +212,9 @@ func Run(s *options.ServerRunOptions) error {
|
|||||||
|
|
||||||
restOptionsFactory := restOptionsFactory{
|
restOptionsFactory := restOptionsFactory{
|
||||||
storageFactory: storageFactory,
|
storageFactory: storageFactory,
|
||||||
deleteCollectionWorkers: s.DeleteCollectionWorkers,
|
deleteCollectionWorkers: s.GenericServerRunOptions.DeleteCollectionWorkers,
|
||||||
}
|
}
|
||||||
if s.EnableWatchCache {
|
if s.GenericServerRunOptions.EnableWatchCache {
|
||||||
restOptionsFactory.storageDecorator = registry.StorageWithCacher
|
restOptionsFactory.storageDecorator = registry.StorageWithCacher
|
||||||
} else {
|
} else {
|
||||||
restOptionsFactory.storageDecorator = generic.UndecoratedStorage
|
restOptionsFactory.storageDecorator = generic.UndecoratedStorage
|
||||||
|
@ -41,12 +41,12 @@ func NewAPIServer() *APIServer {
|
|||||||
// Start starts the apiserver, returns when apiserver is ready.
|
// Start starts the apiserver, returns when apiserver is ready.
|
||||||
func (a *APIServer) Start() error {
|
func (a *APIServer) Start() error {
|
||||||
config := options.NewServerRunOptions()
|
config := options.NewServerRunOptions()
|
||||||
config.StorageConfig.ServerList = []string{getEtcdClientURL()}
|
config.GenericServerRunOptions.StorageConfig.ServerList = []string{getEtcdClientURL()}
|
||||||
_, ipnet, err := net.ParseCIDR(clusterIPRange)
|
_, ipnet, err := net.ParseCIDR(clusterIPRange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
config.ServiceClusterIPRange = *ipnet
|
config.GenericServerRunOptions.ServiceClusterIPRange = *ipnet
|
||||||
config.AllowPrivileged = true
|
config.AllowPrivileged = true
|
||||||
errCh := make(chan error)
|
errCh := make(chan error)
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -37,7 +37,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestLongRunningRequestRegexp(t *testing.T) {
|
func TestLongRunningRequestRegexp(t *testing.T) {
|
||||||
regexp := regexp.MustCompile(options.NewServerRunOptions().LongRunningRequestRE)
|
regexp := regexp.MustCompile(options.NewServerRunOptions().GenericServerRunOptions.LongRunningRequestRE)
|
||||||
dontMatch := []string{
|
dontMatch := []string{
|
||||||
"/api/v1/watch-namespace/",
|
"/api/v1/watch-namespace/",
|
||||||
"/api/v1/namespace-proxy/",
|
"/api/v1/namespace-proxy/",
|
||||||
@ -86,10 +86,10 @@ var groupVersions = []unversioned.GroupVersion{
|
|||||||
|
|
||||||
func TestRun(t *testing.T) {
|
func TestRun(t *testing.T) {
|
||||||
s := options.NewServerRunOptions()
|
s := options.NewServerRunOptions()
|
||||||
s.InsecurePort = insecurePort
|
s.GenericServerRunOptions.InsecurePort = insecurePort
|
||||||
_, ipNet, _ := net.ParseCIDR("10.10.10.0/24")
|
_, ipNet, _ := net.ParseCIDR("10.10.10.0/24")
|
||||||
s.ServiceClusterIPRange = *ipNet
|
s.GenericServerRunOptions.ServiceClusterIPRange = *ipNet
|
||||||
s.StorageConfig.ServerList = []string{"http://localhost:2379"}
|
s.GenericServerRunOptions.StorageConfig.ServerList = []string{"http://localhost:2379"}
|
||||||
go func() {
|
go func() {
|
||||||
if err := app.Run(s); err != nil {
|
if err := app.Run(s); err != nil {
|
||||||
t.Fatalf("Error in bringing up the server: %v", err)
|
t.Fatalf("Error in bringing up the server: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user