Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
fbd5032d
Commit
fbd5032d
authored
Oct 11, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split genericapiserver configuration apart so that you can run without flag options
parent
f15c12c3
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
129 additions
and
130 deletions
+129
-130
server.go
cmd/kube-apiserver/app/server.go
+8
-3
apiserver.go
examples/apiserver/apiserver.go
+7
-2
server.go
federation/cmd/federation-apiserver/app/server.go
+8
-3
config.go
pkg/genericapiserver/config.go
+90
-69
genericapiserver.go
pkg/genericapiserver/genericapiserver.go
+0
-17
genericapiserver_test.go
pkg/genericapiserver/genericapiserver_test.go
+5
-7
server_run_options.go
pkg/genericapiserver/options/server_run_options.go
+2
-2
master_test.go
pkg/master/master_test.go
+1
-8
master_utils.go
test/integration/framework/master_utils.go
+8
-19
No files found.
cmd/kube-apiserver/app/server.go
View file @
fbd5032d
...
@@ -92,6 +92,13 @@ cluster's shared state through which all other components interact.`,
...
@@ -92,6 +92,13 @@ cluster's shared state through which all other components interact.`,
func
Run
(
s
*
options
.
APIServer
)
error
{
func
Run
(
s
*
options
.
APIServer
)
error
{
genericvalidation
.
VerifyEtcdServersList
(
s
.
ServerRunOptions
)
genericvalidation
.
VerifyEtcdServersList
(
s
.
ServerRunOptions
)
genericapiserver
.
DefaultAndValidateRunOptions
(
s
.
ServerRunOptions
)
genericapiserver
.
DefaultAndValidateRunOptions
(
s
.
ServerRunOptions
)
genericConfig
:=
genericapiserver
.
NewConfig
()
.
// create the new config
ApplyOptions
(
s
.
ServerRunOptions
)
.
// apply the options selected
Complete
()
// set default values based on the known values
if
err
:=
genericConfig
.
MaybeGenerateServingCerts
();
err
!=
nil
{
glog
.
Fatalf
(
"Failed to generate service certificate: %v"
,
err
)
}
capabilities
.
Initialize
(
capabilities
.
Capabilities
{
capabilities
.
Initialize
(
capabilities
.
Capabilities
{
AllowPrivileged
:
s
.
AllowPrivileged
,
AllowPrivileged
:
s
.
AllowPrivileged
,
...
@@ -322,8 +329,6 @@ func Run(s *options.APIServer) error {
...
@@ -322,8 +329,6 @@ func Run(s *options.APIServer) error {
glog
.
Fatalf
(
"Failed to initialize plugins: %v"
,
err
)
glog
.
Fatalf
(
"Failed to initialize plugins: %v"
,
err
)
}
}
genericConfig
:=
genericapiserver
.
NewConfig
(
s
.
ServerRunOptions
)
// TODO: Move the following to generic api server as well.
genericConfig
.
LoopbackClientConfig
=
selfClientConfig
genericConfig
.
LoopbackClientConfig
=
selfClientConfig
genericConfig
.
Authenticator
=
apiAuthenticator
genericConfig
.
Authenticator
=
apiAuthenticator
genericConfig
.
SupportsBasicAuth
=
len
(
s
.
BasicAuthFile
)
>
0
genericConfig
.
SupportsBasicAuth
=
len
(
s
.
BasicAuthFile
)
>
0
...
@@ -341,7 +346,7 @@ func Run(s *options.APIServer) error {
...
@@ -341,7 +346,7 @@ func Run(s *options.APIServer) error {
genericConfig
.
EnableOpenAPISupport
=
true
genericConfig
.
EnableOpenAPISupport
=
true
config
:=
&
master
.
Config
{
config
:=
&
master
.
Config
{
GenericConfig
:
genericConfig
,
GenericConfig
:
genericConfig
.
Config
,
StorageFactory
:
storageFactory
,
StorageFactory
:
storageFactory
,
EnableWatchCache
:
s
.
EnableWatchCache
,
EnableWatchCache
:
s
.
EnableWatchCache
,
...
...
examples/apiserver/apiserver.go
View file @
fbd5032d
...
@@ -67,10 +67,15 @@ func Run(serverOptions *genericoptions.ServerRunOptions) error {
...
@@ -67,10 +67,15 @@ func Run(serverOptions *genericoptions.ServerRunOptions) error {
serverOptions
.
StorageConfig
.
ServerList
=
[]
string
{
"http://127.0.0.1:2379"
}
serverOptions
.
StorageConfig
.
ServerList
=
[]
string
{
"http://127.0.0.1:2379"
}
genericvalidation
.
ValidateRunOptions
(
serverOptions
)
genericvalidation
.
ValidateRunOptions
(
serverOptions
)
genericvalidation
.
VerifyEtcdServersList
(
serverOptions
)
genericvalidation
.
VerifyEtcdServersList
(
serverOptions
)
config
:=
genericapiserver
.
NewConfig
(
serverOptions
)
config
:=
genericapiserver
.
NewConfig
()
.
ApplyOptions
(
serverOptions
)
.
Complete
()
if
err
:=
config
.
MaybeGenerateServingCerts
();
err
!=
nil
{
// this wasn't treated as fatal for this process before
fmt
.
Printf
(
"Error creating cert: %v"
,
err
)
}
config
.
Authorizer
=
authorizer
.
NewAlwaysAllowAuthorizer
()
config
.
Authorizer
=
authorizer
.
NewAlwaysAllowAuthorizer
()
config
.
Serializer
=
api
.
Codecs
config
.
Serializer
=
api
.
Codecs
s
,
err
:=
config
.
Complete
()
.
New
()
s
,
err
:=
config
.
New
()
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error in bringing up the server: %v"
,
err
)
return
fmt
.
Errorf
(
"Error in bringing up the server: %v"
,
err
)
}
}
...
...
federation/cmd/federation-apiserver/app/server.go
View file @
fbd5032d
...
@@ -79,6 +79,13 @@ cluster's shared state through which all other components interact.`,
...
@@ -79,6 +79,13 @@ cluster's shared state through which all other components interact.`,
func
Run
(
s
*
options
.
ServerRunOptions
)
error
{
func
Run
(
s
*
options
.
ServerRunOptions
)
error
{
genericvalidation
.
VerifyEtcdServersList
(
s
.
ServerRunOptions
)
genericvalidation
.
VerifyEtcdServersList
(
s
.
ServerRunOptions
)
genericapiserver
.
DefaultAndValidateRunOptions
(
s
.
ServerRunOptions
)
genericapiserver
.
DefaultAndValidateRunOptions
(
s
.
ServerRunOptions
)
genericConfig
:=
genericapiserver
.
NewConfig
()
.
// create the new config
ApplyOptions
(
s
.
ServerRunOptions
)
.
// apply the options selected
Complete
()
// set default values based on the known values
if
err
:=
genericConfig
.
MaybeGenerateServingCerts
();
err
!=
nil
{
glog
.
Fatalf
(
"Failed to generate service certificate: %v"
,
err
)
}
// TODO: register cluster federation resources here.
// TODO: register cluster federation resources here.
resourceConfig
:=
genericapiserver
.
NewResourceConfig
()
resourceConfig
:=
genericapiserver
.
NewResourceConfig
()
...
@@ -211,8 +218,6 @@ func Run(s *options.ServerRunOptions) error {
...
@@ -211,8 +218,6 @@ func Run(s *options.ServerRunOptions) error {
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"Failed to initialize plugins: %v"
,
err
)
glog
.
Fatalf
(
"Failed to initialize plugins: %v"
,
err
)
}
}
genericConfig
:=
genericapiserver
.
NewConfig
(
s
.
ServerRunOptions
)
// TODO: Move the following to generic api server as well.
genericConfig
.
LoopbackClientConfig
=
selfClientConfig
genericConfig
.
LoopbackClientConfig
=
selfClientConfig
genericConfig
.
Authenticator
=
apiAuthenticator
genericConfig
.
Authenticator
=
apiAuthenticator
genericConfig
.
SupportsBasicAuth
=
len
(
s
.
BasicAuthFile
)
>
0
genericConfig
.
SupportsBasicAuth
=
len
(
s
.
BasicAuthFile
)
>
0
...
@@ -234,7 +239,7 @@ func Run(s *options.ServerRunOptions) error {
...
@@ -234,7 +239,7 @@ func Run(s *options.ServerRunOptions) error {
cachesize
.
SetWatchCacheSizes
(
s
.
WatchCacheSizes
)
cachesize
.
SetWatchCacheSizes
(
s
.
WatchCacheSizes
)
}
}
m
,
err
:=
genericConfig
.
Complete
()
.
New
()
m
,
err
:=
genericConfig
.
New
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/genericapiserver/config.go
View file @
fbd5032d
...
@@ -52,6 +52,7 @@ import (
...
@@ -52,6 +52,7 @@ import (
genericvalidation
"k8s.io/kubernetes/pkg/genericapiserver/validation"
genericvalidation
"k8s.io/kubernetes/pkg/genericapiserver/validation"
ipallocator
"k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
ipallocator
"k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
certutil
"k8s.io/kubernetes/pkg/util/cert"
utilnet
"k8s.io/kubernetes/pkg/util/net"
utilnet
"k8s.io/kubernetes/pkg/util/net"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/sets"
)
)
...
@@ -196,12 +197,54 @@ type CertInfo struct {
...
@@ -196,12 +197,54 @@ type CertInfo struct {
Generate
bool
Generate
bool
}
}
func
NewConfig
(
options
*
options
.
ServerRunOptions
)
*
Config
{
// NewConfig returns a Config struct with the default values
longRunningRE
:=
regexp
.
MustCompile
(
options
.
LongRunningRequestRE
)
func
NewConfig
()
*
Config
{
longRunningRE
:=
regexp
.
MustCompile
(
options
.
DefaultLongRunningRequestRE
)
config
:=
&
Config
{
MasterCount
:
1
,
ReadWritePort
:
6443
,
ServiceReadWritePort
:
443
,
CacheTimeout
:
5
*
time
.
Second
,
RequestContextMapper
:
api
.
NewRequestContextMapper
(),
BuildHandlerChainsFunc
:
DefaultBuildHandlerChain
,
LegacyAPIGroupPrefixes
:
sets
.
NewString
(
LegacyAPIPrefix
),
var
auditWriter
io
.
Writer
EnableIndex
:
true
,
EnableSwaggerSupport
:
true
,
EnableVersion
:
true
,
OpenAPIConfig
:
&
common
.
Config
{
ProtocolList
:
[]
string
{
"https"
},
IgnorePrefixes
:
[]
string
{
"/swaggerapi"
},
Info
:
&
spec
.
Info
{
InfoProps
:
spec
.
InfoProps
{
Title
:
"Generic API Server"
,
Version
:
"unversioned"
,
},
},
DefaultResponse
:
&
spec
.
Response
{
ResponseProps
:
spec
.
ResponseProps
{
Description
:
"Default Response."
,
},
},
},
LongRunningFunc
:
genericfilters
.
BasicLongRunningRequestCheck
(
longRunningRE
,
map
[
string
]
string
{
"watch"
:
"true"
}),
}
// this keeps the defaults in sync
defaultOptions
:=
options
.
NewServerRunOptions
()
// unset fields that can be overridden to avoid setting values so that we won't end up with lingering values.
// TODO we probably want to run the defaults the other way. A default here drives it in the CLI flags
defaultOptions
.
SecurePort
=
0
defaultOptions
.
InsecurePort
=
0
defaultOptions
.
AuditLogPath
=
""
return
config
.
ApplyOptions
(
defaultOptions
)
}
// ApplyOptions applies the run options to the method receiver and returns self
func
(
c
*
Config
)
ApplyOptions
(
options
*
options
.
ServerRunOptions
)
*
Config
{
if
len
(
options
.
AuditLogPath
)
!=
0
{
if
len
(
options
.
AuditLogPath
)
!=
0
{
a
uditWriter
=
&
lumberjack
.
Logger
{
c
.
A
uditWriter
=
&
lumberjack
.
Logger
{
Filename
:
options
.
AuditLogPath
,
Filename
:
options
.
AuditLogPath
,
MaxAge
:
options
.
AuditLogMaxAge
,
MaxAge
:
options
.
AuditLogMaxAge
,
MaxBackups
:
options
.
AuditLogMaxBackups
,
MaxBackups
:
options
.
AuditLogMaxBackups
,
...
@@ -209,9 +252,8 @@ func NewConfig(options *options.ServerRunOptions) *Config {
...
@@ -209,9 +252,8 @@ func NewConfig(options *options.ServerRunOptions) *Config {
}
}
}
}
var
secureServingInfo
*
ServingInfo
if
options
.
SecurePort
>
0
{
if
options
.
SecurePort
>
0
{
secureServingInfo
=
&
ServingInfo
{
secureServingInfo
:
=
&
ServingInfo
{
BindAddress
:
net
.
JoinHostPort
(
options
.
BindAddress
.
String
(),
strconv
.
Itoa
(
options
.
SecurePort
)),
BindAddress
:
net
.
JoinHostPort
(
options
.
BindAddress
.
String
(),
strconv
.
Itoa
(
options
.
SecurePort
)),
ServerCert
:
CertInfo
{
ServerCert
:
CertInfo
{
CertFile
:
options
.
TLSCertFile
,
CertFile
:
options
.
TLSCertFile
,
...
@@ -224,63 +266,43 @@ func NewConfig(options *options.ServerRunOptions) *Config {
...
@@ -224,63 +266,43 @@ func NewConfig(options *options.ServerRunOptions) *Config {
secureServingInfo
.
ServerCert
.
CertFile
=
path
.
Join
(
options
.
CertDirectory
,
"apiserver.crt"
)
secureServingInfo
.
ServerCert
.
CertFile
=
path
.
Join
(
options
.
CertDirectory
,
"apiserver.crt"
)
secureServingInfo
.
ServerCert
.
KeyFile
=
path
.
Join
(
options
.
CertDirectory
,
"apiserver.key"
)
secureServingInfo
.
ServerCert
.
KeyFile
=
path
.
Join
(
options
.
CertDirectory
,
"apiserver.key"
)
}
}
c
.
SecureServingInfo
=
secureServingInfo
c
.
ReadWritePort
=
options
.
SecurePort
}
}
var
insecureServingInfo
*
ServingInfo
if
options
.
InsecurePort
>
0
{
if
options
.
InsecurePort
>
0
{
insecureServingInfo
=
&
ServingInfo
{
insecureServingInfo
:
=
&
ServingInfo
{
BindAddress
:
net
.
JoinHostPort
(
options
.
InsecureBindAddress
.
String
(),
strconv
.
Itoa
(
options
.
InsecurePort
)),
BindAddress
:
net
.
JoinHostPort
(
options
.
InsecureBindAddress
.
String
(),
strconv
.
Itoa
(
options
.
InsecurePort
)),
}
}
c
.
InsecureServingInfo
=
insecureServingInfo
}
}
return
&
Config
{
c
.
APIGroupPrefix
=
options
.
APIGroupPrefix
APIGroupPrefix
:
options
.
APIGroupPrefix
,
c
.
CorsAllowedOriginList
=
options
.
CorsAllowedOriginList
CorsAllowedOriginList
:
options
.
CorsAllowedOriginList
,
c
.
EnableGarbageCollection
=
options
.
EnableGarbageCollection
AuditWriter
:
auditWriter
,
c
.
EnableProfiling
=
options
.
EnableProfiling
EnableGarbageCollection
:
options
.
EnableGarbageCollection
,
c
.
EnableSwaggerUI
=
options
.
EnableSwaggerUI
EnableIndex
:
true
,
c
.
ExternalHost
=
options
.
ExternalHost
EnableProfiling
:
options
.
EnableProfiling
,
c
.
KubernetesServiceNodePort
=
options
.
KubernetesServiceNodePort
EnableSwaggerSupport
:
true
,
c
.
MasterCount
=
options
.
MasterCount
EnableSwaggerUI
:
options
.
EnableSwaggerUI
,
c
.
MinRequestTimeout
=
options
.
MinRequestTimeout
EnableVersion
:
true
,
c
.
PublicAddress
=
options
.
AdvertiseAddress
ExternalHost
:
options
.
ExternalHost
,
c
.
ServiceClusterIPRange
=
&
options
.
ServiceClusterIPRange
KubernetesServiceNodePort
:
options
.
KubernetesServiceNodePort
,
c
.
ServiceNodePortRange
=
options
.
ServiceNodePortRange
MasterCount
:
options
.
MasterCount
,
c
.
MaxRequestsInFlight
=
options
.
MaxRequestsInFlight
MinRequestTimeout
:
options
.
MinRequestTimeout
,
SecureServingInfo
:
secureServingInfo
,
return
c
InsecureServingInfo
:
insecureServingInfo
,
PublicAddress
:
options
.
AdvertiseAddress
,
ReadWritePort
:
options
.
SecurePort
,
ServiceClusterIPRange
:
&
options
.
ServiceClusterIPRange
,
ServiceNodePortRange
:
options
.
ServiceNodePortRange
,
OpenAPIConfig
:
&
common
.
Config
{
ProtocolList
:
[]
string
{
"https"
},
IgnorePrefixes
:
[]
string
{
"/swaggerapi"
},
Info
:
&
spec
.
Info
{
InfoProps
:
spec
.
InfoProps
{
Title
:
"Generic API Server"
,
Version
:
"unversioned"
,
},
},
DefaultResponse
:
&
spec
.
Response
{
ResponseProps
:
spec
.
ResponseProps
{
Description
:
"Default Response."
,
},
},
},
MaxRequestsInFlight
:
options
.
MaxRequestsInFlight
,
LongRunningFunc
:
genericfilters
.
BasicLongRunningRequestCheck
(
longRunningRE
,
map
[
string
]
string
{
"watch"
:
"true"
}),
LegacyAPIGroupPrefixes
:
sets
.
NewString
(
LegacyAPIPrefix
),
}
}
}
type
completedConfig
struct
{
type
completedConfig
struct
{
*
Config
*
Config
}
}
// Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
// Complete fills in any fields not set that are required to have valid data and can be derived
// from other fields. If you're going to `ApplyOptions`, do that first. It's mutating the receiver.
func
(
c
*
Config
)
Complete
()
completedConfig
{
func
(
c
*
Config
)
Complete
()
completedConfig
{
if
c
.
ServiceClusterIPRange
==
nil
{
if
c
.
ServiceClusterIPRange
==
nil
||
c
.
ServiceClusterIPRange
.
IP
==
nil
{
defaultNet
:=
"10.0.0.0/24"
defaultNet
:=
"10.0.0.0/24"
glog
.
Warningf
(
"Network range for service cluster IPs is unspecified. Defaulting to %v."
,
defaultNet
)
glog
.
Warningf
(
"Network range for service cluster IPs is unspecified. Defaulting to %v."
,
defaultNet
)
_
,
serviceClusterIPRange
,
err
:=
net
.
ParseCIDR
(
defaultNet
)
_
,
serviceClusterIPRange
,
err
:=
net
.
ParseCIDR
(
defaultNet
)
...
@@ -301,9 +323,6 @@ func (c *Config) Complete() completedConfig {
...
@@ -301,9 +323,6 @@ func (c *Config) Complete() completedConfig {
glog
.
V
(
4
)
.
Infof
(
"Setting GenericAPIServer service IP to %q (read-write)."
,
serviceReadWriteIP
)
glog
.
V
(
4
)
.
Infof
(
"Setting GenericAPIServer service IP to %q (read-write)."
,
serviceReadWriteIP
)
c
.
ServiceReadWriteIP
=
serviceReadWriteIP
c
.
ServiceReadWriteIP
=
serviceReadWriteIP
}
}
if
c
.
ServiceReadWritePort
==
0
{
c
.
ServiceReadWritePort
=
443
}
if
c
.
ServiceNodePortRange
.
Size
==
0
{
if
c
.
ServiceNodePortRange
.
Size
==
0
{
// TODO: Currently no way to specify an empty range (do we need to allow this?)
// TODO: Currently no way to specify an empty range (do we need to allow this?)
// We should probably allow this for clouds that don't require NodePort to do load-balancing (GCE)
// We should probably allow this for clouds that don't require NodePort to do load-balancing (GCE)
...
@@ -312,19 +331,6 @@ func (c *Config) Complete() completedConfig {
...
@@ -312,19 +331,6 @@ func (c *Config) Complete() completedConfig {
c
.
ServiceNodePortRange
=
options
.
DefaultServiceNodePortRange
c
.
ServiceNodePortRange
=
options
.
DefaultServiceNodePortRange
glog
.
Infof
(
"Node port range unspecified. Defaulting to %v."
,
c
.
ServiceNodePortRange
)
glog
.
Infof
(
"Node port range unspecified. Defaulting to %v."
,
c
.
ServiceNodePortRange
)
}
}
if
c
.
MasterCount
==
0
{
// Clearly, there will be at least one GenericAPIServer.
c
.
MasterCount
=
1
}
if
c
.
ReadWritePort
==
0
{
c
.
ReadWritePort
=
6443
}
if
c
.
CacheTimeout
==
0
{
c
.
CacheTimeout
=
5
*
time
.
Second
}
if
c
.
RequestContextMapper
==
nil
{
c
.
RequestContextMapper
=
api
.
NewRequestContextMapper
()
}
if
len
(
c
.
ExternalHost
)
==
0
&&
c
.
PublicAddress
!=
nil
{
if
len
(
c
.
ExternalHost
)
==
0
&&
c
.
PublicAddress
!=
nil
{
hostAndPort
:=
c
.
PublicAddress
.
String
()
hostAndPort
:=
c
.
PublicAddress
.
String
()
if
c
.
ReadWritePort
!=
0
{
if
c
.
ReadWritePort
!=
0
{
...
@@ -332,9 +338,6 @@ func (c *Config) Complete() completedConfig {
...
@@ -332,9 +338,6 @@ func (c *Config) Complete() completedConfig {
}
}
c
.
ExternalHost
=
hostAndPort
c
.
ExternalHost
=
hostAndPort
}
}
if
c
.
BuildHandlerChainsFunc
==
nil
{
c
.
BuildHandlerChainsFunc
=
DefaultBuildHandlerChain
}
return
completedConfig
{
c
}
return
completedConfig
{
c
}
}
}
...
@@ -386,7 +389,6 @@ func (c completedConfig) New() (*GenericAPIServer, error) {
...
@@ -386,7 +389,6 @@ func (c completedConfig) New() (*GenericAPIServer, error) {
SecureServingInfo
:
c
.
SecureServingInfo
,
SecureServingInfo
:
c
.
SecureServingInfo
,
InsecureServingInfo
:
c
.
InsecureServingInfo
,
InsecureServingInfo
:
c
.
InsecureServingInfo
,
ExternalAddress
:
c
.
ExternalHost
,
ExternalAddress
:
c
.
ExternalHost
,
ClusterIP
:
c
.
PublicAddress
,
ServiceReadWriteIP
:
c
.
ServiceReadWriteIP
,
ServiceReadWriteIP
:
c
.
ServiceReadWriteIP
,
ServiceReadWritePort
:
c
.
ServiceReadWritePort
,
ServiceReadWritePort
:
c
.
ServiceReadWritePort
,
...
@@ -413,6 +415,25 @@ func (c completedConfig) New() (*GenericAPIServer, error) {
...
@@ -413,6 +415,25 @@ func (c completedConfig) New() (*GenericAPIServer, error) {
return
s
,
nil
return
s
,
nil
}
}
// MaybeGenerateServingCerts generates serving certificates if requested and needed.
func
(
c
completedConfig
)
MaybeGenerateServingCerts
()
error
{
// It would be nice to set a fqdn subject alt name, but only the kubelets know, the apiserver is clueless
// alternateDNS = append(alternateDNS, "kubernetes.default.svc.CLUSTER.DNS.NAME")
if
c
.
SecureServingInfo
!=
nil
&&
c
.
SecureServingInfo
.
ServerCert
.
Generate
&&
!
certutil
.
CanReadCertOrKey
(
c
.
SecureServingInfo
.
ServerCert
.
CertFile
,
c
.
SecureServingInfo
.
ServerCert
.
KeyFile
)
{
// TODO (cjcullen): Is ClusterIP the right address to sign a cert with?
alternateIPs
:=
[]
net
.
IP
{
c
.
ServiceReadWriteIP
}
alternateDNS
:=
[]
string
{
"kubernetes.default.svc"
,
"kubernetes.default"
,
"kubernetes"
,
"localhost"
}
if
err
:=
certutil
.
GenerateSelfSignedCert
(
c
.
PublicAddress
.
String
(),
c
.
SecureServingInfo
.
ServerCert
.
CertFile
,
c
.
SecureServingInfo
.
ServerCert
.
KeyFile
,
alternateIPs
,
alternateDNS
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to generate self signed cert: %v"
,
err
)
}
else
{
glog
.
Infof
(
"Generated self-signed cert (%s, %s)"
,
c
.
SecureServingInfo
.
ServerCert
.
CertFile
,
c
.
SecureServingInfo
.
ServerCert
.
KeyFile
)
}
}
return
nil
}
func
DefaultBuildHandlerChain
(
apiHandler
http
.
Handler
,
c
*
Config
)
(
secure
,
insecure
http
.
Handler
)
{
func
DefaultBuildHandlerChain
(
apiHandler
http
.
Handler
,
c
*
Config
)
(
secure
,
insecure
http
.
Handler
)
{
attributeGetter
:=
apiserverfilters
.
NewRequestAttributeGetter
(
c
.
RequestContextMapper
)
attributeGetter
:=
apiserverfilters
.
NewRequestAttributeGetter
(
c
.
RequestContextMapper
)
...
...
pkg/genericapiserver/genericapiserver.go
View file @
fbd5032d
...
@@ -124,9 +124,6 @@ type GenericAPIServer struct {
...
@@ -124,9 +124,6 @@ type GenericAPIServer struct {
// external (public internet) URLs for this GenericAPIServer.
// external (public internet) URLs for this GenericAPIServer.
ExternalAddress
string
ExternalAddress
string
// ClusterIP is the IP address of the GenericAPIServer within the cluster.
ClusterIP
net
.
IP
// storage contains the RESTful endpoints exposed by this GenericAPIServer
// storage contains the RESTful endpoints exposed by this GenericAPIServer
storage
map
[
string
]
rest
.
Storage
storage
map
[
string
]
rest
.
Storage
...
@@ -225,20 +222,6 @@ func (s *GenericAPIServer) Run() {
...
@@ -225,20 +222,6 @@ func (s *GenericAPIServer) Run() {
}
}
// It would be nice to set a fqdn subject alt name, but only the kubelets know, the apiserver is clueless
// alternateDNS = append(alternateDNS, "kubernetes.default.svc.CLUSTER.DNS.NAME")
if
s
.
SecureServingInfo
.
ServerCert
.
Generate
&&
!
certutil
.
CanReadCertOrKey
(
s
.
SecureServingInfo
.
ServerCert
.
CertFile
,
s
.
SecureServingInfo
.
ServerCert
.
KeyFile
)
{
// TODO (cjcullen): Is ClusterIP the right address to sign a cert with?
alternateIPs
:=
[]
net
.
IP
{
s
.
ServiceReadWriteIP
}
alternateDNS
:=
[]
string
{
"kubernetes.default.svc"
,
"kubernetes.default"
,
"kubernetes"
,
"localhost"
}
if
err
:=
certutil
.
GenerateSelfSignedCert
(
s
.
ClusterIP
.
String
(),
s
.
SecureServingInfo
.
ServerCert
.
CertFile
,
s
.
SecureServingInfo
.
ServerCert
.
KeyFile
,
alternateIPs
,
alternateDNS
);
err
!=
nil
{
glog
.
Errorf
(
"Unable to generate self signed cert: %v"
,
err
)
}
else
{
glog
.
Infof
(
"Using self-signed cert (%s, %s)"
,
s
.
SecureServingInfo
.
ServerCert
.
CertFile
,
s
.
SecureServingInfo
.
ServerCert
.
KeyFile
)
}
}
glog
.
Infof
(
"Serving securely on %s"
,
s
.
SecureServingInfo
.
BindAddress
)
glog
.
Infof
(
"Serving securely on %s"
,
s
.
SecureServingInfo
.
BindAddress
)
go
func
()
{
go
func
()
{
defer
utilruntime
.
HandleCrash
()
defer
utilruntime
.
HandleCrash
()
...
...
pkg/genericapiserver/genericapiserver_test.go
View file @
fbd5032d
...
@@ -50,7 +50,7 @@ import (
...
@@ -50,7 +50,7 @@ import (
func
setUp
(
t
*
testing
.
T
)
(
*
etcdtesting
.
EtcdTestServer
,
Config
,
*
assert
.
Assertions
)
{
func
setUp
(
t
*
testing
.
T
)
(
*
etcdtesting
.
EtcdTestServer
,
Config
,
*
assert
.
Assertions
)
{
etcdServer
,
_
:=
etcdtesting
.
NewUnsecuredEtcd3TestClientServer
(
t
)
etcdServer
,
_
:=
etcdtesting
.
NewUnsecuredEtcd3TestClientServer
(
t
)
config
:=
Config
{}
config
:=
NewConfig
()
config
.
PublicAddress
=
net
.
ParseIP
(
"192.168.10.4"
)
config
.
PublicAddress
=
net
.
ParseIP
(
"192.168.10.4"
)
config
.
RequestContextMapper
=
api
.
NewRequestContextMapper
()
config
.
RequestContextMapper
=
api
.
NewRequestContextMapper
()
config
.
ProxyDialer
=
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
nil
,
nil
}
config
.
ProxyDialer
=
func
(
network
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
nil
,
nil
}
...
@@ -59,7 +59,7 @@ func setUp(t *testing.T) (*etcdtesting.EtcdTestServer, Config, *assert.Assertion
...
@@ -59,7 +59,7 @@ func setUp(t *testing.T) (*etcdtesting.EtcdTestServer, Config, *assert.Assertion
config
.
LegacyAPIGroupPrefixes
=
sets
.
NewString
(
"/api"
)
config
.
LegacyAPIGroupPrefixes
=
sets
.
NewString
(
"/api"
)
config
.
APIGroupPrefix
=
"/apis"
config
.
APIGroupPrefix
=
"/apis"
return
etcdServer
,
config
,
assert
.
New
(
t
)
return
etcdServer
,
*
config
,
assert
.
New
(
t
)
}
}
func
newMaster
(
t
*
testing
.
T
)
(
*
GenericAPIServer
,
*
etcdtesting
.
EtcdTestServer
,
Config
,
*
assert
.
Assertions
)
{
func
newMaster
(
t
*
testing
.
T
)
(
*
GenericAPIServer
,
*
etcdtesting
.
EtcdTestServer
,
Config
,
*
assert
.
Assertions
)
{
...
@@ -84,7 +84,6 @@ func TestNew(t *testing.T) {
...
@@ -84,7 +84,6 @@ func TestNew(t *testing.T) {
assert
.
Equal
(
s
.
apiPrefix
,
config
.
APIGroupPrefix
)
assert
.
Equal
(
s
.
apiPrefix
,
config
.
APIGroupPrefix
)
assert
.
Equal
(
s
.
admissionControl
,
config
.
AdmissionControl
)
assert
.
Equal
(
s
.
admissionControl
,
config
.
AdmissionControl
)
assert
.
Equal
(
s
.
RequestContextMapper
(),
config
.
RequestContextMapper
)
assert
.
Equal
(
s
.
RequestContextMapper
(),
config
.
RequestContextMapper
)
assert
.
Equal
(
s
.
ClusterIP
,
config
.
PublicAddress
)
// these values get defaulted
// these values get defaulted
_
,
serviceClusterIPRange
,
_
:=
net
.
ParseCIDR
(
"10.0.0.0/24"
)
_
,
serviceClusterIPRange
,
_
:=
net
.
ParseCIDR
(
"10.0.0.0/24"
)
...
@@ -109,7 +108,7 @@ func TestInstallAPIGroups(t *testing.T) {
...
@@ -109,7 +108,7 @@ func TestInstallAPIGroups(t *testing.T) {
config
.
LegacyAPIGroupPrefixes
=
sets
.
NewString
(
"/apiPrefix"
)
config
.
LegacyAPIGroupPrefixes
=
sets
.
NewString
(
"/apiPrefix"
)
config
.
APIGroupPrefix
=
"/apiGroupPrefix"
config
.
APIGroupPrefix
=
"/apiGroupPrefix"
s
,
err
:=
config
.
Complete
()
.
New
()
s
,
err
:=
config
.
Skip
Complete
()
.
New
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Error in bringing up the server: %v"
,
err
)
t
.
Fatalf
(
"Error in bringing up the server: %v"
,
err
)
}
}
...
@@ -179,7 +178,7 @@ func TestCustomHandlerChain(t *testing.T) {
...
@@ -179,7 +178,7 @@ func TestCustomHandlerChain(t *testing.T) {
called
=
true
called
=
true
})
})
s
,
err
:=
config
.
Complete
()
.
New
()
s
,
err
:=
config
.
Skip
Complete
()
.
New
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Error in bringing up the server: %v"
,
err
)
t
.
Fatalf
(
"Error in bringing up the server: %v"
,
err
)
}
}
...
@@ -235,7 +234,7 @@ func TestNotRestRoutesHaveAuth(t *testing.T) {
...
@@ -235,7 +234,7 @@ func TestNotRestRoutesHaveAuth(t *testing.T) {
config
.
EnableSwaggerSupport
=
true
config
.
EnableSwaggerSupport
=
true
config
.
EnableVersion
=
true
config
.
EnableVersion
=
true
s
,
err
:=
config
.
Complete
()
.
New
()
s
,
err
:=
config
.
Skip
Complete
()
.
New
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Error in bringing up the server: %v"
,
err
)
t
.
Fatalf
(
"Error in bringing up the server: %v"
,
err
)
}
}
...
@@ -311,7 +310,6 @@ func TestInstallSwaggerAPI(t *testing.T) {
...
@@ -311,7 +310,6 @@ func TestInstallSwaggerAPI(t *testing.T) {
mux
=
http
.
NewServeMux
()
mux
=
http
.
NewServeMux
()
server
.
HandlerContainer
=
genericmux
.
NewAPIContainer
(
mux
,
nil
)
server
.
HandlerContainer
=
genericmux
.
NewAPIContainer
(
mux
,
nil
)
server
.
ExternalAddress
=
""
server
.
ExternalAddress
=
""
server
.
ClusterIP
=
net
.
IPv4
(
10
,
10
,
10
,
10
)
server
.
InstallSwaggerAPI
()
server
.
InstallSwaggerAPI
()
if
assert
.
NotEqual
(
0
,
len
(
ws
),
"SwaggerAPI not installed."
)
{
if
assert
.
NotEqual
(
0
,
len
(
ws
),
"SwaggerAPI not installed."
)
{
assert
.
Equal
(
"/swaggerapi/"
,
ws
[
0
]
.
RootPath
(),
"SwaggerAPI did not install to the proper path. %s != /swaggerapi"
,
ws
[
0
]
.
RootPath
())
assert
.
Equal
(
"/swaggerapi/"
,
ws
[
0
]
.
RootPath
(),
"SwaggerAPI did not install to the proper path. %s != /swaggerapi"
,
ws
[
0
]
.
RootPath
())
...
...
pkg/genericapiserver/options/server_run_options.go
View file @
fbd5032d
...
@@ -38,7 +38,7 @@ import (
...
@@ -38,7 +38,7 @@ import (
const
(
const
(
// TODO: This can be tightened up. It still matches objects named watch or proxy.
// TODO: This can be tightened up. It still matches objects named watch or proxy.
d
efaultLongRunningRequestRE
=
"(/|^)((watch|proxy)(/|$)|(logs?|portforward|exec|attach)/?$)"
D
efaultLongRunningRequestRE
=
"(/|^)((watch|proxy)(/|$)|(logs?|portforward|exec|attach)/?$)"
)
)
var
DefaultServiceNodePortRange
=
utilnet
.
PortRange
{
Base
:
30000
,
Size
:
2768
}
var
DefaultServiceNodePortRange
=
utilnet
.
PortRange
{
Base
:
30000
,
Size
:
2768
}
...
@@ -139,7 +139,7 @@ func NewServerRunOptions() *ServerRunOptions {
...
@@ -139,7 +139,7 @@ func NewServerRunOptions() *ServerRunOptions {
EnableWatchCache
:
true
,
EnableWatchCache
:
true
,
InsecureBindAddress
:
net
.
ParseIP
(
"127.0.0.1"
),
InsecureBindAddress
:
net
.
ParseIP
(
"127.0.0.1"
),
InsecurePort
:
8080
,
InsecurePort
:
8080
,
LongRunningRequestRE
:
d
efaultLongRunningRequestRE
,
LongRunningRequestRE
:
D
efaultLongRunningRequestRE
,
MasterCount
:
1
,
MasterCount
:
1
,
MasterServiceNamespace
:
api
.
NamespaceDefault
,
MasterServiceNamespace
:
api
.
NamespaceDefault
,
MaxRequestsInFlight
:
400
,
MaxRequestsInFlight
:
400
,
...
...
pkg/master/master_test.go
View file @
fbd5032d
...
@@ -49,7 +49,6 @@ import (
...
@@ -49,7 +49,6 @@ import (
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/client/restclient"
openapigen
"k8s.io/kubernetes/pkg/generated/openapi"
openapigen
"k8s.io/kubernetes/pkg/generated/openapi"
"k8s.io/kubernetes/pkg/genericapiserver"
"k8s.io/kubernetes/pkg/genericapiserver"
"k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
"k8s.io/kubernetes/pkg/kubelet/client"
"k8s.io/kubernetes/pkg/kubelet/client"
ipallocator
"k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
ipallocator
"k8s.io/kubernetes/pkg/registry/core/service/ipallocator"
"k8s.io/kubernetes/pkg/registry/registrytest"
"k8s.io/kubernetes/pkg/registry/registrytest"
...
@@ -71,9 +70,7 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
...
@@ -71,9 +70,7 @@ func setUp(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.
server
,
storageConfig
:=
etcdtesting
.
NewUnsecuredEtcd3TestClientServer
(
t
)
server
,
storageConfig
:=
etcdtesting
.
NewUnsecuredEtcd3TestClientServer
(
t
)
config
:=
&
Config
{
config
:=
&
Config
{
GenericConfig
:
&
genericapiserver
.
Config
{
GenericConfig
:
genericapiserver
.
NewConfig
(),
OpenAPIConfig
:
&
common
.
Config
{},
},
}
}
resourceEncoding
:=
genericapiserver
.
NewDefaultResourceEncodingConfig
()
resourceEncoding
:=
genericapiserver
.
NewDefaultResourceEncodingConfig
()
...
@@ -164,10 +161,6 @@ func TestNew(t *testing.T) {
...
@@ -164,10 +161,6 @@ func TestNew(t *testing.T) {
master
,
etcdserver
,
config
,
assert
:=
newMaster
(
t
)
master
,
etcdserver
,
config
,
assert
:=
newMaster
(
t
)
defer
etcdserver
.
Terminate
(
t
)
defer
etcdserver
.
Terminate
(
t
)
// Verify many of the variables match their config counterparts
assert
.
Equal
(
master
.
GenericAPIServer
.
RequestContextMapper
(),
config
.
GenericConfig
.
RequestContextMapper
)
assert
.
Equal
(
master
.
GenericAPIServer
.
ClusterIP
,
config
.
GenericConfig
.
PublicAddress
)
// these values get defaulted
// these values get defaulted
_
,
serviceClusterIPRange
,
_
:=
net
.
ParseCIDR
(
"10.0.0.0/24"
)
_
,
serviceClusterIPRange
,
_
:=
net
.
ParseCIDR
(
"10.0.0.0/24"
)
serviceReadWriteIP
,
_
:=
ipallocator
.
GetIndexedIP
(
serviceClusterIPRange
,
1
)
serviceReadWriteIP
,
_
:=
ipallocator
.
GetIndexedIP
(
serviceClusterIPRange
,
1
)
...
...
test/integration/framework/master_utils.go
View file @
fbd5032d
...
@@ -60,8 +60,6 @@ import (
...
@@ -60,8 +60,6 @@ import (
"k8s.io/kubernetes/pkg/master"
"k8s.io/kubernetes/pkg/master"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage/storagebackend"
"k8s.io/kubernetes/pkg/storage/storagebackend"
utilnet
"k8s.io/kubernetes/pkg/util/net"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/plugin/pkg/admission/admit"
"k8s.io/kubernetes/plugin/pkg/admission/admit"
...
@@ -69,7 +67,6 @@ import (
...
@@ -69,7 +67,6 @@ import (
"github.com/go-openapi/spec"
"github.com/go-openapi/spec"
"github.com/pborman/uuid"
"github.com/pborman/uuid"
"k8s.io/kubernetes/pkg/genericapiserver/openapi/common"
)
)
const
(
const
(
...
@@ -346,21 +343,15 @@ func NewMasterConfig() *master.Config {
...
@@ -346,21 +343,15 @@ func NewMasterConfig() *master.Config {
""
,
""
,
NewSingleContentTypeSerializer
(
api
.
Scheme
,
testapi
.
Storage
.
Codec
(),
runtime
.
ContentTypeJSON
))
NewSingleContentTypeSerializer
(
api
.
Scheme
,
testapi
.
Storage
.
Codec
(),
runtime
.
ContentTypeJSON
))
genericConfig
:=
genericapiserver
.
NewConfig
()
genericConfig
.
APIResourceConfigSource
=
master
.
DefaultAPIResourceConfigSource
()
genericConfig
.
Authorizer
=
authorizer
.
NewAlwaysAllowAuthorizer
()
genericConfig
.
AdmissionControl
=
admit
.
NewAlwaysAdmit
()
genericConfig
.
Serializer
=
api
.
Codecs
genericConfig
.
EnableOpenAPISupport
=
true
return
&
master
.
Config
{
return
&
master
.
Config
{
GenericConfig
:
&
genericapiserver
.
Config
{
GenericConfig
:
genericConfig
,
APIResourceConfigSource
:
master
.
DefaultAPIResourceConfigSource
(),
LegacyAPIGroupPrefixes
:
sets
.
NewString
(
"/api"
),
APIGroupPrefix
:
"/apis"
,
Authorizer
:
authorizer
.
NewAlwaysAllowAuthorizer
(),
AdmissionControl
:
admit
.
NewAlwaysAdmit
(),
Serializer
:
api
.
Codecs
,
// Set those values to avoid annoying warnings in logs.
ServiceClusterIPRange
:
parseCIDROrDie
(
"10.0.0.0/24"
),
ServiceNodePortRange
:
utilnet
.
PortRange
{
Base
:
30000
,
Size
:
2768
},
EnableVersion
:
true
,
EnableOpenAPISupport
:
true
,
OpenAPIConfig
:
&
common
.
Config
{},
},
StorageFactory
:
storageFactory
,
StorageFactory
:
storageFactory
,
EnableCoreControllers
:
true
,
EnableCoreControllers
:
true
,
EnableWatchCache
:
true
,
EnableWatchCache
:
true
,
...
@@ -372,8 +363,6 @@ func NewMasterConfig() *master.Config {
...
@@ -372,8 +363,6 @@ func NewMasterConfig() *master.Config {
func
NewIntegrationTestMasterConfig
()
*
master
.
Config
{
func
NewIntegrationTestMasterConfig
()
*
master
.
Config
{
masterConfig
:=
NewMasterConfig
()
masterConfig
:=
NewMasterConfig
()
masterConfig
.
EnableCoreControllers
=
true
masterConfig
.
EnableCoreControllers
=
true
masterConfig
.
GenericConfig
.
EnableIndex
=
true
masterConfig
.
GenericConfig
.
EnableVersion
=
true
masterConfig
.
GenericConfig
.
PublicAddress
=
net
.
ParseIP
(
"192.168.10.4"
)
masterConfig
.
GenericConfig
.
PublicAddress
=
net
.
ParseIP
(
"192.168.10.4"
)
masterConfig
.
GenericConfig
.
APIResourceConfigSource
=
master
.
DefaultAPIResourceConfigSource
()
masterConfig
.
GenericConfig
.
APIResourceConfigSource
=
master
.
DefaultAPIResourceConfigSource
()
return
masterConfig
return
masterConfig
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment