Skip to content

Commit

Permalink
allow configuring enabled and disabled openshift controllerS
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Dec 15, 2017
1 parent b7120a8 commit a5743a7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 3 deletions.
8 changes: 8 additions & 0 deletions pkg/cmd/server/api/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ func fuzzInternalObject(t *testing.T, forVersion schema.GroupVersion, item runti
if len(obj.Controllers) == 0 {
obj.Controllers = configapi.ControllersAll
}
if len(obj.ControllerConfig.Controllers) == 0 {
switch {
case obj.Controllers == configapi.ControllersAll:
obj.ControllerConfig.Controllers = []string{"*"}
case obj.Controllers == configapi.ControllersDisabled:
obj.ControllerConfig.Controllers = []string{}
}
}
if election := obj.ControllerConfig.Election; election != nil {
if len(election.LockNamespace) == 0 {
election.LockNamespace = "kube-system"
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/server/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1519,6 +1519,10 @@ type AdmissionConfig struct {

// ControllerConfig holds configuration values for controllers
type ControllerConfig struct {
// Controllers is a list of controllers to enable. '*' enables all on-by-default controllers, 'foo' enables the controller "+
// named 'foo', '-foo' disables the controller named 'foo'.
// Defaults to "*".
Controllers []string
// Election defines the configuration for electing a controller instance to make changes to
// the cluster. If unspecified, the ControllerTTL value is checked to determine whether the
// legacy direct etcd election code will be used.
Expand Down
10 changes: 10 additions & 0 deletions pkg/cmd/server/api/v1/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func SetDefaults_MasterConfig(obj *MasterConfig) {
if len(obj.Controllers) == 0 {
obj.Controllers = ControllersAll
}
if len(obj.ControllerConfig.Controllers) == 0 {
switch {
case obj.Controllers == ControllersAll:
obj.ControllerConfig.Controllers = []string{"*"}
case obj.Controllers == ControllersDisabled:
obj.ControllerConfig.Controllers = []string{}
}
}
if election := obj.ControllerConfig.Election; election != nil {
if len(election.LockNamespace) == 0 {
election.LockNamespace = "kube-system"
Expand All @@ -30,6 +38,7 @@ func SetDefaults_MasterConfig(obj *MasterConfig) {
election.LockResource.Resource = "configmaps"
}
}

if obj.ServingInfo.RequestTimeoutSeconds == 0 {
obj.ServingInfo.RequestTimeoutSeconds = 60 * 60
}
Expand Down Expand Up @@ -194,6 +203,7 @@ func SetDefaults_EtcdStorageConfig(obj *EtcdStorageConfig) {
obj.OpenShiftStoragePrefix = "openshift.io"
}
}

func SetDefaults_DockerConfig(obj *DockerConfig) {
if len(obj.ExecHandlerName) == 0 {
obj.ExecHandlerName = DockerExecHandlerNative
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/server/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,10 @@ type AdmissionConfig struct {

// ControllerConfig holds configuration values for controllers
type ControllerConfig struct {
// Controllers is a list of controllers to enable. '*' enables all on-by-default controllers, 'foo' enables the controller "+
// named 'foo', '-foo' disables the controller named 'foo'.
// Defaults to "*".
Controllers []string `json:"controllers"`
// Election defines the configuration for electing a controller instance to make changes to
// the cluster. If unspecified, the ControllerTTL value is checked to determine whether the
// legacy direct etcd election code will be used.
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/server/api/v1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ auditConfig:
authConfig:
requestHeader: null
controllerConfig:
controllers: null
election: null
serviceServingCert:
signer: null
Expand Down
7 changes: 5 additions & 2 deletions pkg/cmd/server/origin/controller/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
kexternalinformers "k8s.io/client-go/informers"
controllerapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
kclientsetinternal "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
kinternalinformers "k8s.io/kubernetes/pkg/client/informers/informers_generated/internalversion"
"k8s.io/kubernetes/pkg/controller"
Expand All @@ -29,6 +31,8 @@ import (
type ControllerContext struct {
OpenshiftControllerOptions OpenshiftControllerOptions

EnabledControllers []string

// ClientBuilder will provide a client for this controller to use
ClientBuilder ControllerClientBuilder

Expand Down Expand Up @@ -74,9 +78,8 @@ type ServiceAccountTokenOptions struct {
ConcurrentSyncs int32
}

// TODO wire this up to something that handles the names. The logic is available upstream, we just have to wire to it
func (c ControllerContext) IsControllerEnabled(name string) bool {
return true
return controllerapp.IsControllerEnabled(name, sets.String{}, c.EnabledControllers...)
}

type ControllerClientBuilder interface {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/server/start/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

func newControllerContext(
openshiftControllerOptions origincontrollers.OpenshiftControllerOptions,
enabledControllers []string,
privilegedLoopbackConfig *rest.Config,
kubeExternal kclientsetexternal.Interface,
informers *informers,
Expand All @@ -42,6 +43,7 @@ func newControllerContext(

openshiftControllerContext := origincontrollers.ControllerContext{
OpenshiftControllerOptions: openshiftControllerOptions,
EnabledControllers: enabledControllers,

ClientBuilder: origincontrollers.OpenshiftControllerClientBuilder{
ControllerClientBuilder: controller.SAControllerClientBuilder{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/start/start_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (m *Master) Start() error {
glog.Fatal(err)
}

controllerContext := newControllerContext(openshiftControllerOptions, privilegedLoopbackConfig, kubeExternal, openshiftControllerInformers, utilwait.NeverStop, make(chan struct{}))
controllerContext := newControllerContext(openshiftControllerOptions, m.config.ControllerConfig.Controllers, privilegedLoopbackConfig, kubeExternal, openshiftControllerInformers, utilwait.NeverStop, make(chan struct{}))
if err := startControllers(*m.config, allocationController, controllerContext); err != nil {
glog.Fatal(err)
}
Expand Down

0 comments on commit a5743a7

Please sign in to comment.