Skip to content

Commit d7abc61

Browse files
Improve CoPIlot configuration (#4845)
* Add path to installed tools * Add instructions to guide copilot * Add key guidelines * Add Quick Start to new resource guide * Move original instructions file into a folder * Add new resource instructions * Remove empty file
1 parent eb48135 commit d7abc61

File tree

4 files changed

+202
-1
lines changed

4 files changed

+202
-1
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copilot Instructions for Azure Service Operator
2+
3+
You are an expert Go developer and an AI assistant helping to maintain the Azure Service Operator (ASO) project. Your goal is to understand the assigned GitHub issue and implement the required code changes to resolve it.
4+
5+
## Your Workflow
6+
7+
Please follow these steps to ensure your contributions are effective and align with our project standards:
8+
9+
1. **Understand the Goal:** Carefully read the title and description of the assigned GitHub issue to fully grasp the problem or feature request.
10+
2. **Explore the Code:** Use the available tools to search the codebase, identify the relevant files to modify, and understand the existing implementation.
11+
3. **Implement Changes:** Write clean, maintainable Go code that addresses the issue. Please mimic the style of the existing code in the repository.
12+
4. **Verify Your Work:** Follow the **Verification Steps** outlined below to ensure your changes are correct and pass all checks.
13+
14+
## Project Context
15+
16+
* **Purpose:** ASO is a Go-based operator for creating and managing Azure resources from a Kubernetes cluster.
17+
18+
* **Key Files:**
19+
* `v2/azure-arm.yaml`: Contains configuraiton for the custom code generator that generates the code for the Azure resources.
20+
21+
* **Key Directories:**
22+
* `v2/api/`: Contains the API definitions for the Azure resources (the CRDs).
23+
* `v2/internal/controllers/`: Contains the reconciliation logic for the operator.
24+
* `docs/hugo/content/`: Holds the reference documentation.
25+
* `v2/tools/generator`: Contains the code generator that generates the code for the Azure resources.
26+
27+
## Development Environment
28+
29+
Your environment is automatically configured by the `.github/workflows/copilot-setup-steps.yml` workflow. This ensures all necessary tools are installed and available.
30+
31+
* Custom tools are installed in the `hack/tools` directory and added to your `PATH`.
32+
* If you find a required tool is missing, please stop and report it as a problem.
33+
* Don't modify generated files by hand (e.g. `*.gen.go` and `*.gen_test.go` files) as those changes will be overwritten during the build.
34+
35+
## Verification Steps
36+
37+
Before completing your task, you **must** run these checks in the specified order, one at a time. If any step fails, fix the issues and **start again from the beginning of the list.**
38+
39+
1. **Format Code:**
40+
```bash
41+
task format-code
42+
```
43+
44+
45+
2. **Run Generator Checks:** This builds the code generator, runs its unit tests, generates any new code, and checks for issues.
46+
```bash
47+
task generator:quick-checks
48+
```
49+
50+
3. **Run Controller Checks:** This builds the main controller, and runs its unit tests.
51+
```bash
52+
task controller:quick-checks
53+
```
54+
55+
If an issue seems too complex to fix, please stop and ask for clarification.
56+
57+
## Key Guidelines
58+
59+
1. Follow Go best practices and idiomatic patterns
60+
2. Maintain existing code structure and organization
61+
3. Write unit tests for new functionality. Use table-driven unit tests when possible.
62+
4. Document public APIs and complex logic. Suggest changes to the `docs/hugo/content` folder when appropriate
63+
64+
## Reference Documentation
65+
66+
We have extensive reference documentation available under the `docs/hugo/content` directory, including a detailed contributors guide in the `docs/hugo/content/contributing` directory. Please consult this as required.
67+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Copilot instructions for adding a new resource to Azure Service Operator
2+
3+
You are an expert Go developer and an AI assistant helping to maintain the Azure Service Operator (ASO) project. Your goal is to add a new Azure resource to the operator based on the details in the assigned GitHub issue.
4+
5+
Instructions in this file are specific to adding a new resource (or a new version of an existing resource) to the project.
6+
7+
## Your Workflow
8+
9+
Follow these steps precisely. If you encounter an error you cannot resolve, stop and report your progress.
10+
11+
### 1. Identify the Resource to Add
12+
13+
From the GitHub issue, determine the resource's **Group**, **Version**, and **Kind** (GVK).
14+
15+
* **Group**: The Azure service name (e.g., `storage`, `network`, `compute`).
16+
* **Version**: The API version, like `2021-06-01`, which becomes `v1api20210601`. Use the latest stable version unless the issue specifies a preview.
17+
* **Kind**: The singular name of the resource (e.g., `storageAccount`, `virtualNetwork`).
18+
19+
### 2. Configure the Code Generator
20+
21+
You will now edit `v2/azure-arm.yaml` to tell the code generator about the new resource.
22+
23+
1. Locate the `objectModelConfiguration` section.
24+
2. Find the resource's `group` (e.g., `synapse:`). If it doesn't exist, add it in alphabetical order.
25+
3. Find the `version` (e.g., `2021-06-01:`). If it doesn't exist, add it in numerical order.
26+
4. Add the resource `Kind` (e.g., `Workspace:`), ensuring it is nested correctly.
27+
5. Add the `$exportAs` and `$supportedFrom` directives. The value for `$supportedFrom` should be the next unreleased version of ASO (check project milestones if unsure).
28+
29+
**Example:**
30+
```yaml
31+
# ...
32+
synapse:
33+
2021-06-01:
34+
Workspace:
35+
$exportAs: Workspace
36+
$supportedFrom: v2.10.0 # Check for the correct upcoming release
37+
# ...
38+
```
39+
40+
### 3. Run the Code Generator
41+
42+
Execute the following command from the root of the repository to generate the resource files.
43+
44+
```bash
45+
task generator:quick-checks
46+
```
47+
48+
This command will likely fail with errors about resource references. This is expected. Proceed to the next step.
49+
50+
### 4. Fix Generator Errors
51+
52+
The most common error is `"looks like a resource reference but was not labelled as one"`. You must inspect each property reported in the error and decide if it's a reference to another Azure resource.
53+
54+
* If it **IS** a reference to another ARM resource, mark it with `$referenceType: arm`.
55+
* If it **IS NOT** a reference, mark it with `$referenceType: simple`.
56+
57+
Update `v2/azure-arm.yaml` with the necessary configuration.
58+
59+
**Example:**
60+
```yaml
61+
# ...
62+
network:
63+
2020-11-01:
64+
NetworkSecurityGroup:
65+
PrivateLinkResource:
66+
Id:
67+
$referenceType: arm # This property IS an ARM reference
68+
# ...
69+
```
70+
71+
After editing the file, re-run `task generator:quick-checks`. Repeat this process until the generator succeeds without errors.
72+
73+
### 5. Review the Generated Code
74+
75+
Inspect the newly generated files in `v2/api/<group>/<version>/`. Pay close attention to the `_types_gen.go` file for your resource.
76+
77+
* **Check for missing secrets:** Identify any properties on the `Spec` that should be secrets (e.g., passwords, keys) but are currently strings. Mark them in `azure-arm.yaml` with `$isSecret: true`.
78+
* **Check for Azure-generated secrets:** Look at the `Status` object. If Azure generates keys, connection strings, or other sensitive data upon creation, configure them to be exported to a Kubernetes secret using `$azureGeneratedSecrets`.
79+
* **Check for read-only properties in the Spec:** Sometimes properties that are read-only in Azure are not marked as such in the OpenAPI spec. These must be removed from the `Spec` by adding a `remove: true` directive in `azure-arm.yaml`.
80+
81+
After making any changes, re-run `task generator:quick-checks`.
82+
83+
### 6. Write an Integration Test
84+
85+
1. Navigate to `v2/internal/controllers/`.
86+
2. Find a test for a similar resource and copy it to a new file. The file should be named `<group>_<kind>_crud_test.go`.
87+
3. Modify the test to create, verify, and delete your new resource. Ensure you are testing a representative set of properties.
88+
4. Delete any existing recording file for your new test from the `recordings` sub-directory.
89+
5. Run the test to record the interaction with Azure:
90+
```bash
91+
TEST_FILTER=Test_<Group>_<Kind>_CRUD task controller:test-integration-envtest
92+
```
93+
Replace `<Group>` and `<Kind>` with the appropriate values.
94+
95+
### 7. Create a Sample
96+
97+
1. Create a new sample YAML file in `v2/samples/<group>/<version>/`.
98+
2. The sample should demonstrate a simple, working configuration of the resource.
99+
3. Run the samples test to record the new sample's creation and deletion:
100+
```bash
101+
TEST_FILTER=Test_Samples_CreationAndDeletion task controller:test-integration-envtest
102+
```
103+
104+
### 8. Final Verification
105+
106+
Run all local checks to ensure your changes haven't introduced any regressions.
107+
108+
```bash
109+
task ci
110+
```
111+
112+
This command takes a long time but is the best way to ensure your pull request will pass CI. Once it completes successfully, your task is done.
113+
114+
115+
## Reference Documentation
116+
117+
For more detailed instructions on adding a new resource, refer to the [Adding a new code generated resource to ASO v2 documentation](docs/hugo/content/contributing/add-a-new-code-generated-resource/_index.md).
118+

.github/workflows/copilot-setup-steps.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ jobs:
2626
submodules: 'true'
2727

2828
- name: Install Dependencies
29-
run: sudo .devcontainer/install-dependencies.sh
29+
run: sudo .devcontainer/install-dependencies.sh --skip-installed
30+
31+
- name: Set custom PATH
32+
run: echo "PATH=$PATH:$(realpath ./hack/tools)" >> $GITHUB_ENV

docs/hugo/content/contributing/add-a-new-code-generated-resource/_index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ layout: single
66

77
Want to add a new resource to Azure Service Operator v2? You're in the right place - here's your step by step guide.
88

9+
## Quick Start
10+
11+
Adding a new resource is a multi-step process driven by our code generator. At a high level, the process is:
12+
13+
1. **Configure**: Edit `v2/azure-arm.yaml` to add the new resource.
14+
2. **Generate**: Run `task generator:quick-checks` to generate the Go code. This will likely fail.
15+
3. **Fix & Repeat**: Fix errors reported by the generator by adding configuration to `v2/azure-arm.yaml`, then re-run the generator. Repeat until generation succeeds.
16+
4. **Test**: Write an integration test to verify the resource can be created, updated, and deleted.
17+
5. **Sample**: Create a sample YAML to demonstrate how to use the resource.
18+
6. **Verify**: Run `task ci` to ensure all checks pass before creating a pull request.
19+
20+
## Step by step guide
21+
922
By the end of this process, you'll have created a new resource, written a test to verify it works, and created a sample to demonstrate how to use it. This sounds like a lot of work, but most of it is done for you by our code generator.
1023

1124
1. [**Before you begin**]({{< relref "before-you-begin" >}}) sets the context for the rest of the process. You begin by identifying the resource you want to add and preparing your development environment.

0 commit comments

Comments
 (0)