|
| 1 | +# Tekton Triggers |
| 2 | + |
| 3 | +Event-driven CI/CD controller for Kubernetes. Listens for events (GitHub webhooks, etc.), |
| 4 | +maps them to Tekton PipelineRuns/TaskRuns via TriggerBindings and TriggerTemplates, and |
| 5 | +creates Kubernetes resources through EventListeners. |
| 6 | + |
| 7 | +**Behavioral guidelines**: See [.agents/guidelines.md](./.agents/guidelines.md) for generic coding principles. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## Build & Test Commands |
| 12 | + |
| 13 | +```bash |
| 14 | +# Build all binaries |
| 15 | +make all |
| 16 | + |
| 17 | +# Build specific component |
| 18 | +make bin/controller |
| 19 | +make bin/eventlistenersink |
| 20 | +make bin/interceptors |
| 21 | +make bin/webhook |
| 22 | +make bin/tkn-triggers |
| 23 | + |
| 24 | +# Unit tests — no cluster required |
| 25 | +make test-unit |
| 26 | + |
| 27 | +# End-to-end tests — requires a running cluster |
| 28 | +make test-e2e |
| 29 | + |
| 30 | +# YAML tests |
| 31 | +make test-yamls |
| 32 | + |
| 33 | +# Format code — required before PR submission |
| 34 | +make fmt |
| 35 | + |
| 36 | +# Lint — must pass before every PR |
| 37 | +make golangci-lint |
| 38 | + |
| 39 | +# Code generation — required after modifying types or CRD schemas |
| 40 | +./hack/update-codegen.sh |
| 41 | +``` |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +## Single-File Verification |
| 46 | + |
| 47 | +```bash |
| 48 | +# Lint a single Go file |
| 49 | +golangci-lint run path/to/file.go |
| 50 | + |
| 51 | +# Type-check using staticcheck |
| 52 | +staticcheck ./path/to/pkg/... |
| 53 | + |
| 54 | +# Format a single file in place |
| 55 | +gofmt -w path/to/file.go |
| 56 | + |
| 57 | +# Vet the package containing the file |
| 58 | +go vet ./path/to/pkg/... |
| 59 | +``` |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## Key Conventions |
| 64 | + |
| 65 | +1. **Dependencies are vendored.** All Go dependencies live in `vendor/`. Review agents |
| 66 | + should ignore the `vendor/` directory — it contains third-party code. |
| 67 | + |
| 68 | +2. **Use structured logging.** Import `knative.dev/pkg/logging` and use context-aware |
| 69 | + loggers. Never use `fmt.Printf` or `log.Print` in production code. |
| 70 | + |
| 71 | +3. **CRD types live in `pkg/apis/`.** After modifying any type definition, run |
| 72 | + `./hack/update-codegen.sh` to regenerate deepcopy, client, and informer code. |
| 73 | + |
| 74 | +4. **Interceptors are the request/response processing layer.** Core interceptors |
| 75 | + (CEL, GitHub, GitLab, Bitbucket, Slack) live in `pkg/interceptors/` and run as a |
| 76 | + dedicated HTTPS service (port 8443). Custom interceptors are registered via the |
| 77 | + `ClusterInterceptor` CRD and called by the sink over HTTP(S). The `pkg/interceptors/webhook/` |
| 78 | + package handles the deprecated `Interceptor.Webhook` field for calling arbitrary |
| 79 | + external URLs directly from the sink — distinct from `ClusterInterceptor`. |
| 80 | + |
| 81 | +5. **Test coverage is enforced.** PRs adding functionality must include tests. |
| 82 | + E2E tests are tagged and require a cluster — unit tests should not. |
| 83 | + |
| 84 | +6. **Config lives in `config/`.** Kubernetes manifests (CRDs, RBAC, deployments) |
| 85 | + are generated/managed there. Do not hand-edit generated CRD YAML. |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## Architecture |
| 90 | + |
| 91 | +**Controller** (`cmd/controller`, `pkg/reconciler/`): Reconciles EventListener, |
| 92 | +TriggerBinding, TriggerTemplate, ClusterTriggerBinding, ClusterInterceptor CRDs. |
| 93 | +Uses Knative's controller framework. |
| 94 | + |
| 95 | +**EventListener Sink** (`cmd/eventlistenersink`, `pkg/sink/`): HTTP server |
| 96 | +that receives events and processes them through trigger bindings, templates, and |
| 97 | +interceptors to create Kubernetes resources. |
| 98 | + |
| 99 | +**Interceptors** (`cmd/interceptors`, `pkg/interceptors/`): HTTPS service (port 8443) |
| 100 | +handling core interceptors (CEL, GitHub, GitLab, Bitbucket, Slack). The sink calls interceptors |
| 101 | +via HTTP POST. ClusterInterceptors can extend this for custom logic. |
| 102 | + |
| 103 | +**Webhook** (`cmd/webhook`): Kubernetes admission webhook for validating and |
| 104 | +defaulting CRD resources. |
| 105 | + |
| 106 | +**tkn-triggers CLI** (`cmd/tkn-triggers`): CLI plugin for `tkn` to interact |
| 107 | +with Triggers resources. |
| 108 | + |
| 109 | +**Utility CLIs** (`cmd/binding-eval`, `cmd/cel-eval`, `cmd/triggerrun`): Developer |
| 110 | +tools for evaluating bindings, CEL expressions, and trigger processing locally. |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## Pattern References for Common Changes |
| 115 | + |
| 116 | +- **New interceptor type**: Follow `pkg/interceptors/cel/` as the reference implementation |
| 117 | +- **New reconciler**: Follow `pkg/reconciler/eventlistener/` for structure and patterns |
| 118 | +- **New CRD type**: Add to `pkg/apis/triggers/`, update `./hack/update-codegen.sh` |
| 119 | +- **Sink event processing**: See `pkg/sink/sink.go` for the main event handling path |
| 120 | +- **E2E tests**: Follow examples in `test/eventlistener_test.go` |
| 121 | +- **CEL expressions**: See `pkg/interceptors/cel/` and `docs/cel_expressions.md` |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +## PR Conventions |
| 126 | + |
| 127 | +- Pull requests must follow the repository PR template in `.github/pull_request_template.md`. |
| 128 | +- Run `make fmt` before submitting for review. |
| 129 | +- `make golangci-lint` must pass with zero issues. |
| 130 | +- Tests required for any functionality changes. |
| 131 | +- Follow [Tekton commit message standards](https://github.com/tektoncd/community/blob/main/standards.md#commits). |
| 132 | +- Add `/kind <type>` label (bug, feature, cleanup, etc.). |
| 133 | +- Update release notes block if user-facing changes. |
| 134 | +- Run `./hack/update-codegen.sh` after modifying CRD types. |
| 135 | +- Ignore `vendor/` directory in reviews — contains vendored dependencies only. |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## Skills |
| 140 | + |
| 141 | +None configured yet. Repo-local skills can be added to `.agents/skills/`. |
0 commit comments