kubebuilder
kubebuilder copied to clipboard
:bug: Add leader election namespace to fix manager start error
Fixes #3016
On generated code main.go L57, just set leader-election to true:
flag.BoolVar(&enableLeaderElection, "leader-elect", true, ...
Then make run will got error:
go run ./main.go
1.665666448465308e+09 ERROR setup unable to start manager {"error": "unable to find leader election namespace: not running in-cluster, please specify LeaderElectionNamespace"}
main.main
This PR is to add leader election namespace to fix this issue. Plugins go/v3 and go/v4-alpha are updated.
Hi @astraw99. Thanks for your PR.
I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.
Once the patch is verified, the new status will be reflected by the ok-to-test label.
I understand the commands that are listed here.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
/ok-to-test
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: astraw99
Once this PR has been reviewed and has the lgtm label, please assign camilamacedo86 for approval by writing /assign @camilamacedo86 in a comment. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
/hold
These changes have broken the projects and are not passing in the e2e tests.
<*errors.errorString | 0xc000186030>: { s: "kubebuilder init --plugins go/v3 --project-version 3 --domain example.comjxud failed with error: (exit status 1) Writing kustomize manifests for you to edit...\nWriting scaffold for you to edit...\nError: failed to initialize project: unable to scaffold with \"base.go.kubebuilder.io/v3\": template: *templates.Main:65:31: executing \"*templates.Main\" at <.ProjectName>: can't evaluate field ProjectName in type *templates.Main\nUsage:\n kubebuilder init [flags]\n\nExamples:\n # Initialize a new project with your domain and name in copyright\n kubebuilder init --plugins go/v3 --domain example.org --owner \"Your name\"\n\n # Initialize a new project defining a specific project version\n kubebuilder init --plugins go/v3 --project-version 3\n\n\nFlags:\n --component-config create a versioned ComponentConfig file, may be 'true' or 'false'\n --domain string domain for groups (default \"my.domain\")\n --fetch-deps ensure dependencies are downloaded (default true)\n -h, --help help for init\n --license string license to use to boilerplate, may be one of 'apache2', 'none' (default \"apache2\")\n --owner string owner to add to the copyright\n --project-name string name of this project\n --project-version string project version (default \"3\")\n --repo string name to use for go module (e.g., github.com/user/repo), defaults to the go package of the current working directory.\n --skip-go-version-check if specified, skip checking the Go version\n\nGlobal Flags:\n --plugins strings plugin keys to be used for this subcommand execution\n\n2022/10/17 16:00:25 failed to initialize project: unable to scaffold with \"base.go.kubebuilder.io/v3\": template: *templates.Main:65:31: executing \"*templates.Main\" at <.ProjectName>: can't evaluate field ProjectName in type *templates.Main\n", } kubebuilder init --plugins go/v3 --project-version 3 --domain example.comjxud failed with error: (exit status 1) Writing kustomize manifests for you to edit... **Writing scaffold for you to edit... Error: failed to initialize project: unable to scaffold with "base.go.kubebuilder.io/v3": template: *templates.Main:65:31: executing "*templates.Main" at <.ProjectName>: can't evaluate field ProjectName in type *templates.Main**See that for you are able to have the project name <.ProjectName> the boilerplate that defines the main.go must use
machinery.ProjectNameMixin. You can look for code examples in the project implementation.
Done, PTAL thanks.
OK, this case is a little customized case, maybe it is more proper to add it into the FAQ section (I am doing).
Hi @astraw99,
The FAQ PR https://github.com/kubernetes-sigs/kubebuilder/pull/3044 is merged so I think we can close this one. however, please feel free to re-open if you think that we should still be addressing this change in the scaffolds.