Skip to content

leader-election support multi cluster #1817

Closed

Description

@hkmdxlftjf

Bug Report

What did you do?

an instance watch multi-cluster event, but only one election

What did you expect to see?

https://github.com/java-operator-sdk/java-operator-sdk/blob/3812a7fe73f81033d87297afd3081a93760a7abd/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java#L76
can support custom kubernetes-client

Activity

  1. csviri commented on Mar 14, 2023

    @csviri
    Collaborator

    Hi @hkmdxlftjf , I'm not sure I uderstand what are you asking for, could you describe your use case?

  2. hkmdxlftjf commented on Mar 14, 2023

    @hkmdxlftjf
    Author

    we have multi k8s clusters, I want to deploy the operator on a cluster and namespace is xxxx, watch all cluster cr events,
    eg:
    Map<String, Operator> clusterWithOperator = new HashMap<>();
    when isLeaderElectionEnabled is true, new Operator() will create lease on a different cluster,expect to create a lease only on the deployed cluster, or i can specify the cluster(kubernetes client)

  3. self-assigned this
    on Mar 14, 2023
  4. csviri commented on Mar 14, 2023

    @csviri
    Collaborator

    Ok, so currently you can do this just not using the leader election capabilities of the JOSDK, and just setup leader election with fabric8 client, and start the operators if becomes the leader.
    The downside is that the non-leader operator does prepares the caches, so when one them becomes the leader it might take some time until the resources are processed on startup on large clusters.

    So if I understand the problem what you asking for is to be able to specify the client for leader election.
    Will have to take a look because this not necessarily will solve the problem. Since you will have multiple operators competing for the lease, even if they have the same ID (in terms of leader election), this might not work. Will have to think about it / check it.

  5. added this to the 4.4 milestone on Mar 14, 2023
  6. hkmdxlftjf commented on Mar 14, 2023

    @hkmdxlftjf
    Author

    can i try add attributein leaderelectionconfiguration(KubernetesClient client), and provide a method to use modify this attribute

  7. csviri commented on Mar 14, 2023

    @csviri
    Collaborator

    You are always free to create a pull request, and we can take a look. But would require a test for this, pls see current leader election tests.

    I will also take a look on the implementation of the leader election, since there might be conceptual issue with this approach. Since in this case it is more like about having multiple leaders instead of one with same identity and the leader election was not designed for this, so it anyways feels like a hack to me. (But will try the best to support your use case).

    cc @shawkins

  8. csviri commented on Mar 15, 2023

    @csviri
    Collaborator

    Will take a look but I think the proper solution here is to share the LeaderElector between multiple controllers, not create LeaderElector for each Operator with the same client. Will take a look how feasible is this to implement.

  9. csviri commented on Mar 15, 2023

    @csviri
    Collaborator

    @hkmdxlftjf Also note that leader election does not give you that much, so if pod crashes and restarts is good enough in most of cases.

  10. csviri commented on Apr 3, 2023

    @csviri
    Collaborator

    @hkmdxlftjf can we close this issue too?

  11. hkmdxlftjf commented on Apr 3, 2023

    @hkmdxlftjf
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions