{"id":20670474,"url":"https://github.com/caicloud/leader-election-example","last_synced_at":"2025-11-10T02:03:30.086Z","repository":{"id":75261693,"uuid":"213858316","full_name":"caicloud/leader-election-example","owner":"caicloud","description":"This example demonstrates how to write high availability controller with GO.","archived":false,"fork":false,"pushed_at":"2023-02-24T17:27:48.000Z","size":7708,"stargazers_count":10,"open_issues_count":1,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T11:34:40.767Z","etag":null,"topics":["controller","example","golang","kubernetes","leader-election"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caicloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-09T08:06:47.000Z","updated_at":"2024-05-21T05:14:27.000Z","dependencies_parsed_at":"2023-06-05T22:33:39.989Z","dependency_job_id":null,"html_url":"https://github.com/caicloud/leader-election-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":"caicloud/common-template-project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caicloud%2Fleader-election-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caicloud%2Fleader-election-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caicloud%2Fleader-election-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caicloud%2Fleader-election-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caicloud","download_url":"https://codeload.github.com/caicloud/leader-election-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249762269,"owners_count":21321903,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["controller","example","golang","kubernetes","leader-election"],"created_at":"2024-11-16T20:20:45.086Z","updated_at":"2025-11-10T02:03:29.979Z","avatar_url":"https://github.com/caicloud.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n- [Leader Election Example](#leader-election-example)\n  - [Running](#running)\n  - [Health Check](#health-check)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n# Leader Election Example\n\nThis example demonstrates how to use the leader election package.\n\n## Running\n\nRun the following three commands in separate terminals.\n\n```bash\n# first terminal\ngo run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=0 -port=8080\n\n# second terminal\ngo run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=1 -port=8081\n\n# third terminal\ngo run main.go -kubeconfig=/path/to/kubeconfig -logtostderr=true -lease-lock-name=example -lease-lock-namespace=default -id=2 -port=8082\n```\n\n\u003e You can ignore the `-kubeconfig` flag if you are running these commands in the Kubernetes cluster.\n\nNow kill the existing leader. You will see from the terminal outputs that one of the remaining two processes will be elected as the new leader.\n\n## Health Check\n\n```bash\n$ curl -i localhost:8080/healthz\nHTTP/1.1 200 OK\nContent-Type: text/plain; charset=utf-8\nX-Content-Type-Options: nosniff\nDate: Thu, 19 Sep 2019 10:44:39 GMT\nContent-Length: 2\n\nok%\n\n$ curl -i localhost:8080/healthz/leaderElection\nHTTP/1.1 200 OK\nDate: Thu, 19 Sep 2019 10:44:31 GMT\nContent-Length: 2\nContent-Type: text/plain; charset=utf-8\n\nok%\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaicloud%2Fleader-election-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaicloud%2Fleader-election-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaicloud%2Fleader-election-example/lists"}