mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-29 21:29:24 +00:00
Merge pull request #125661 from mjudeikis/mjudeikis/poststarthookctx.stopch.cleanup
Clean deprecated context.StopCh
This commit is contained in:
@@ -26,7 +26,6 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
apiserverfeatures "k8s.io/apiserver/pkg/features"
|
||||
peerreconcilers "k8s.io/apiserver/pkg/reconcilers"
|
||||
genericregistry "k8s.io/apiserver/pkg/registry/generic"
|
||||
@@ -136,7 +135,7 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele
|
||||
}
|
||||
if len(c.SystemNamespaces) > 0 {
|
||||
s.GenericAPIServer.AddPostStartHookOrDie("start-system-namespaces-controller", func(hookContext genericapiserver.PostStartHookContext) error {
|
||||
go systemnamespaces.NewController(c.SystemNamespaces, client, s.VersionedInformers.Core().V1().Namespaces()).Run(hookContext.StopCh)
|
||||
go systemnamespaces.NewController(c.SystemNamespaces, client, s.VersionedInformers.Core().V1().Namespaces()).Run(hookContext.Done())
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -156,7 +155,7 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele
|
||||
client)
|
||||
s.GenericAPIServer.AddPostStartHookOrDie("peer-endpoint-reconciler-controller",
|
||||
func(hookContext genericapiserver.PostStartHookContext) error {
|
||||
peerEndpointCtrl.Start(hookContext.StopCh)
|
||||
peerEndpointCtrl.Start(hookContext.Done())
|
||||
return nil
|
||||
})
|
||||
s.GenericAPIServer.AddPreShutdownHookOrDie("peer-endpoint-reconciler-controller",
|
||||
@@ -166,7 +165,7 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele
|
||||
})
|
||||
if c.Extra.PeerProxy != nil {
|
||||
s.GenericAPIServer.AddPostStartHookOrDie("unknown-version-proxy-filter", func(context genericapiserver.PostStartHookContext) error {
|
||||
err := c.Extra.PeerProxy.WaitForCacheSync(context.StopCh)
|
||||
err := c.Extra.PeerProxy.WaitForCacheSync(context.Done())
|
||||
return err
|
||||
})
|
||||
}
|
||||
@@ -174,43 +173,34 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele
|
||||
|
||||
s.GenericAPIServer.AddPostStartHookOrDie("start-cluster-authentication-info-controller", func(hookContext genericapiserver.PostStartHookContext) error {
|
||||
controller := clusterauthenticationtrust.NewClusterAuthenticationTrustController(s.ClusterAuthenticationInfo, client)
|
||||
|
||||
// generate a context from stopCh. This is to avoid modifying files which are relying on apiserver
|
||||
// TODO: See if we can pass ctx to the current method
|
||||
ctx := wait.ContextForChannel(hookContext.StopCh)
|
||||
|
||||
// prime values and start listeners
|
||||
if s.ClusterAuthenticationInfo.ClientCA != nil {
|
||||
s.ClusterAuthenticationInfo.ClientCA.AddListener(controller)
|
||||
if controller, ok := s.ClusterAuthenticationInfo.ClientCA.(dynamiccertificates.ControllerRunner); ok {
|
||||
// runonce to be sure that we have a value.
|
||||
if err := controller.RunOnce(ctx); err != nil {
|
||||
if err := controller.RunOnce(hookContext); err != nil {
|
||||
runtime.HandleError(err)
|
||||
}
|
||||
go controller.Run(ctx, 1)
|
||||
go controller.Run(hookContext, 1)
|
||||
}
|
||||
}
|
||||
if s.ClusterAuthenticationInfo.RequestHeaderCA != nil {
|
||||
s.ClusterAuthenticationInfo.RequestHeaderCA.AddListener(controller)
|
||||
if controller, ok := s.ClusterAuthenticationInfo.RequestHeaderCA.(dynamiccertificates.ControllerRunner); ok {
|
||||
// runonce to be sure that we have a value.
|
||||
if err := controller.RunOnce(ctx); err != nil {
|
||||
if err := controller.RunOnce(hookContext); err != nil {
|
||||
runtime.HandleError(err)
|
||||
}
|
||||
go controller.Run(ctx, 1)
|
||||
go controller.Run(hookContext, 1)
|
||||
}
|
||||
}
|
||||
|
||||
go controller.Run(ctx, 1)
|
||||
go controller.Run(hookContext, 1)
|
||||
return nil
|
||||
})
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(apiserverfeatures.APIServerIdentity) {
|
||||
s.GenericAPIServer.AddPostStartHookOrDie("start-kube-apiserver-identity-lease-controller", func(hookContext genericapiserver.PostStartHookContext) error {
|
||||
// generate a context from stopCh. This is to avoid modifying files which are relying on apiserver
|
||||
// TODO: See if we can pass ctx to the current method
|
||||
ctx := wait.ContextForChannel(hookContext.StopCh)
|
||||
|
||||
leaseName := s.GenericAPIServer.APIServerID
|
||||
holderIdentity := s.GenericAPIServer.APIServerID + "_" + string(uuid.NewUUID())
|
||||
|
||||
@@ -227,7 +217,7 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele
|
||||
metav1.NamespaceSystem,
|
||||
// TODO: receive identity label value as a parameter when post start hook is moved to generic apiserver.
|
||||
labelAPIServerHeartbeatFunc(name, peeraddress))
|
||||
go controller.Run(ctx)
|
||||
go controller.Run(hookContext)
|
||||
return nil
|
||||
})
|
||||
// TODO: move this into generic apiserver and make the lease identity value configurable
|
||||
@@ -237,7 +227,7 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele
|
||||
IdentityLeaseGCPeriod,
|
||||
metav1.NamespaceSystem,
|
||||
IdentityLeaseComponentLabelKey+"="+name,
|
||||
).Run(hookContext.StopCh)
|
||||
).Run(hookContext.Done())
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -247,7 +237,7 @@ func (c completedConfig) New(name string, delegationTarget genericapiserver.Dele
|
||||
}
|
||||
|
||||
s.GenericAPIServer.AddPostStartHookOrDie("start-legacy-token-tracking-controller", func(hookContext genericapiserver.PostStartHookContext) error {
|
||||
go legacytokentracking.NewController(client).Run(hookContext.StopCh)
|
||||
go legacytokentracking.NewController(client).Run(hookContext.Done())
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -349,7 +349,7 @@ func (c CompletedConfig) New(delegationTarget genericapiserver.DelegationTarget)
|
||||
KubernetesServiceNodePort: c.Extra.KubernetesServiceNodePort,
|
||||
}, client, c.ControlPlane.Extra.VersionedInformers.Core().V1().Services())
|
||||
s.ControlPlane.GenericAPIServer.AddPostStartHookOrDie("bootstrap-controller", func(hookContext genericapiserver.PostStartHookContext) error {
|
||||
kubernetesServiceCtrl.Start(hookContext.StopCh)
|
||||
kubernetesServiceCtrl.Start(hookContext.Done())
|
||||
return nil
|
||||
})
|
||||
s.ControlPlane.GenericAPIServer.AddPreShutdownHookOrDie("stop-kubernetes-service-controller", func() error {
|
||||
|
||||
@@ -514,7 +514,7 @@ func (p *legacyProvider) PostStartHook() (string, genericapiserver.PostStartHook
|
||||
runner.Start()
|
||||
go func() {
|
||||
defer runner.Stop()
|
||||
<-context.StopCh
|
||||
<-context.Done()
|
||||
}()
|
||||
|
||||
// For backward compatibility, we ensure that if we never are able
|
||||
|
||||
@@ -145,7 +145,7 @@ func (bce *bootstrapConfigurationEnsurer) ensureAPFBootstrapConfiguration(hookCo
|
||||
err = func() error {
|
||||
// get a derived context that gets cancelled after 5m or
|
||||
// when the StopCh gets closed, whichever happens first.
|
||||
ctx, cancel := contextFromChannelAndMaxWaitDuration(hookContext.StopCh, 5*time.Minute)
|
||||
ctx, cancel := contextFromChannelAndMaxWaitDuration(hookContext.Done(), 5*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
if !cache.WaitForCacheSync(ctx.Done(), bce.informersSynced...) {
|
||||
@@ -174,16 +174,15 @@ func (bce *bootstrapConfigurationEnsurer) ensureAPFBootstrapConfiguration(hookCo
|
||||
// we have successfully initialized the bootstrap configuration, now we
|
||||
// spin up a goroutine which reconciles the bootstrap configuration periodically.
|
||||
go func() {
|
||||
ctx := wait.ContextForChannel(hookContext.StopCh)
|
||||
wait.PollImmediateUntil(
|
||||
time.Minute,
|
||||
func() (bool, error) {
|
||||
if err := ensure(ctx, clientset, bce.fsLister, bce.plcLister); err != nil {
|
||||
if err := ensure(hookContext, clientset, bce.fsLister, bce.plcLister); err != nil {
|
||||
klog.ErrorS(err, "APF bootstrap ensurer ran into error, will retry later")
|
||||
}
|
||||
// always auto update both suggested and mandatory configuration
|
||||
return false, nil
|
||||
}, hookContext.StopCh)
|
||||
}, hookContext.Done())
|
||||
klog.Info("APF bootstrap ensurer is exiting")
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user