Skip to content

LeaderElector does not write logs or exceptions during failure #1390

Closed
@vrnmthr

Description

@vrnmthr

Describe the bug
I was using the LeaderElector with a LeaseLock, but failed to set RBAC on my app to create/read leases (this is not present in the default service account). This means that this piece of code was failing, probably with a different HttpStatusCode. The end result is that the LeaderElector basically "does nothing" infinitely, with no logs and no exception thrown.

LeaderElectionRecord oldLeaderElectionRecord = null;
            try
            {
                oldLeaderElectionRecord = await l.GetAsync(cancellationToken).ConfigureAwait(false);
            }
            catch (HttpOperationException e)
            {
                if (e.Response.StatusCode != HttpStatusCode.NotFound)
                {
                    return false;
                }
            }

This is not intuitive behavior, and since there is no documentation for this that includes how to setup RBAC, it makes debugging issues difficult.

Kubernetes C# SDK Client Version
11.0.44

Server Kubernetes Version
e.g. 1.21

Dotnet Runtime Version
net6

To Reproduce
Start leader elector without required RBAC in a cluster

Expected behavior
Either log error, or throw exception

KubeConfig
If applicable, add a KubeConfig file with secrets redacted.

Where do you run your app with Kubernetes SDK (please complete the following information):

  • OS: Linux
  • Environment: Container
  • Cloud: Azure

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions