From 4ce220beb63eacad4a4445bfe29ff5140c51750d Mon Sep 17 00:00:00 2001 From: Michal Fojtik Date: Wed, 1 Nov 2017 10:31:00 +0100 Subject: [PATCH] Bug 1508061: Fix panic during openshift controller options initialization --- .../start/start_kube_controller_manager.go | 28 ++++++++++--------- pkg/cmd/server/start/start_master.go | 5 +++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/pkg/cmd/server/start/start_kube_controller_manager.go b/pkg/cmd/server/start/start_kube_controller_manager.go index f45e70a1f997..59e1a70f9c49 100644 --- a/pkg/cmd/server/start/start_kube_controller_manager.go +++ b/pkg/cmd/server/start/start_kube_controller_manager.go @@ -216,15 +216,7 @@ func createRecylerTemplate(recyclerImage string) (string, error) { return filename, nil } -func runEmbeddedKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCAFile, podEvictionTimeout string, dynamicProvisioningEnabled bool, cmdLineArgs map[string][]string, - recyclerImage string, informers *informers) { - controllerapp.CreateControllerContext = newKubeControllerContext(informers) - controllerapp.StartInformers = func(stop <-chan struct{}) { - informers.Start(stop) - } - - // TODO we need a real identity for this. Right now it's just using the loopback connection like it used to. - controllerManager, cleanupFunctions, err := newKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCAFile, podEvictionTimeout, recyclerImage, dynamicProvisioningEnabled, cmdLineArgs) +func runEmbeddedKubeControllerManager(controllerManager *controlleroptions.CMServer, cleanupFunctions []func()) { defer func() { // Clean up any temporary files and similar stuff. // TODO: Make sure this defer is actually called - controllerapp.Run() @@ -233,10 +225,6 @@ func runEmbeddedKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCA f() } }() - - if err != nil { - glog.Fatal(err) - } // this does a second leader election, but doing the second leader election will allow us to move out process in // 3.8 if we so choose. if err := controllerapp.Run(controllerManager); err != nil { @@ -244,6 +232,20 @@ func runEmbeddedKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCA } } +func setupEmbeddedKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCAFile, podEvictionTimeout string, dynamicProvisioningEnabled bool, cmdLineArgs map[string][]string, + recyclerImage string, informers *informers) (*controlleroptions.CMServer, []func()) { + controllerapp.CreateControllerContext = newKubeControllerContext(informers) + controllerapp.StartInformers = func(stop <-chan struct{}) { + informers.Start(stop) + } + // TODO we need a real identity for this. Right now it's just using the loopback connection like it used to. + controllerManager, cleanupFunctions, err := newKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCAFile, podEvictionTimeout, recyclerImage, dynamicProvisioningEnabled, cmdLineArgs) + if err != nil { + glog.Fatal(err) + } + return controllerManager, cleanupFunctions +} + type GenericResourceInformer interface { ForResource(resource schema.GroupVersionResource) (kinformers.GenericInformer, error) } diff --git a/pkg/cmd/server/start/start_master.go b/pkg/cmd/server/start/start_master.go index 387b39a94e16..8600fd490920 100644 --- a/pkg/cmd/server/start/start_master.go +++ b/pkg/cmd/server/start/start_master.go @@ -475,7 +475,8 @@ func (m *Master) Start() error { // continuously run the scheduler while we have the primary lease go runEmbeddedScheduler(m.config.MasterClients.OpenShiftLoopbackKubeConfig, m.config.KubernetesMasterConfig.SchedulerConfigFile, m.config.KubernetesMasterConfig.SchedulerArguments) - go runEmbeddedKubeControllerManager( + // this mutates the ControllerArguments + controllerManager, cleanupFunctions := setupEmbeddedKubeControllerManager( m.config.MasterClients.OpenShiftLoopbackKubeConfig, m.config.ServiceAccountConfig.PrivateKeyFile, m.config.ServiceAccountConfig.MasterCA, @@ -485,6 +486,8 @@ func (m *Master) Start() error { recyclerImage, informers) + go runEmbeddedKubeControllerManager(controllerManager, cleanupFunctions) + openshiftControllerOptions, err := getOpenshiftControllerOptions(m.config.KubernetesMasterConfig.ControllerArguments) if err != nil { glog.Fatal(err)