From 3786cfdf855b46044a33de5622452825ad86816b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Tyczy=C5=84ski?= Date: Wed, 26 Oct 2022 16:15:22 +0200 Subject: [PATCH] Clean shutdown of serving integration test --- cmd/kube-scheduler/app/options/options.go | 22 +++++++++-------- .../k8s.io/cloud-provider/options/options.go | 24 +++++++++++-------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/cmd/kube-scheduler/app/options/options.go b/cmd/kube-scheduler/app/options/options.go index 6a5b2a1c131..dfc7ce86300 100644 --- a/cmd/kube-scheduler/app/options/options.go +++ b/cmd/kube-scheduler/app/options/options.go @@ -222,6 +222,15 @@ func (o *Options) ApplyTo(c *schedulerappconfig.Config) error { c.ComponentConfig = *cfg } + // Build kubeconfig first to so that if it fails, it doesn't cause leaking + // goroutines (started from initializing secure serving - which underneath + // creates a queue which in its constructor starts a goroutine). + kubeConfig, err := createKubeConfig(c.ComponentConfig.ClientConnection, o.Master) + if err != nil { + return err + } + c.KubeConfig = kubeConfig + if err := o.SecureServing.ApplyTo(&c.SecureServing, &c.LoopbackClientConfig); err != nil { return err } @@ -271,14 +280,8 @@ func (o *Options) Config() (*schedulerappconfig.Config, error) { return nil, err } - // Prepare kube config. - kubeConfig, err := createKubeConfig(c.ComponentConfig.ClientConnection, o.Master) - if err != nil { - return nil, err - } - // Prepare kube clients. - client, eventClient, err := createClients(kubeConfig) + client, eventClient, err := createClients(c.KubeConfig) if err != nil { return nil, err } @@ -294,16 +297,15 @@ func (o *Options) Config() (*schedulerappconfig.Config, error) { schedulerName = c.ComponentConfig.Profiles[0].SchedulerName } coreRecorder := c.EventBroadcaster.DeprecatedNewLegacyRecorder(schedulerName) - leaderElectionConfig, err = makeLeaderElectionConfig(c.ComponentConfig.LeaderElection, kubeConfig, coreRecorder) + leaderElectionConfig, err = makeLeaderElectionConfig(c.ComponentConfig.LeaderElection, c.KubeConfig, coreRecorder) if err != nil { return nil, err } } c.Client = client - c.KubeConfig = kubeConfig c.InformerFactory = scheduler.NewInformerFactory(client, 0) - dynClient := dynamic.NewForConfigOrDie(kubeConfig) + dynClient := dynamic.NewForConfigOrDie(c.KubeConfig) c.DynInformerFactory = dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynClient, 0, corev1.NamespaceAll, nil) c.LeaderElection = leaderElectionConfig diff --git a/staging/src/k8s.io/cloud-provider/options/options.go b/staging/src/k8s.io/cloud-provider/options/options.go index 7c29fa39574..6dcfa233a28 100644 --- a/staging/src/k8s.io/cloud-provider/options/options.go +++ b/staging/src/k8s.io/cloud-provider/options/options.go @@ -138,6 +138,20 @@ func (o *CloudControllerManagerOptions) Flags(allControllers, disabledByDefaultC // ApplyTo fills up cloud controller manager config with options. func (o *CloudControllerManagerOptions) ApplyTo(c *config.Config, userAgent string) error { var err error + + // Build kubeconfig first to so that if it fails, it doesn't cause leaking + // goroutines (started from initializing secure serving - which underneath + // creates a queue which in its constructor starts a goroutine). + c.Kubeconfig, err = clientcmd.BuildConfigFromFlags(o.Master, o.Kubeconfig) + if err != nil { + return err + } + c.Kubeconfig.DisableCompression = true + c.Kubeconfig.ContentConfig.AcceptContentTypes = o.Generic.ClientConnection.AcceptContentTypes + c.Kubeconfig.ContentConfig.ContentType = o.Generic.ClientConnection.ContentType + c.Kubeconfig.QPS = o.Generic.ClientConnection.QPS + c.Kubeconfig.Burst = int(o.Generic.ClientConnection.Burst) + if err = o.Generic.ApplyTo(&c.ComponentConfig.Generic); err != nil { return err } @@ -159,16 +173,6 @@ func (o *CloudControllerManagerOptions) ApplyTo(c *config.Config, userAgent stri } } - c.Kubeconfig, err = clientcmd.BuildConfigFromFlags(o.Master, o.Kubeconfig) - if err != nil { - return err - } - c.Kubeconfig.DisableCompression = true - c.Kubeconfig.ContentConfig.AcceptContentTypes = o.Generic.ClientConnection.AcceptContentTypes - c.Kubeconfig.ContentConfig.ContentType = o.Generic.ClientConnection.ContentType - c.Kubeconfig.QPS = o.Generic.ClientConnection.QPS - c.Kubeconfig.Burst = int(o.Generic.ClientConnection.Burst) - c.Client, err = clientset.NewForConfig(restclient.AddUserAgent(c.Kubeconfig, userAgent)) if err != nil { return err