diff --git a/pkg/registration/spoke/spokeagent.go b/pkg/registration/spoke/spokeagent.go index 5b9cfeeb9..2a7da44ee 100644 --- a/pkg/registration/spoke/spokeagent.go +++ b/pkg/registration/spoke/spokeagent.go @@ -359,7 +359,10 @@ func (o *SpokeAgentConfig) RunSpokeAgentWithSpokeInformers(ctx context.Context, if err := wait.PollUntilContextCancel(bootstrapCtx, 1*time.Second, true, o.internalHubConfigValidFunc); err != nil { // TODO need run the bootstrap CSR forever to re-establish the client-cert if it is ever lost. stopBootstrap() - return fmt.Errorf("failed to wait for hub client config for managed cluster to be ready: %w", err) + // DO NOT return error if context canceled, allows leader election to release the leadership. + if err != context.Canceled { + return fmt.Errorf("failed to wait for hub client config for managed cluster to be ready: %w", err) + } } // stop the clientCertForHubController for bootstrap once the hub client config is ready diff --git a/pkg/singleton/spoke/agent.go b/pkg/singleton/spoke/agent.go index c0c0e81df..3ede7e678 100644 --- a/pkg/singleton/spoke/agent.go +++ b/pkg/singleton/spoke/agent.go @@ -42,7 +42,10 @@ func (a *AgentConfig) RunSpokeAgent(ctx context.Context, controllerContext *cont // wait for the hub client config ready. klog.Info("Waiting for hub client config and managed cluster to be ready") if err := wait.PollUntilContextCancel(ctx, 1*time.Second, true, a.registrationConfig.IsHubKubeConfigValid); err != nil { - return err + // DO NOT return error if context canceled, allows leader election to release the leadership. + if err != context.Canceled { + return err + } } // start work agent