From dfbd95fb6e95199a90428b110af3e77b4b7d6f33 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 --- pkg/cmd/server/start/start_kube_controller_manager.go | 5 ++++- pkg/cmd/server/start/start_master.go | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/server/start/start_kube_controller_manager.go b/pkg/cmd/server/start/start_kube_controller_manager.go index f45e70a1f997..31be0e3399f0 100644 --- a/pkg/cmd/server/start/start_kube_controller_manager.go +++ b/pkg/cmd/server/start/start_kube_controller_manager.go @@ -217,7 +217,7 @@ func createRecylerTemplate(recyclerImage string) (string, error) { } func runEmbeddedKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCAFile, podEvictionTimeout string, dynamicProvisioningEnabled bool, cmdLineArgs map[string][]string, - recyclerImage string, informers *informers) { + initialized chan struct{}, recyclerImage string, informers *informers) { controllerapp.CreateControllerContext = newKubeControllerContext(informers) controllerapp.StartInformers = func(stop <-chan struct{}) { informers.Start(stop) @@ -233,6 +233,9 @@ func runEmbeddedKubeControllerManager(kubeconfigFile, saPrivateKeyFile, saRootCA f() } }() + // At this point do not mutate cmdLineArgs and signal this back to upper + // level. + close(initialized) if err != nil { glog.Fatal(err) diff --git a/pkg/cmd/server/start/start_master.go b/pkg/cmd/server/start/start_master.go index 387b39a94e16..9690ef5f2ee0 100644 --- a/pkg/cmd/server/start/start_master.go +++ b/pkg/cmd/server/start/start_master.go @@ -475,6 +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) + controllerArgumentsInitialized := make(chan struct{}) + go runEmbeddedKubeControllerManager( m.config.MasterClients.OpenShiftLoopbackKubeConfig, m.config.ServiceAccountConfig.PrivateKeyFile, @@ -482,9 +484,14 @@ func (m *Master) Start() error { m.config.KubernetesMasterConfig.PodEvictionTimeout, m.config.VolumeConfig.DynamicProvisioningEnabled, m.config.KubernetesMasterConfig.ControllerArguments, + controllerArgumentsInitialized, recyclerImage, informers) + // Wait for the runEmbeddedKubeControllerManager to mutate the + // ControllerArguments to prevent getOpenshiftControllerOptions from + // panicking because of concurrent read/write access. + <-controllerArgumentsInitialized openshiftControllerOptions, err := getOpenshiftControllerOptions(m.config.KubernetesMasterConfig.ControllerArguments) if err != nil { glog.Fatal(err)