2015-12-25 00:08:15 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2015-12-25 00:08:15 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Package options contains flags and options for initializing an apiserver
|
|
|
|
package options
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"k8s.io/kubernetes/pkg/api/validation"
|
2016-05-06 15:15:36 +00:00
|
|
|
genericoptions "k8s.io/kubernetes/pkg/genericapiserver/options"
|
2015-12-25 00:08:15 +00:00
|
|
|
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
|
|
|
|
"k8s.io/kubernetes/pkg/master/ports"
|
|
|
|
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
// APIServer runs a kubernetes api server.
|
|
|
|
type APIServer struct {
|
2016-05-06 15:15:36 +00:00
|
|
|
*genericoptions.ServerRunOptions
|
2016-04-28 01:08:33 +00:00
|
|
|
AllowPrivileged bool
|
|
|
|
EventTTL time.Duration
|
|
|
|
KubeletConfig kubeletclient.KubeletClientConfig
|
|
|
|
MaxConnectionBytesPerSec int64
|
|
|
|
SSHKeyfile string
|
|
|
|
SSHUser string
|
|
|
|
ServiceAccountKeyFile string
|
|
|
|
ServiceAccountLookup bool
|
|
|
|
WebhookTokenAuthnConfigFile string
|
2016-05-14 23:35:11 +00:00
|
|
|
WebhookTokenAuthnCacheTTL time.Duration
|
2015-12-25 00:08:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewAPIServer creates a new APIServer object with default parameters
|
|
|
|
func NewAPIServer() *APIServer {
|
|
|
|
s := APIServer{
|
2016-08-09 11:35:53 +00:00
|
|
|
ServerRunOptions: genericoptions.NewServerRunOptions().WithEtcdOptions(),
|
2016-05-11 01:53:43 +00:00
|
|
|
EventTTL: 1 * time.Hour,
|
2015-12-25 00:08:15 +00:00
|
|
|
KubeletConfig: kubeletclient.KubeletClientConfig{
|
|
|
|
Port: ports.KubeletPort,
|
|
|
|
EnableHttps: true,
|
|
|
|
HTTPTimeout: time.Duration(5) * time.Second,
|
|
|
|
},
|
2016-05-14 23:35:11 +00:00
|
|
|
WebhookTokenAuthnCacheTTL: 2 * time.Minute,
|
2015-12-25 00:08:15 +00:00
|
|
|
}
|
|
|
|
return &s
|
|
|
|
}
|
|
|
|
|
|
|
|
// AddFlags adds flags for a specific APIServer to the specified FlagSet
|
|
|
|
func (s *APIServer) AddFlags(fs *pflag.FlagSet) {
|
2016-04-06 22:24:48 +00:00
|
|
|
// Add the generic flags.
|
2016-08-09 11:35:53 +00:00
|
|
|
s.ServerRunOptions.AddUniversalFlags(fs)
|
|
|
|
//Add etcd specific flags.
|
|
|
|
s.ServerRunOptions.AddEtcdStorageFlags(fs)
|
2015-12-25 00:08:15 +00:00
|
|
|
// Note: the weird ""+ in below lines seems to be the only way to get gofmt to
|
|
|
|
// arrange these text blocks sensibly. Grrr.
|
2016-06-16 00:33:02 +00:00
|
|
|
|
|
|
|
fs.DurationVar(&s.EventTTL, "event-ttl", s.EventTTL,
|
|
|
|
"Amount of time to retain events. Default is 1h.")
|
|
|
|
|
|
|
|
fs.StringVar(&s.ServiceAccountKeyFile, "service-account-key-file", s.ServiceAccountKeyFile, ""+
|
2016-09-27 05:44:33 +00:00
|
|
|
"File containing PEM-encoded x509 RSA or ECDSA private or public key, used to verify "+
|
2016-06-16 00:33:02 +00:00
|
|
|
"ServiceAccount tokens. If unspecified, --tls-private-key-file is used.")
|
|
|
|
|
|
|
|
fs.BoolVar(&s.ServiceAccountLookup, "service-account-lookup", s.ServiceAccountLookup,
|
|
|
|
"If true, validate ServiceAccount tokens exist in etcd as part of authentication.")
|
|
|
|
|
|
|
|
fs.StringVar(&s.WebhookTokenAuthnConfigFile, "authentication-token-webhook-config-file", s.WebhookTokenAuthnConfigFile, ""+
|
|
|
|
"File with webhook configuration for token authentication in kubeconfig format. "+
|
|
|
|
"The API server will query the remote service to determine authentication for bearer tokens.")
|
|
|
|
|
|
|
|
fs.DurationVar(&s.WebhookTokenAuthnCacheTTL, "authentication-token-webhook-cache-ttl", s.WebhookTokenAuthnCacheTTL,
|
|
|
|
"The duration to cache responses from the webhook token authenticator. Default is 2m.")
|
|
|
|
|
|
|
|
fs.BoolVar(&s.AllowPrivileged, "allow-privileged", s.AllowPrivileged,
|
|
|
|
"If true, allow privileged containers.")
|
|
|
|
|
|
|
|
fs.StringVar(&s.SSHUser, "ssh-user", s.SSHUser,
|
|
|
|
"If non-empty, use secure SSH proxy to the nodes, using this user name")
|
|
|
|
|
|
|
|
fs.StringVar(&s.SSHKeyfile, "ssh-keyfile", s.SSHKeyfile,
|
|
|
|
"If non-empty, use secure SSH proxy to the nodes, using this user keyfile")
|
|
|
|
|
|
|
|
fs.Int64Var(&s.MaxConnectionBytesPerSec, "max-connection-bytes-per-sec", s.MaxConnectionBytesPerSec, ""+
|
|
|
|
"If non-zero, throttle each user connection to this number of bytes/sec. "+
|
|
|
|
"Currently only applies to long-running requests.")
|
|
|
|
|
2015-12-25 00:08:15 +00:00
|
|
|
// Kubelet related flags:
|
2016-06-16 00:33:02 +00:00
|
|
|
fs.BoolVar(&s.KubeletConfig.EnableHttps, "kubelet-https", s.KubeletConfig.EnableHttps,
|
|
|
|
"Use https for kubelet connections.")
|
|
|
|
|
|
|
|
fs.UintVar(&s.KubeletConfig.Port, "kubelet-port", s.KubeletConfig.Port,
|
|
|
|
"DEPRECATED: kubelet port.")
|
|
|
|
fs.MarkDeprecated("kubelet-port", "kubelet-port is deprecated and will be removed.")
|
|
|
|
|
|
|
|
fs.DurationVar(&s.KubeletConfig.HTTPTimeout, "kubelet-timeout", s.KubeletConfig.HTTPTimeout,
|
|
|
|
"Timeout for kubelet operations.")
|
|
|
|
|
|
|
|
fs.StringVar(&s.KubeletConfig.CertFile, "kubelet-client-certificate", s.KubeletConfig.CertFile,
|
|
|
|
"Path to a client cert file for TLS.")
|
|
|
|
|
|
|
|
fs.StringVar(&s.KubeletConfig.KeyFile, "kubelet-client-key", s.KubeletConfig.KeyFile,
|
|
|
|
"Path to a client key file for TLS.")
|
|
|
|
|
|
|
|
fs.StringVar(&s.KubeletConfig.CAFile, "kubelet-certificate-authority", s.KubeletConfig.CAFile,
|
|
|
|
"Path to a cert file for the certificate authority.")
|
|
|
|
|
2015-12-25 00:08:15 +00:00
|
|
|
// TODO: delete this flag as soon as we identify and fix all clients that send malformed updates, like #14126.
|
2016-06-16 00:33:02 +00:00
|
|
|
fs.BoolVar(&validation.RepairMalformedUpdates, "repair-malformed-updates", validation.RepairMalformedUpdates, ""+
|
|
|
|
"If true, server will do its best to fix the update request to pass the validation, "+
|
|
|
|
"e.g., setting empty UID in update request to its existing value. This flag can be turned off "+
|
|
|
|
"after we fix all the clients that send malformed updates.")
|
2015-12-25 00:08:15 +00:00
|
|
|
}
|