|
| 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 | + |
0 commit comments