kelos-dev / kelos-dev/kelos

webhook server: conditionally omitting .Branch from template vars breaks task creation with missingkey=error

Open
#964 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

actor/kelos kind/bug priority/important-soon triage-accepted
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:160
  • internal/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_comment event posted on a regular issue — GitHub's payload has no head ref because there is no PR
  • issue_comment event posted on a pull request when the webhook server has no GitHub API credentials — the lazy enrichGitHubIssueCommentBranch fetch in internal/webhook/github_api.go returns 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.activeTasks does 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 tasks shows nothing

Reproduction

  1. Deploy kelos with the webhook server enabled but webhookServer.sources.github.githubSecretName unset
  2. Create a TaskSpawner with taskTemplate.branch: "{{.Branch}}" and an issue_comment filter
  3. Post a matching comment on an open PR
  4. Check kelos-controller-manager logs: template render fails with map has no entry for key "Branch"
  5. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.