Skip to content

Commit c278d0f

Browse files
committed
chore: add AGENTS.md and CONTRIBUTING.md
On-behalf-of: @SAP mirza.kopic@sap.com Signed-off-by: Mirza Kopić <mirza.kopic@gmail.com>
1 parent c322cd5 commit c278d0f

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

AGENTS.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# resource-broker
2+
3+
Kubernetes operator for multi-cluster resource brokering. Kubebuilder v4, multigroup layout. Built on `sigs.k8s.io/multicluster-runtime`.
4+
5+
Read the org-wide [AGENTS.md](https://github.com/platform-mesh/.github/blob/main/AGENTS.md) for general conventions. Read [CONTRIBUTING.md](CONTRIBUTING.md) for contribution workflow.
6+
7+
## Commands
8+
9+
- `make check` — codegen + lint + test + test-e2e (CI gate)
10+
- `make test` — unit tests
11+
- `make test TEST_ARGS="-run TestName"` — single unit test
12+
- `make test-e2e` — e2e tests (uses envtest)
13+
- `make test-e2e TEST_ARGS="-run TestName"` — single e2e test
14+
- `make codegen` — regenerate CRDs, RBAC, DeepCopy from API types
15+
- `make lint` / `make lint-fix` — golangci-lint v2
16+
- `make build` — build broker binary
17+
- `make build-operator` — build operator binary
18+
- `make run` — run broker locally (debug logging)
19+
- `make run-operator` — run operator locally (debug logging)
20+
- `make examples` — run all example walkthroughs
21+
- `make help` — list all targets
22+
23+
## Structure
24+
25+
```
26+
api/ CRD types, grouped by domain
27+
broker/ AcceptAPI, Migration, MigrationConfiguration
28+
generic/ Cross-cloud APIs (databases, networking, storage, compute, etc.)
29+
example/ Example CRDs (Certificate, VM)
30+
operator/ Broker operator CRD
31+
cmd/ Entrypoints
32+
main.go resource-broker
33+
operator/ resource-broker-operator
34+
pkg/ Core logic
35+
broker/ Reconcilers (acceptapi, generic, migration)
36+
sync/ Resource copy and condition tracking
37+
conditions/ Status condition utilities
38+
kubernetes/ Annotation and map helpers
39+
config/ Kustomize manifests (CRDs, RBAC, deployment)
40+
test/ E2e tests and test utilities
41+
examples/ Runnable walkthroughs (certs, kcp-certs, platform-mesh)
42+
contrib/kcp/ kcp-specific Dockerfile and config
43+
```
44+
45+
## Architecture
46+
47+
Three cluster roles: coordination, consumer, provider. Two separate binaries: **operator** (single-cluster, manages Broker CRD, deploys broker) and **broker manager** (multi-cluster, runs reconcilers).
48+
49+
### Reconciliation Flow
50+
51+
1. Consumer resource created → consumer watch triggers GenericReconciler
52+
2. `decorateInConsumer()` adds finalizer + annotations
53+
3. `providerAcceptsObj()` queries AcceptAPI registry (in-memory map protected by lock)
54+
4. Resource copied to provider with hashed cluster prefix in name (`SanitizeClusterName()` → 12-char hex) to avoid multi-consumer collisions
55+
5. Provider watch triggers via `providerEventHandler` which maps back to consumer using annotations
56+
6. Status synced back to consumer via status subresource, with prefixes stripped by `StatusTransformer`
57+
7. Related resources (declared in `status.relatedResources`) copied to consumer with owner references
58+
59+
### Provider Churn
60+
61+
If AcceptAPI no longer matches, reconciler sets `new-provider-cluster` annotation, syncs to new provider, waits for readiness, then deletes from old provider.
62+
63+
### Migration
64+
65+
Staged state machine: Unknown → Pending → InitialInProgress → InitialCompleted → CutoverInProgress → CutoverCompleted. Each stage deploys template resources and evaluates CEL expressions against them before progressing.
66+
67+
### Key Annotations (control plane)
68+
69+
- `broker.platform-mesh.io/consumer-cluster`, `consumer-name` — origin tracking
70+
- `broker.platform-mesh.io/provider-cluster` — current provider
71+
- `broker.platform-mesh.io/new-provider-cluster` — migration target
72+
73+
### Constants
74+
75+
- Cluster prefixes: `consumer`, `provider`, `coordination` (`pkg/broker/broker.go`)
76+
- Finalizers: `broker.platform-mesh.io/acceptapi-finalizer`, `broker.platform-mesh.io/generic-finalizer`
77+
- AcceptAPI filters: ValueIn (enum), Boundary (min/max), Suffix (string suffix) — keys use dot notation for nested spec fields
78+
79+
## Code Conventions
80+
81+
License header on all `.go` files — Apache-2.0, "The Platform Mesh Authors". Enforced by goheader linter.
82+
83+
Import order (enforced by gci):
84+
1. stdlib
85+
2. third-party
86+
3. `k8s.io/`
87+
4. `sigs.k8s.io/controller-runtime/`
88+
5. `sigs.k8s.io/multicluster-runtime/`
89+
6. `github.com/platform-mesh/`
90+
91+
Tests: testify (require/assert). E2e: controller-runtime envtest. All tests must be parallel (paralleltest linter).
92+
93+
Run `make codegen` after any change to `api/` types.
94+
95+
## Git
96+
97+
Conventional Commits: `feat:`, `fix:`, `chore(deps):`, `ci:`, `refactor:`, `test:`, `docs:`
98+
99+
Never add AI attribution to commits or PRs.
100+
101+
## Do Not
102+
103+
- Edit `zz_generated.deepcopy.go` — generated by controller-gen
104+
- Edit `config/*/crd/*.yaml` directly — generated by `make manifests`
105+
- Skip the license header — CI enforces it
106+
- Add tool-specific instruction files (`CLAUDE.md`, `.cursorrules`, etc.) — use this file
107+
- Commit without running `make codegen` after API type changes

CONTRIBUTING.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Contributing to resource-broker
2+
3+
## General Remarks
4+
5+
You are welcome to contribute content (code, documentation etc.) to this open source project.
6+
7+
There are some important things to know:
8+
9+
1. You must **comply to the license of this project**, **accept the Developer Certificate of Origin** (see below) before being able to contribute. The acknowledgement to the DCO will usually be requested from you as part of your first pull request to this project.
10+
2. Please **adhere to our [Code of Conduct](https://github.com/platform-mesh/.github/blob/main/CODE_OF_CONDUCT.md)**.
11+
3. If you plan to use **generative AI for your contribution**, please see our [guideline for AI-generated code contributions](https://github.com/platform-mesh/.github/blob/main/CONTRIBUTING_USING_GENAI.md).
12+
4. **Not all proposed contributions can be accepted**. Some features may fit another project better or don't fit the general direction of this project. Of course, this doesn't apply to most bug fixes, but a major feature implementation for instance needs to be discussed with one of the maintainers first. The best way would be to just open an issue to discuss the feature you plan to implement (make it clear that you intend to contribute).
13+
14+
## Developer Certificate of Origin (DCO)
15+
16+
Contributors will be asked to accept a DCO before they submit the first pull request to this project, this happens in an automated fashion during the submission process. SAP uses [the standard DCO text of the Linux Foundation](https://developercertificate.org/).
17+
18+
## How to Contribute
19+
20+
1. Make sure the change is welcome (see [General Remarks](#general-remarks)).
21+
2. Fork the repository and create a branch.
22+
3. Make your changes and verify them locally:
23+
- Run `make check` to run code generation, linting, and all tests.
24+
- See [DEVELOPEPMENT.md](DEVELOPEPMENT.md) for all available make targets.
25+
4. Commit using [Conventional Commits](https://www.conventionalcommits.org/) format (e.g. `feat:`, `fix:`, `chore:`).
26+
5. Create a pull request.
27+
6. Follow the link posted by the CLA assistant to your pull request and accept it, as described above.
28+
7. Wait for code review and approval, possibly enhancing your change on request.
29+
30+
## Development
31+
32+
Prerequisites: Go (see version in `go.mod`), Docker, kubectl.
33+
34+
Key commands:
35+
36+
- `make check` — full validation (codegen + lint + test + test-e2e)
37+
- `make test` — unit tests
38+
- `make test-e2e` — end-to-end tests
39+
- `make codegen` — regenerate CRDs, RBAC, and DeepCopy after API type changes
40+
- `make lint-fix` — lint and auto-fix
41+
- `make run` — run broker locally with debug logging
42+
43+
See [DEVELOPEPMENT.md](DEVELOPEPMENT.md) for the full list.
44+
45+
## License
46+
47+
By contributing, you agree that your contributions will be licensed under the [Apache-2.0 License](LICENSE).

0 commit comments

Comments
 (0)