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
f21475ac
Commit
f21475ac
authored
May 16, 2018
by
stewart-yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify kube-controller manager config struct to adapt option change
parent
14f7b959
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
112 deletions
+60
-112
config.go
cmd/controller-manager/app/config.go
+0
-64
serve.go
cmd/controller-manager/app/serve.go
+8
-6
config.go
cmd/kube-controller-manager/app/config/config.go
+26
-16
controllermanager.go
cmd/kube-controller-manager/app/controllermanager.go
+26
-26
No files found.
cmd/controller-manager/app/config.go
deleted
100644 → 0
View file @
14f7b959
/*
Copyright 2018 The Kubernetes Authors.
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
app
import
(
apiserver
"k8s.io/apiserver/pkg/server"
clientset
"k8s.io/client-go/kubernetes"
restclient
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/apis/componentconfig"
)
// Config is the main context object for the controller manager.
type
Config
struct
{
ComponentConfig
componentconfig
.
KubeControllerManagerConfiguration
SecureServing
*
apiserver
.
SecureServingInfo
// TODO: remove deprecated insecure serving
InsecureServing
*
InsecureServingInfo
Authentication
apiserver
.
AuthenticationInfo
Authorization
apiserver
.
AuthorizationInfo
// the general kube client
Client
*
clientset
.
Clientset
// the client only used for leader election
LeaderElectionClient
*
clientset
.
Clientset
// the rest config for the master
Kubeconfig
*
restclient
.
Config
// the event sink
EventRecorder
record
.
EventRecorder
}
type
completedConfig
struct
{
*
Config
}
// CompletedConfig same as Config, just to swap private object.
type
CompletedConfig
struct
{
// Embed a private pointer that cannot be instantiated outside of this package.
*
completedConfig
}
// Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
func
(
c
*
Config
)
Complete
()
CompletedConfig
{
cc
:=
completedConfig
{
c
}
return
CompletedConfig
{
&
cc
}
}
cmd/controller-manager/app/serve.go
View file @
f21475ac
...
@@ -24,21 +24,23 @@ import (
...
@@ -24,21 +24,23 @@ import (
genericapifilters
"k8s.io/apiserver/pkg/endpoints/filters"
genericapifilters
"k8s.io/apiserver/pkg/endpoints/filters"
apirequest
"k8s.io/apiserver/pkg/endpoints/request"
apirequest
"k8s.io/apiserver/pkg/endpoints/request"
apiserver
"k8s.io/apiserver/pkg/server"
genericfilters
"k8s.io/apiserver/pkg/server/filters"
genericfilters
"k8s.io/apiserver/pkg/server/filters"
"k8s.io/apiserver/pkg/server/healthz"
"k8s.io/apiserver/pkg/server/healthz"
"k8s.io/apiserver/pkg/server/mux"
"k8s.io/apiserver/pkg/server/mux"
"k8s.io/apiserver/pkg/server/routes"
"k8s.io/apiserver/pkg/server/routes"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/componentconfig"
"k8s.io/kubernetes/pkg/util/configz"
"k8s.io/kubernetes/pkg/util/configz"
)
)
// BuildHandlerChain builds a handler chain with a base handler and CompletedConfig.
// BuildHandlerChain builds a handler chain with a base handler and CompletedConfig.
func
BuildHandlerChain
(
apiHandler
http
.
Handler
,
c
*
CompletedConfig
)
http
.
Handler
{
func
BuildHandlerChain
(
apiHandler
http
.
Handler
,
authorizationInfo
*
apiserver
.
AuthorizationInfo
,
authenticationInfo
*
apiserver
.
AuthenticationInfo
)
http
.
Handler
{
requestInfoResolver
:=
&
apirequest
.
RequestInfoFactory
{}
requestInfoResolver
:=
&
apirequest
.
RequestInfoFactory
{}
failedHandler
:=
genericapifilters
.
Unauthorized
(
legacyscheme
.
Codecs
,
false
)
failedHandler
:=
genericapifilters
.
Unauthorized
(
legacyscheme
.
Codecs
,
false
)
handler
:=
genericapifilters
.
WithAuthorization
(
apiHandler
,
c
.
Authorization
.
Authorizer
,
legacyscheme
.
Codecs
)
handler
:=
genericapifilters
.
WithAuthorization
(
apiHandler
,
authorizationInfo
.
Authorizer
,
legacyscheme
.
Codecs
)
handler
=
genericapifilters
.
WithAuthentication
(
handler
,
c
.
Authentication
.
Authenticator
,
failedHandler
)
handler
=
genericapifilters
.
WithAuthentication
(
handler
,
authenticationInfo
.
Authenticator
,
failedHandler
)
handler
=
genericapifilters
.
WithRequestInfo
(
handler
,
requestInfoResolver
)
handler
=
genericapifilters
.
WithRequestInfo
(
handler
,
requestInfoResolver
)
handler
=
genericfilters
.
WithPanicRecovery
(
handler
)
handler
=
genericfilters
.
WithPanicRecovery
(
handler
)
...
@@ -46,12 +48,12 @@ func BuildHandlerChain(apiHandler http.Handler, c *CompletedConfig) http.Handler
...
@@ -46,12 +48,12 @@ func BuildHandlerChain(apiHandler http.Handler, c *CompletedConfig) http.Handler
}
}
// NewBaseHandler takes in CompletedConfig and returns a handler.
// NewBaseHandler takes in CompletedConfig and returns a handler.
func
NewBaseHandler
(
c
*
CompletedConfig
)
http
.
Handler
{
func
NewBaseHandler
(
c
*
componentconfig
.
DebuggingConfiguration
)
http
.
Handler
{
mux
:=
mux
.
NewPathRecorderMux
(
"controller-manager"
)
mux
:=
mux
.
NewPathRecorderMux
(
"controller-manager"
)
healthz
.
InstallHandler
(
mux
)
healthz
.
InstallHandler
(
mux
)
if
c
.
ComponentConfig
.
Debugging
.
EnableProfiling
{
if
c
.
EnableProfiling
{
routes
.
Profiling
{}
.
Install
(
mux
)
routes
.
Profiling
{}
.
Install
(
mux
)
if
c
.
ComponentConfig
.
Debugging
.
EnableContentionProfiling
{
if
c
.
EnableContentionProfiling
{
goruntime
.
SetBlockProfileRate
(
1
)
goruntime
.
SetBlockProfileRate
(
1
)
}
}
}
}
...
...
cmd/kube-controller-manager/app/config/config.go
View file @
f21475ac
...
@@ -17,25 +17,39 @@ limitations under the License.
...
@@ -17,25 +17,39 @@ limitations under the License.
package
config
package
config
import
(
import
(
"time"
apiserver
"k8s.io/apiserver/pkg/server"
clientset
"k8s.io/client-go/kubernetes"
restclient
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"
genericcontrollermanager
"k8s.io/kubernetes/cmd/controller-manager/app"
genericcontrollermanager
"k8s.io/kubernetes/cmd/controller-manager/app"
"k8s.io/kubernetes/pkg/apis/componentconfig"
)
)
// ExtraConfig are part of Config, also can place your custom config here.
type
ExtraConfig
struct
{
NodeStatusUpdateFrequency
time
.
Duration
}
// Config is the main context object for the controller manager.
// Config is the main context object for the controller manager.
type
Config
struct
{
type
Config
struct
{
Generic
genericcontrollermanager
.
Config
ComponentConfig
componentconfig
.
KubeControllerManagerConfiguration
Extra
ExtraConfig
SecureServing
*
apiserver
.
SecureServingInfo
// TODO: remove deprecated insecure serving
InsecureServing
*
genericcontrollermanager
.
InsecureServingInfo
Authentication
apiserver
.
AuthenticationInfo
Authorization
apiserver
.
AuthorizationInfo
// the general kube client
Client
*
clientset
.
Clientset
// the client only used for leader election
LeaderElectionClient
*
clientset
.
Clientset
// the rest config for the master
Kubeconfig
*
restclient
.
Config
// the event sink
EventRecorder
record
.
EventRecorder
}
}
type
completedConfig
struct
{
type
completedConfig
struct
{
Generic
genericcontrollermanager
.
CompletedConfig
*
Config
Extra
*
ExtraConfig
}
}
// CompletedConfig same as Config, just to swap private object.
// CompletedConfig same as Config, just to swap private object.
...
@@ -46,10 +60,6 @@ type CompletedConfig struct {
...
@@ -46,10 +60,6 @@ type CompletedConfig struct {
// 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. It's mutating the receiver.
func
(
c
*
Config
)
Complete
()
*
CompletedConfig
{
func
(
c
*
Config
)
Complete
()
*
CompletedConfig
{
cc
:=
completedConfig
{
cc
:=
completedConfig
{
c
}
c
.
Generic
.
Complete
(),
&
c
.
Extra
,
}
return
&
CompletedConfig
{
&
cc
}
return
&
CompletedConfig
{
&
cc
}
}
}
cmd/kube-controller-manager/app/controllermanager.go
View file @
f21475ac
...
@@ -108,7 +108,7 @@ controller, and serviceaccounts controller.`,
...
@@ -108,7 +108,7 @@ controller, and serviceaccounts controller.`,
func
ResyncPeriod
(
c
*
config
.
CompletedConfig
)
func
()
time
.
Duration
{
func
ResyncPeriod
(
c
*
config
.
CompletedConfig
)
func
()
time
.
Duration
{
return
func
()
time
.
Duration
{
return
func
()
time
.
Duration
{
factor
:=
rand
.
Float64
()
+
1
factor
:=
rand
.
Float64
()
+
1
return
time
.
Duration
(
float64
(
c
.
Generic
.
ComponentConfig
.
GenericComponent
.
MinResyncPeriod
.
Nanoseconds
())
*
factor
)
return
time
.
Duration
(
float64
(
c
.
ComponentConfig
.
GenericComponent
.
MinResyncPeriod
.
Nanoseconds
())
*
factor
)
}
}
}
}
...
@@ -118,43 +118,43 @@ func Run(c *config.CompletedConfig) error {
...
@@ -118,43 +118,43 @@ func Run(c *config.CompletedConfig) error {
glog
.
Infof
(
"Version: %+v"
,
version
.
Get
())
glog
.
Infof
(
"Version: %+v"
,
version
.
Get
())
if
cfgz
,
err
:=
configz
.
New
(
"componentconfig"
);
err
==
nil
{
if
cfgz
,
err
:=
configz
.
New
(
"componentconfig"
);
err
==
nil
{
cfgz
.
Set
(
c
.
Generic
.
ComponentConfig
)
cfgz
.
Set
(
c
.
ComponentConfig
)
}
else
{
}
else
{
glog
.
Errorf
(
"unable to register configz: %c"
,
err
)
glog
.
Errorf
(
"unable to register configz: %c"
,
err
)
}
}
// Start the controller manager HTTP server
// Start the controller manager HTTP server
stopCh
:=
make
(
chan
struct
{})
stopCh
:=
make
(
chan
struct
{})
if
c
.
Generic
.
SecureServing
!=
nil
{
if
c
.
SecureServing
!=
nil
{
handler
:=
genericcontrollermanager
.
NewBaseHandler
(
&
c
.
Generic
)
handler
:=
genericcontrollermanager
.
NewBaseHandler
(
&
c
.
ComponentConfig
.
Debugging
)
handler
=
genericcontrollermanager
.
BuildHandlerChain
(
handler
,
&
c
.
Generic
)
handler
=
genericcontrollermanager
.
BuildHandlerChain
(
handler
,
&
c
.
Authorization
,
&
c
.
Authentication
)
if
err
:=
c
.
Generic
.
SecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
if
err
:=
c
.
SecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
return
err
return
err
}
}
}
}
if
c
.
Generic
.
InsecureServing
!=
nil
{
if
c
.
InsecureServing
!=
nil
{
handler
:=
genericcontrollermanager
.
NewBaseHandler
(
&
c
.
Generic
)
handler
:=
genericcontrollermanager
.
NewBaseHandler
(
&
c
.
ComponentConfig
.
Debugging
)
handler
=
genericcontrollermanager
.
BuildHandlerChain
(
handler
,
&
c
.
Generic
)
handler
=
genericcontrollermanager
.
BuildHandlerChain
(
handler
,
&
c
.
Authorization
,
&
c
.
Authentication
)
if
err
:=
c
.
Generic
.
InsecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
if
err
:=
c
.
InsecureServing
.
Serve
(
handler
,
0
,
stopCh
);
err
!=
nil
{
return
err
return
err
}
}
}
}
run
:=
func
(
stop
<-
chan
struct
{})
{
run
:=
func
(
stop
<-
chan
struct
{})
{
rootClientBuilder
:=
controller
.
SimpleControllerClientBuilder
{
rootClientBuilder
:=
controller
.
SimpleControllerClientBuilder
{
ClientConfig
:
c
.
Generic
.
Kubeconfig
,
ClientConfig
:
c
.
Kubeconfig
,
}
}
var
clientBuilder
controller
.
ControllerClientBuilder
var
clientBuilder
controller
.
ControllerClientBuilder
if
c
.
Generic
.
ComponentConfig
.
KubeCloudShared
.
UseServiceAccountCredentials
{
if
c
.
ComponentConfig
.
KubeCloudShared
.
UseServiceAccountCredentials
{
if
len
(
c
.
Generic
.
ComponentConfig
.
KubeCloudShared
.
ServiceAccountKeyFile
)
==
0
{
if
len
(
c
.
ComponentConfig
.
KubeCloudShared
.
ServiceAccountKeyFile
)
==
0
{
// It'c possible another controller process is creating the tokens for us.
// It'c possible another controller process is creating the tokens for us.
// If one isn't, we'll timeout and exit when our client builder is unable to create the tokens.
// If one isn't, we'll timeout and exit when our client builder is unable to create the tokens.
glog
.
Warningf
(
"--use-service-account-credentials was specified without providing a --service-account-private-key-file"
)
glog
.
Warningf
(
"--use-service-account-credentials was specified without providing a --service-account-private-key-file"
)
}
}
clientBuilder
=
controller
.
SAControllerClientBuilder
{
clientBuilder
=
controller
.
SAControllerClientBuilder
{
ClientConfig
:
restclient
.
AnonymousClientConfig
(
c
.
Generic
.
Kubeconfig
),
ClientConfig
:
restclient
.
AnonymousClientConfig
(
c
.
Kubeconfig
),
CoreClient
:
c
.
Generic
.
Client
.
CoreV1
(),
CoreClient
:
c
.
Client
.
CoreV1
(),
AuthenticationClient
:
c
.
Generic
.
Client
.
AuthenticationV1
(),
AuthenticationClient
:
c
.
Client
.
AuthenticationV1
(),
Namespace
:
"kube-system"
,
Namespace
:
"kube-system"
,
}
}
}
else
{
}
else
{
...
@@ -176,7 +176,7 @@ func Run(c *config.CompletedConfig) error {
...
@@ -176,7 +176,7 @@ func Run(c *config.CompletedConfig) error {
select
{}
select
{}
}
}
if
!
c
.
Generic
.
ComponentConfig
.
GenericComponent
.
LeaderElection
.
LeaderElect
{
if
!
c
.
ComponentConfig
.
GenericComponent
.
LeaderElection
.
LeaderElect
{
run
(
wait
.
NeverStop
)
run
(
wait
.
NeverStop
)
panic
(
"unreachable"
)
panic
(
"unreachable"
)
}
}
...
@@ -188,13 +188,13 @@ func Run(c *config.CompletedConfig) error {
...
@@ -188,13 +188,13 @@ func Run(c *config.CompletedConfig) error {
// add a uniquifier so that two processes on the same host don't accidentally both become active
// add a uniquifier so that two processes on the same host don't accidentally both become active
id
=
id
+
"_"
+
string
(
uuid
.
NewUUID
())
id
=
id
+
"_"
+
string
(
uuid
.
NewUUID
())
rl
,
err
:=
resourcelock
.
New
(
c
.
Generic
.
ComponentConfig
.
GenericComponent
.
LeaderElection
.
ResourceLock
,
rl
,
err
:=
resourcelock
.
New
(
c
.
ComponentConfig
.
GenericComponent
.
LeaderElection
.
ResourceLock
,
"kube-system"
,
"kube-system"
,
"kube-controller-manager"
,
"kube-controller-manager"
,
c
.
Generic
.
LeaderElectionClient
.
CoreV1
(),
c
.
LeaderElectionClient
.
CoreV1
(),
resourcelock
.
ResourceLockConfig
{
resourcelock
.
ResourceLockConfig
{
Identity
:
id
,
Identity
:
id
,
EventRecorder
:
c
.
Generic
.
EventRecorder
,
EventRecorder
:
c
.
EventRecorder
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Fatalf
(
"error creating lock: %v"
,
err
)
glog
.
Fatalf
(
"error creating lock: %v"
,
err
)
...
@@ -202,9 +202,9 @@ func Run(c *config.CompletedConfig) error {
...
@@ -202,9 +202,9 @@ func Run(c *config.CompletedConfig) error {
leaderelection
.
RunOrDie
(
leaderelection
.
LeaderElectionConfig
{
leaderelection
.
RunOrDie
(
leaderelection
.
LeaderElectionConfig
{
Lock
:
rl
,
Lock
:
rl
,
LeaseDuration
:
c
.
Generic
.
ComponentConfig
.
GenericComponent
.
LeaderElection
.
LeaseDuration
.
Duration
,
LeaseDuration
:
c
.
ComponentConfig
.
GenericComponent
.
LeaderElection
.
LeaseDuration
.
Duration
,
RenewDeadline
:
c
.
Generic
.
ComponentConfig
.
GenericComponent
.
LeaderElection
.
RenewDeadline
.
Duration
,
RenewDeadline
:
c
.
ComponentConfig
.
GenericComponent
.
LeaderElection
.
RenewDeadline
.
Duration
,
RetryPeriod
:
c
.
Generic
.
ComponentConfig
.
GenericComponent
.
LeaderElection
.
RetryPeriod
.
Duration
,
RetryPeriod
:
c
.
ComponentConfig
.
GenericComponent
.
LeaderElection
.
RetryPeriod
.
Duration
,
Callbacks
:
leaderelection
.
LeaderCallbacks
{
Callbacks
:
leaderelection
.
LeaderCallbacks
{
OnStartedLeading
:
run
,
OnStartedLeading
:
run
,
OnStoppedLeading
:
func
()
{
OnStoppedLeading
:
func
()
{
...
@@ -409,8 +409,8 @@ func CreateControllerContext(s *config.CompletedConfig, rootClientBuilder, clien
...
@@ -409,8 +409,8 @@ func CreateControllerContext(s *config.CompletedConfig, rootClientBuilder, clien
return
ControllerContext
{},
err
return
ControllerContext
{},
err
}
}
cloud
,
loopMode
,
err
:=
createCloudProvider
(
s
.
Generic
.
ComponentConfig
.
CloudProvider
.
Name
,
s
.
Generic
.
ComponentConfig
.
ExternalCloudVolumePlugin
,
cloud
,
loopMode
,
err
:=
createCloudProvider
(
s
.
ComponentConfig
.
CloudProvider
.
Name
,
s
.
ComponentConfig
.
ExternalCloudVolumePlugin
,
s
.
Generic
.
ComponentConfig
.
CloudProvider
.
CloudConfigFile
,
s
.
Generic
.
ComponentConfig
.
KubeCloudShared
.
AllowUntaggedCloud
,
sharedInformers
)
s
.
ComponentConfig
.
CloudProvider
.
CloudConfigFile
,
s
.
ComponentConfig
.
KubeCloudShared
.
AllowUntaggedCloud
,
sharedInformers
)
if
err
!=
nil
{
if
err
!=
nil
{
return
ControllerContext
{},
err
return
ControllerContext
{},
err
}
}
...
@@ -418,7 +418,7 @@ func CreateControllerContext(s *config.CompletedConfig, rootClientBuilder, clien
...
@@ -418,7 +418,7 @@ func CreateControllerContext(s *config.CompletedConfig, rootClientBuilder, clien
ctx
:=
ControllerContext
{
ctx
:=
ControllerContext
{
ClientBuilder
:
clientBuilder
,
ClientBuilder
:
clientBuilder
,
InformerFactory
:
sharedInformers
,
InformerFactory
:
sharedInformers
,
ComponentConfig
:
s
.
Generic
.
ComponentConfig
,
ComponentConfig
:
s
.
ComponentConfig
,
RESTMapper
:
restMapper
,
RESTMapper
:
restMapper
,
AvailableResources
:
availableResources
,
AvailableResources
:
availableResources
,
Cloud
:
cloud
,
Cloud
:
cloud
,
...
...
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