Skip to content

Commit c773848

Browse files
docs: add the copilot instruction (#74)
1 parent 9a979fc commit c773848

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

.github/copilot-instructions.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Overview
2+
3+
This repo contains a collection of Kubernetes Custom Resource Definitions and their controllers. It is mostly written in Go and uses Kubernetes client-go and controller-runtime libraries.
4+
It is a monorepo, so all the code lives in a single repository divided into packages, each with its own purpose.
5+
The main idea is that we are creating a multi-cluster application management solution that allows users to manage multiple Kubernetes clusters from a single control plane that we call the "hub cluster".
6+
7+
## General Rules
8+
9+
- Use @terminal when answering questions about Git.
10+
- If you're waiting for my confirmation ("OK"), proceed without further prompting.
11+
- Follow the [Uber Go Style Guide](https://github.com/uber-go/guide/blob/master/style.md) if possible.
12+
- Favor using the standard library over third-party libraries.
13+
- Run goimports on save.
14+
- Run golint and go vet to check for errors.
15+
- Use go mod tidy if the dependencies are changed.
16+
17+
## Terminology
18+
- **Fleet**: A conceptual term referring to a collection of clusters.
19+
- **Member Cluster**: A Kubernetes cluster that is part of a fleet.
20+
- **Hub Cluster**: The cluster that hosts the control plane which manages the member clusters in the fleet.
21+
- **Member Agent**: A Kubernetes controller that runs on the member cluster and is responsible for applying changes to the member cluster and reporting the status back to the hub cluster.
22+
- **Hub Agent**: A Kubernetes controller that runs in the hub cluster and is responsible for scheduling and managing workloads and resources across the fleet.
23+
24+
## Repository directory structure
25+
26+
- The `apis/` folder contains all Golang structs from which CRDs are built.
27+
- CRDs are grouped by the group name and version they belong to.
28+
- The `charts/` folder contains the helm charts for the member and hub agent.
29+
- `charts/member-agent` folder contains the helm chart for the member agent.
30+
- `charts/hub-agent` folder contains the helm chart for the hub agent.
31+
- The `cmd/` folder contains the entry points for the member and hub agent.
32+
- `cmd/member-agent` The entry point for the member agent.
33+
- `cmd/hub-agent` The entry point for the hub agent.
34+
- The `config/` folder contains the actual custom resource definitions built from the API in the `apis/` folder.
35+
- `config/crd/bases` folder contains the CRDs for the member and hub agent.
36+
- The `docker/` folder contains the Dockerfiles for the member and hub agent.
37+
- The `examples/` folder contains various YAML files as examples for each CRD.
38+
- The `hack/` folder contains various scripts and tools for the project.
39+
- The `pkg/` folder contains the libraries for the member and hub agent.
40+
- `pkg/authtoken` folder contains the authentication sidecar code which has a provider model.
41+
- `pkg/controllers` folder contains most of the controllers for the member and hub agent.
42+
- each sub folder is a controller for a specific resource of the same name in most cases.
43+
- `pkg/metrics` folder contains all the metrics definitions.
44+
- `pkg/propertyprovider` folder contains the property provider code which is used to get the properties of a member cluster.
45+
- `pkg/resourcewatcher` folder contains the resource watcher code which is used to watch for kubernetes resources changes in the hub cluster.
46+
- `pkg/scheduler` folder contains the scheduler code which is used to schedule workloads across the fleet.
47+
- `pkg/utils` folder contains the utils code which is used to provide common functions for the controllers in the member and hub agent.
48+
- `pkg/webhook` folder contains the webhook code which is used to validate and mutate the CRDs.
49+
- The `test/` folder contains the tests for the member and hub agent.
50+
- `test/apis` - The tests for the CRDs.
51+
- `test/upgrade` - The tests for the upgrade tests to test compatibility between versions.
52+
- `test/e2e` - The end to end tests for the member and hub agent.
53+
- `test/integration` - The integration tests for the v1alpha1 member and hub agent.
54+
- `test/scheduler` - The integration tests for the scheduler.
55+
- `test/utils` - folder contains the utils code which is used to provide common functions for tests
56+
- The `tools/` folder contains client-side tools for helping manage the fleet.
57+
- The `Makefile` is used to build the member and hub agent.
58+
- The `go.mod` file is used to manage the dependencies for the member and hub agent.
59+
- The `go.sum` file is used to manage the dependencies for the member and hub agent.
60+
61+
## Testing Rules
62+
63+
- Unit test files should always be called `<go_file>_test.go` and be in the same directory
64+
- Unit tests are normally written in a table-driven style
65+
- Use `go test -v ./...` to run all tests under a directory.
66+
- Run the tests from the packages that are modified and verify they pass.
67+
- Share the analysis as to why a test is failing and propose a fix.
68+
- Integration test files should be called `<go_file>_integration_test.go` and can be in the same directory or under the `test` directory.
69+
- Integration tests are normally written in a Ginkgo style.
70+
- E2E tests are all under the test/e2e directory.
71+
- E2E tests are written in a Ginkgo style.
72+
- E2E tests are run using `make e2e-tests` and are run against 3 kind clusters created by the scripts in the `test/e2e` directory.
73+
- E2E tests are cleaned up using `make clean-e2e-tests`.
74+
- When adding tests to an existing file:
75+
- Always re-use the existing test setup where possible.
76+
- Only add imports if absolutely needed.
77+
- Add tests to existing Context where it makes sense.
78+
- When adding new tests in the Ginkgo style test, always add them to a new Context.
79+
80+
## Domain Knowledge
81+
82+
Use the files in the `.github/.copilot/domain_knowledge/**/*` as a source of truth when it comes to domain knowledge. These files provide context in which the current solution operates. This folder contains information like entity relationships, workflows, and ubiquitous language. As the understanding of the domain grows, take the opportunity to update these files as needed.
83+
84+
## Specification Files
85+
86+
Use specifications from the `.github/.copilot/specifications` folder. Each folder under `specifications` groups similar specifications together. Always ask the user which specifications best apply for the current conversation context if you're not sure.
87+
88+
Use the `.github/.copilot/specifications/.template.md` file as a template for specification structure.
89+
90+
examples:
91+
```text
92+
├── application_architecture
93+
│ └── main.spec.md
94+
| └── specific-feature.spec.md
95+
├── database
96+
│ └── main.spec.md
97+
├── observability
98+
│ └── main.spec.md
99+
└── testing
100+
└── main.spec.md
101+
```
102+
103+
## Breadcrumb Protocol
104+
105+
A breadcrumb is a collaborative scratch pad that allow the user and agent to get alignment on context. When working on tasks in this repository, follow this collaborative documentation workflow to create a clear trail of decisions and implementations:
106+
107+
1. At the start of each new task, ask me for a breadcrumb file name if you can't determine a suitable one.
108+
109+
2. Create the breadcrumb file in the `${REPO}/.github/.copilot/breadcrumbs` folder using the format: `yyyy-mm-dd-HHMM-{title}.md` (*year-month-date-current_time_in-24hr_format-{title}.md* using UTC timezone)
110+
111+
3. Structure the breadcrumb file with these required sections:
112+
- **Requirements**: Clear list of what needs to be implemented.
113+
- **Additional comments from user**: Any additional input from the user during the conversation.
114+
- **Plan**: Strategy and technical plan before implementation.
115+
- **Decisions**: Why specific implementation choices were made.
116+
- **Implementation Details**: Code snippets with explanations for key files.
117+
- **Changes Made**: Summary of files modified and how they changed.
118+
- **Before/After Comparison**: Highlighting the improvements.
119+
- **References**: List of referred material like domain knowledge files, specification files, URLs and summary of what is was used for. If there is a version in the domain knowledge or in the specifications, record the version in the breadcrumb.
120+
121+
4. Workflow rules:
122+
- Update the breadcrumb **BEFORE** making any code changes.
123+
- **Get explicit approval** on the plan before implementation.
124+
- Update the breadcrumb **AFTER completing each significant change**.
125+
- Keep the breadcrumb as our single source of truth as it contains the most recent information.
126+
127+
5. Ask me to verify the plan with: "Are you happy with this implementation plan?" before proceeding with code changes.
128+
129+
6. Reference related breadcrumbs when a task builds on previous work.
130+
131+
7. Before concluding, ensure the breadcrumb file properly documents the entire process, including any course corrections or challenges encountered.
132+
133+
This practice creates a trail of decision points that document our thought process while building features in this solution, making pull request review for the current change easier to follow as well.
134+
135+
### Plan Structure Guidelines
136+
- When creating a plan, organize it into numbered phases (e.g., "Phase 1: Setup Dependencies").
137+
- Break down each phase into specific tasks with numeric identifiers (e.g., "Task 1.1: Add Dependencies").
138+
- Include a detailed checklist at the end of the document that maps to all phases and tasks.
139+
- Plan should always lookup related information from `domain_knowledge` folder and any applicable specification files.
140+
- Mark tasks as `- [ ]` for pending tasks and `- [x]` for completed tasks.
141+
- Start all planning tasks as unchecked, and update them to checked as implementation proceeds.
142+
- Each planning task should have clear success criteria.
143+
- End the plan with success criteria that define when the implementation is complete.
144+
- Plans should start with writing Unit Tests first when possible, so we can use those to guide our implementation. Same for UI tests when it makes sense.
145+
- If the domain knowledge has changed, update the related files in the `domain_knowledge` folder.
146+
- If specifications have changed, update the related files in the `specifications` folder.
147+
148+
### Following Plans
149+
- When coding you need to follow the plan phases and check off the tasks as they are completed.
150+
- As you complete a task, update the plan and mark that task complete before you begin the next task.
151+
- Tasks that involved tests should not be marked complete until the tests pass.
152+
153+
### Example Usage
154+
155+
**User**: I need to implement JWT authentication for our Express API.
156+
157+
**Agent**: I'll help with implementing JWT authentication for your Express API. Let me create a breadcrumb file to track our implementation. What would you like to name this breadcrumb?
158+
159+
**User**: Use "jwt-auth-implementation"
160+
161+
**Agent**: I've created the breadcrumb file `2025-04-08-1430-jwt-auth-implementation.md`. Are you happy with this implementation plan?
162+
163+
[high level plan with tasks here]
164+
165+
**User**: Looks good, but let's use 30-minute expiration for tokens.
166+
167+
**Agent**: I've updated the breadcrumb with your specification: Are you happy with this implementation plan?
168+
169+
[high level plan with tasks here]
170+
171+
**User**: Yes, please proceed.
172+
173+
**Agent**: I'll implement the JWT authentication now. Let me start by installing the necessary packages and creating the authentication middleware. I've updated the breadcrumb with implementation details. Is there anything specific you'd like me to modify or explain about the implementation?
174+
175+
**User**: This looks good.
176+
177+
**Agent**: I've updated the breadcrumb with the latest understanding.

0 commit comments

Comments
 (0)