webhook server: conditionally omitting .Branch from template vars breaks task creation with missingkey=error
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 331
- Forks
- 40
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 70
Description
Problem
internal/webhook/github_filter.go builds the webhook template variable map and adds .Branch only when the value is non-empty:
if eventData.Branch != "" {
vars["Branch"] = eventData.Branch
}
The task builder and task controller parse templates with .Option("missingkey=error"):
internal/taskbuilder/builder.go:160internal/controller/task_controller.go:874
So any TaskSpawner template that references {{.Branch}} fails to render when the webhook payload does not carry a branch, and task creation aborts with map has no entry for key "Branch".
When .Branch is empty
issue_commentevent posted on a regular issue — GitHub's payload has no head ref because there is no PRissue_commentevent posted on a pull request when the webhook server has no GitHub API credentials — the lazyenrichGitHubIssueCommentBranchfetch ininternal/webhook/github_api.goreturns empty and logs"No GitHub credentials configured, cannot enrich issue_comment event with PR branch"- Push events with no ref string (unusual but possible via synthetic or incomplete deliveries)
Impact
Any TaskSpawner whose taskTemplate.branch is set to {{.Branch}} silently fails to create tasks in the above cases. This is the recommended idiom for PR-scoped spawners — the value is also used by TaskReconciler as the per-branch writer lock — so any spawner following that convention is affected whenever the above conditions hit.
The failure mode is particularly hard to debug:
- Webhook server logs show delivery accepted
TaskSpawner.status.activeTasksdoes not increment- The error only appears in controller logs when it tries to render the template
- No Task object is ever created, so
kubectl get tasksshows nothing
Reproduction
- Deploy kelos with the webhook server enabled but
webhookServer.sources.github.githubSecretNameunset - Create a TaskSpawner with
taskTemplate.branch: "{{.Branch}}"and anissue_commentfilter - Post a matching comment on an open PR
- Check
kelos-controller-managerlogs: template render fails withmap has no entry for key "Branch" - Confirm no Task is created
Same failure is reproducible by posting the trigger comment on an issue instead of a PR, even when credentials ARE configured.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with internal/webhook/github_filter.go, then inspect the template parsing in internal/taskbuilder/builder.go:160 and internal/controller/task_controller.go:874. Reproduce the issue with an issue_comment event lacking a branch and verify that a TaskSpawner template referencing .Branch can render and create a Task with an empty branch value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, kubernetes
- Domain
- backend, devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100