Skip to content

Commit

Permalink
Add 'manual' provisioning to containers (#6423)
Browse files Browse the repository at this point in the history
# Description

This change adds 'manual' provisioning mode to containers, this means
that a container can have the setting `resourceProvisioning: 'manual'`
which means that Radius won't create any resources. This also includes
the ability to specify `resources: ...` to denote the existing resources
associated with the container.

This will be used by the new Kubernetes integration that needs to
*track* the existance of a container without deploying it.


## Type of change

- This pull request adds or changes features of Radius and has an
approved issue (issue link required).


## Auto-generated summary

<!--
GitHub Copilot for docs will auto-generate a summary of the PR
-->

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at fce2fbf</samp>

### Summary
🐳🛠️🧪

<!--
1. 🐳 - This emoji represents a container or a whale, and it can be used
to indicate the changes related to container resources and their
provisioning.
2. 🛠️ - This emoji represents a tool or a hammer and wrench, and it can
be used to indicate the changes related to adding or modifying code,
functions, types, or schemas.
3. 🧪 - This emoji represents a test or a test tube, and it can be used
to indicate the changes related to adding or updating tests or
assertions.
-->
This pull request adds support for manual resource provisioning for
containers in the radius project. It introduces new fields, types, and
schemas to the `v20231001preview` API version, the `datamodel` package,
and the `typespec` folder. It also updates the `corerp` package, the
`swagger` specification, and the test files to handle the new feature.
It adds conditional logic to the `handlers` and `renderers` packages to
skip creating or rendering resources that are manually provisioned.

> _To manage containers with ease_
> _We added some new fields and keys_
> _`resourceProvisioning` and `resources`_
> _Are part of the `ContainerProperties`_
> _And they help us reference and create with APIs_

### Walkthrough
* Add support for manual resource provisioning for containers
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-c019a02a8a768b2eec23949592ff1e7b5a167de082059261b3c3372e2870dacaL136-R139),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-c019a02a8a768b2eec23949592ff1e7b5a167de082059261b3c3372e2870dacaL261-R267),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-c019a02a8a768b2eec23949592ff1e7b5a167de082059261b3c3372e2870dacaR555-R589),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbR59-R63),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbR87-R93),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbL121-R149),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbL165-R183),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-fe08aa1da384f35b2b045ae14ccfeef240b4feb9f65363e29c882a9b1718845eL1-R16),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-d98390d94414de84ab52d6bd92ff16d9a6643ca92e366d025a07d9c3b3e63e4aL1-R35),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-07cd8284519deaa5e625f1fe393cb48bdd1cc621c9a4656ca43cc6049dfe7962R68-R87),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-21034b9d798fa570ecae4b7d54142c7f94d9d0f1b39c5f45f0c4c859674b19fbR303-R308),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-21034b9d798fa570ecae4b7d54142c7f94d9d0f1b39c5f45f0c4c859674b19fbR381-R386),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-21034b9d798fa570ecae4b7d54142c7f94d9d0f1b39c5f45f0c4c859674b19fbR1387-R1392),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-bc1502ced9e29d6d61dc028d22603e863f59a981bbc54a59879ba3177d8e62e9R624-R625),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-bc1502ced9e29d6d61dc028d22603e863f59a981bbc54a59879ba3177d8e62e9R661-R666),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-bc1502ced9e29d6d61dc028d22603e863f59a981bbc54a59879ba3177d8e62e9R803-R804),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-bc1502ced9e29d6d61dc028d22603e863f59a981bbc54a59879ba3177d8e62e9R836-R841),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-bc1502ced9e29d6d61dc028d22603e863f59a981bbc54a59879ba3177d8e62e9R3274-R3300),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-5275155acd7f7a59f0301cfc95f8dd38f72f22795e3197c6a150bae13dd5d5f3L74-R80),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-5275155acd7f7a59f0301cfc95f8dd38f72f22795e3197c6a150bae13dd5d5f3R138-R141),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-033dc8a7c9b970cc30f7420ce8cf2f12a26258b276779683ba3f761c481bf0a7R81-R86),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-3da981bf20df07918a646eafcd867d6c95abac1f3aef1ed1b50a29f3f4cc8636R36),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-3da981bf20df07918a646eafcd867d6c95abac1f3aef1ed1b50a29f3f4cc8636R169-R183),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-3da981bf20df07918a646eafcd867d6c95abac1f3aef1ed1b50a29f3f4cc8636L204),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-6f1219f263ab06a1493ac76960e2ab8cbe647e83e926bff7d13988f393334f94R25),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-6f1219f263ab06a1493ac76960e2ab8cbe647e83e926bff7d13988f393334f94R401-R435),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-a2ffa8fdf3e7cacf68f61fdc82a345456a27dd04bb95d914b1194454b00d1c0aR81-R85),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-99efabd56bb5d297b7f40c7c9958b4b11139710d7149e713ab6ac662d1546cb4R75-R79),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-ac35cdfa65680d5d2be2d0513a686f4651b9a41eb951d05dcd446bc927090d68R2953-R2963),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-ac35cdfa65680d5d2be2d0513a686f4651b9a41eb951d05dcd446bc927090d68R3015-R3038),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-ac35cdfa65680d5d2be2d0513a686f4651b9a41eb951d05dcd446bc927090d68R3091-R3101),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-ac35cdfa65680d5d2be2d0513a686f4651b9a41eb951d05dcd446bc927090d68R4637-R4649),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-2f8e96d0546ae7b99ee68e516a354825696d77ca06e49bb6f82ab1caaa778522L65-R83))
* Add new fields `ResourceProvisioning` and `Resources` to the
`ContainerProperties` and `ContainerResourceUpdateProperties` structs in
the `v20231001preview` and `datamodel` packages
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-c019a02a8a768b2eec23949592ff1e7b5a167de082059261b3c3372e2870dacaL136-R139),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-c019a02a8a768b2eec23949592ff1e7b5a167de082059261b3c3372e2870dacaL261-R267),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-21034b9d798fa570ecae4b7d54142c7f94d9d0f1b39c5f45f0c4c859674b19fbR303-R308),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-21034b9d798fa570ecae4b7d54142c7f94d9d0f1b39c5f45f0c4c859674b19fbR381-R386),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-5275155acd7f7a59f0301cfc95f8dd38f72f22795e3197c6a150bae13dd5d5f3L74-R80))
* Add new type `ContainerResourceProvisioning` as an enum that specifies
how the container resource is managed in the `v20231001preview` package
and the `typespec` folder
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-07cd8284519deaa5e625f1fe393cb48bdd1cc621c9a4656ca43cc6049dfe7962R68-R87),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-2f8e96d0546ae7b99ee68e516a354825696d77ca06e49bb6f82ab1caaa778522L65-R83))
* Add new type `ResourceReference` as a struct that describes a
reference to an existing resource in the `v20231001preview` and
`datamodel` packages and the `swagger` folder
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-21034b9d798fa570ecae4b7d54142c7f94d9d0f1b39c5f45f0c4c859674b19fbR1387-R1392),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-5275155acd7f7a59f0301cfc95f8dd38f72f22795e3197c6a150bae13dd5d5f3R138-R141),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-ac35cdfa65680d5d2be2d0513a686f4651b9a41eb951d05dcd446bc927090d68R4637-R4649))
* Add new helper functions to convert between the `ResourceReference`
and `ContainerResourceProvisioning` types in the `v20231001preview` and
`datamodel` packages
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-c019a02a8a768b2eec23949592ff1e7b5a167de082059261b3c3372e2870dacaR555-R589))
* Add new test cases to the `TestContainerConvertVersionedToDataModel`
and `TestContainerConvertDataModelToVersioned` functions in the
`container_conversion_test.go` file using the
`containerresource-manual.json` and
`containerresourcedatamodel-manual.json` files as test inputs
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbR59-R63),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbR87-R93),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbL121-R149),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbL165-R183),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-fe08aa1da384f35b2b045ae14ccfeef240b4feb9f65363e29c882a9b1718845eL1-R16),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-d98390d94414de84ab52d6bd92ff16d9a6643ca92e366d025a07d9c3b3e63e4aL1-R35))
* Add JSON marshalling and unmarshalling logic for the
`ResourceProvisioning` and `Resources` fields in the
`zz_generated_models_serde.go` file
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-bc1502ced9e29d6d61dc028d22603e863f59a981bbc54a59879ba3177d8e62e9R624-R625),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-bc1502ced9e29d6d61dc028d22603e863f59a981bbc54a59879ba3177d8e62e9R661-R666),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-bc1502ced9e29d6d61dc028d22603e863f59a981bbc54a59879ba3177d8e62e9R803-R804),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-bc1502ced9e29d6d61dc028d22603e863f59a981bbc54a59879ba3177d8e62e9R836-R841),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-bc1502ced9e29d6d61dc028d22603e863f59a981bbc54a59879ba3177d8e62e9R3274-R3300))
* Add new properties `resourceProvisioning` and `resources` to the
`ContainerProperties` and `ContainerResourceUpdateProperties` schemas in
the `openapi.json` file and reference the
`ContainerResourceProvisioning` and `ResourceReference` schemas
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-ac35cdfa65680d5d2be2d0513a686f4651b9a41eb951d05dcd446bc927090d68R2953-R2963),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-ac35cdfa65680d5d2be2d0513a686f4651b9a41eb951d05dcd446bc927090d68R3015-R3038),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-ac35cdfa65680d5d2be2d0513a686f4651b9a41eb951d05dcd446bc927090d68R3091-R3101))
* Add new function `Test_Render_Manual` to the `render_test.go` file in
the `container` package to test the `Render` function with a container
resource with manual provisioning and a resource reference
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-6f1219f263ab06a1493ac76960e2ab8cbe647e83e926bff7d13988f393334f94R25),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-6f1219f263ab06a1493ac76960e2ab8cbe647e83e926bff7d13988f393334f94R401-R435))
* Modify the `Render` function in the `render.go` file in the
`container` package to populate the `outputResources` variable with the
`Resources` field in the `ContainerProperties` struct and skip the
creation of the container resource if the `ResourceProvisioning` field
is `manual`
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-3da981bf20df07918a646eafcd867d6c95abac1f3aef1ed1b50a29f3f4cc8636R36),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-3da981bf20df07918a646eafcd867d6c95abac1f3aef1ed1b50a29f3f4cc8636R169-R183),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-3da981bf20df07918a646eafcd867d6c95abac1f3aef1ed1b50a29f3f4cc8636L204))
* Modify the `Render` function in the `kubernetes.go` file in the
`handlers` package to return an empty map of computed values and no
error if the `CreateResource` field in the `RenderOptions` struct is nil
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-033dc8a7c9b970cc30f7420ce8cf2f12a26258b276779683ba3f761c481bf0a7R81-R86))
* Modify the `Render` function in the `renderer.go` file in the
`daprextension` package and the `render.go` file in the
`kubernetesmetadata` package to skip the iteration and continue with the
next output resource if the `CreateResource` field in the
`OutputResource` struct is nil
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-a2ffa8fdf3e7cacf68f61fdc82a345456a27dd04bb95d914b1194454b00d1c0aR81-R85),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-99efabd56bb5d297b7f40c7c9958b4b11139710d7149e713ab6ac662d1546cb4R75-R79))
* Refactor the test code in the `container_conversion_test.go` file
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbR124),[link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbL154-R177))
* Remove the `emptyExt` field from the test cases in the
`TestContainerConvertDataModelToVersioned` function as it is no longer
needed
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbR124))
* Replace the `r` variable with the `versioned` variable in the
`TestContainerConvertDataModelToVersioned` function for clarity
([link](https://github.com/radius-project/radius/pull/6423/files?diff=unified&w=0#diff-4183e8fa58766ff3187ebf888b8266b181dd6b4f11a23debac68833bde480edbL154-R177))
  • Loading branch information
rynowak authored Oct 4, 2023
1 parent ec45393 commit 1a7a898
Show file tree
Hide file tree
Showing 25 changed files with 395 additions and 33 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@
* **extensions**: [Extension](#extension)[]: Extensions spec of the resource
* **identity**: [IdentitySettings](#identitysettings): IdentitySettings is the external identity setting.
* **provisioningState**: 'Accepted' | 'Canceled' | 'Deleting' | 'Failed' | 'Provisioning' | 'Succeeded' | 'Updating' (ReadOnly): Provisioning state of the portable resource at the time the operation was called
* **resourceProvisioning**: 'internal' | 'manual': Specifies how the underlying service/resource is provisioned and managed. Available values are 'internal', where Radius manages the lifecycle of the resource internally, and 'manual', where a user manages the resource.
* **resources**: [ResourceReference](#resourcereference)[]: A collection of references to resources associated with the container
* **runtimes**: [RuntimesProperties](#runtimesproperties): The properties for runtime configuration
* **status**: [ResourceStatus](#resourcestatus) (ReadOnly): Status of a resource.

Expand Down Expand Up @@ -309,6 +311,10 @@
* **source**: string (Required): The source of the volume


## ResourceReference
### Properties
* **id**: string (Required): Resource id of an existing resource

## RuntimesProperties
### Properties
* **kubernetes**: [KubernetesRuntimeProperties](#kubernetesruntimeproperties): The runtime configuration properties for Kubernetes
Expand Down
2 changes: 1 addition & 1 deletion hack/bicep-types-radius/generated/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Resources":{"Applications.Core/applications@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":57},"Applications.Core/containers@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":113},"Applications.Core/environments@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":138},"Applications.Core/extenders@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":156},"Applications.Core/gateways@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":177},"Applications.Core/httpRoutes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":191},"Applications.Core/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":214},"Applications.Core/volumes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":251},"Applications.Dapr/pubSubBrokers@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":48},"Applications.Dapr/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":65},"Applications.Dapr/stateStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":83},"Applications.Datastores/mongoDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":49},"Applications.Datastores/redisCaches@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":68},"Applications.Datastores/sqlDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":87},"Applications.Messaging/rabbitMQQueues@2023-10-01-preview":{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":49}},"Functions":{"applications.core/extenders":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":252}]},"applications.core/secretstores":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":258}]},"applications.datastores/mongodatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":89}]},"applications.datastores/rediscaches":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":91}]},"applications.datastores/sqldatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":93}]},"applications.messaging/rabbitmqqueues":{"2023-10-01-preview":[{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":51}]}}}
{"Resources":{"Applications.Core/applications@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":57},"Applications.Core/containers@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":118},"Applications.Core/environments@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":143},"Applications.Core/extenders@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":161},"Applications.Core/gateways@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":182},"Applications.Core/httpRoutes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":196},"Applications.Core/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":219},"Applications.Core/volumes@2023-10-01-preview":{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":256},"Applications.Dapr/pubSubBrokers@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":48},"Applications.Dapr/secretStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":65},"Applications.Dapr/stateStores@2023-10-01-preview":{"RelativePath":"applications/applications.dapr/2023-10-01-preview/types.json","Index":83},"Applications.Datastores/mongoDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":49},"Applications.Datastores/redisCaches@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":68},"Applications.Datastores/sqlDatabases@2023-10-01-preview":{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":87},"Applications.Messaging/rabbitMQQueues@2023-10-01-preview":{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":49}},"Functions":{"applications.core/extenders":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":257}]},"applications.core/secretstores":{"2023-10-01-preview":[{"RelativePath":"applications/applications.core/2023-10-01-preview/types.json","Index":263}]},"applications.datastores/mongodatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":89}]},"applications.datastores/rediscaches":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":91}]},"applications.datastores/sqldatabases":{"2023-10-01-preview":[{"RelativePath":"applications/applications.datastores/2023-10-01-preview/types.json","Index":93}]},"applications.messaging/rabbitmqqueues":{"2023-10-01-preview":[{"RelativePath":"applications/applications.messaging/2023-10-01-preview/types.json","Index":51}]}}}
66 changes: 57 additions & 9 deletions pkg/corerp/api/v20231001preview/container_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,16 @@ func (src *ContainerResource) ConvertTo() (v1.DataModelInterface, error) {
Args: stringSlice(src.Properties.Container.Args),
WorkingDir: to.String(src.Properties.Container.WorkingDir),
},
Extensions: extensions,
Runtimes: toRuntimeProperties(src.Properties.Runtimes),
Extensions: extensions,
Runtimes: toRuntimePropertiesDataModel(src.Properties.Runtimes),
ResourceProvisioning: toContainerResourceProvisioningDataModel(src.Properties.ResourceProvisioning),
Resources: toResourceReferencesDataModel(src.Properties.Resources),
},
}

if src.Properties.Identity != nil {
converted.Properties.Identity = &rpv1.IdentitySettings{
Kind: toIdentityKind(src.Properties.Identity.Kind),
Kind: toIdentityKindDataModel(src.Properties.Identity.Kind),
OIDCIssuer: to.String(src.Properties.Identity.OidcIssuer),
Resource: to.String(src.Properties.Identity.Resource),
}
Expand Down Expand Up @@ -241,7 +243,7 @@ func (dst *ContainerResource) ConvertFrom(src v1.DataModelInterface) error {
dst.Tags = *to.StringMapPtr(c.Tags)
dst.Properties = &ContainerProperties{
Status: &ResourceStatus{
OutputResources: toOutputResources(c.Properties.Status.OutputResources),
OutputResources: toOutputResourcesDataModel(c.Properties.Status.OutputResources),
},
ProvisioningState: fromProvisioningStateDataModel(c.InternalMetadata.AsyncProvisioningState),
Application: to.Ptr(c.Properties.Application),
Expand All @@ -258,9 +260,11 @@ func (dst *ContainerResource) ConvertFrom(src v1.DataModelInterface) error {
Args: to.SliceOfPtrs(c.Properties.Container.Args...),
WorkingDir: to.Ptr(c.Properties.Container.WorkingDir),
},
Extensions: extensions,
Identity: identity,
Runtimes: fromRuntimeProperties(c.Properties.Runtimes),
Extensions: extensions,
Identity: identity,
Runtimes: fromRuntimePropertiesDataModel(c.Properties.Runtimes),
Resources: fromResourceReferencesDataModel(c.Properties.Resources),
ResourceProvisioning: fromContainerResourceProvisioningDataModel(c.Properties.ResourceProvisioning),
}

return nil
Expand Down Expand Up @@ -504,7 +508,7 @@ func fromManagedStoreDataModel(managedStore datamodel.ManagedStore) *ManagedStor
return &m
}

func toRuntimeProperties(runtime *RuntimesProperties) *datamodel.RuntimeProperties {
func toRuntimePropertiesDataModel(runtime *RuntimesProperties) *datamodel.RuntimeProperties {
if runtime == nil {
return nil
}
Expand All @@ -528,7 +532,7 @@ func toRuntimeProperties(runtime *RuntimesProperties) *datamodel.RuntimeProperti
return r
}

func fromRuntimeProperties(runtime *datamodel.RuntimeProperties) *RuntimesProperties {
func fromRuntimePropertiesDataModel(runtime *datamodel.RuntimeProperties) *RuntimesProperties {
if runtime == nil {
return nil
}
Expand All @@ -548,6 +552,50 @@ func fromRuntimeProperties(runtime *datamodel.RuntimeProperties) *RuntimesProper
return r
}

func toResourceReferencesDataModel(r []*ResourceReference) []datamodel.ResourceReference {
result := []datamodel.ResourceReference{}
for _, rr := range r {
result = append(result, datamodel.ResourceReference{ID: to.String(rr.ID)})
}

return result
}

func fromResourceReferencesDataModel(r []datamodel.ResourceReference) []*ResourceReference {
result := []*ResourceReference{}
for _, rr := range r {
result = append(result, &ResourceReference{ID: to.Ptr(rr.ID)})
}

return result
}

func toContainerResourceProvisioningDataModel(r *ContainerResourceProvisioning) datamodel.ContainerResourceProvisioning {
if r == nil {
return datamodel.ContainerResourceProvisioningInternal
}

switch *r {
case ContainerResourceProvisioningInternal:
return datamodel.ContainerResourceProvisioningInternal
case ContainerResourceProvisioningManual:
return datamodel.ContainerResourceProvisioningManual
default:
return datamodel.ContainerResourceProvisioningInternal
}
}

func fromContainerResourceProvisioningDataModel(r datamodel.ContainerResourceProvisioning) *ContainerResourceProvisioning {
switch r {
case datamodel.ContainerResourceProvisioningInternal:
return to.Ptr(ContainerResourceProvisioningInternal)
case datamodel.ContainerResourceProvisioningManual:
return to.Ptr(ContainerResourceProvisioningManual)
default:
return nil
}
}

func toPermissionDataModel(rbac *VolumePermission) datamodel.VolumePermission {
if rbac == nil {
return datamodel.VolumePermissionRead
Expand Down
34 changes: 26 additions & 8 deletions pkg/corerp/api/v20231001preview/container_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func TestContainerConvertVersionedToDataModel(t *testing.T) {
err: nil,
emptyExt: true,
},
{
filename: "containerresource-manual.json",
err: nil,
emptyExt: true,
},
}

for _, tt := range conversionTests {
Expand All @@ -79,6 +84,13 @@ func TestContainerConvertVersionedToDataModel(t *testing.T) {
require.Equal(t, "container0", ct.Name)
require.Equal(t, "Applications.Core/containers", ct.Type)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/applications/app0", ct.Properties.Application)

if tt.filename == "containerresource-manual.json" {
require.Equal(t, datamodel.ContainerResourceProvisioningManual, ct.Properties.ResourceProvisioning)
require.Equal(t, []datamodel.ResourceReference{{ID: "/planes/test/local/providers/Test.Namespace/testResources/test-resource"}}, ct.Properties.Resources)
return
}

val, ok := ct.Properties.Connections["inventory"]
require.True(t, ok)
require.Equal(t, "inventory_route_id", val.Source)
Expand Down Expand Up @@ -109,6 +121,7 @@ func TestContainerConvertVersionedToDataModel(t *testing.T) {
require.Equal(t, *r.Properties.Runtimes.Kubernetes.Base, ct.Properties.Runtimes.Kubernetes.Base)
require.Equal(t, "{\"containers\":[{\"name\":\"sidecar\"}],\"hostNetwork\":true}", ct.Properties.Runtimes.Kubernetes.Pod)
}

}
})
}
Expand All @@ -118,22 +131,21 @@ func TestContainerConvertDataModelToVersioned(t *testing.T) {
conversionTests := []struct {
filename string
err error
emptyExt bool
}{
{
filename: "containerresourcedatamodel.json",
err: nil,
emptyExt: false,
},
{
filename: "containerresourcedatamodel-runtime.json",
err: nil,
emptyExt: false,
},
{
filename: "containerresourcedatamodelemptyext.json",
err: nil,
emptyExt: true,
},
{
filename: "containerresourcedatamodel-manual.json",
},
}

Expand All @@ -151,18 +163,24 @@ func TestContainerConvertDataModelToVersioned(t *testing.T) {
if tt.err != nil {
require.ErrorIs(t, err, tt.err)
} else {
// assert
require.NoError(t, err)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/Applications.Core/containers/container0", r.ID)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/Applications.Core/containers/container0", *versioned.ID)
require.Equal(t, "container0", r.Name)
require.Equal(t, "Applications.Core/containers", r.Type)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/applications/app0", r.Properties.Application)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/applications/app0", *versioned.Properties.Application)

if tt.filename == "containerresourcedatamodel-manual.json" {
require.Equal(t, ContainerResourceProvisioning("manual"), *versioned.Properties.ResourceProvisioning)
require.Equal(t, []*ResourceReference{{ID: to.Ptr("/planes/test/local/providers/Test.Namespace/testResources/test-resource")}}, versioned.Properties.Resources)
return
}

val, ok := r.Properties.Connections["inventory"]
require.True(t, ok)
require.Equal(t, "inventory_route_id", val.Source)
require.Equal(t, "azure", string(val.IAM.Kind))
require.Equal(t, "read", val.IAM.Roles[0])
require.Equal(t, "radius.azurecr.io/webapptutorial-todoapp", r.Properties.Container.Image)
require.Equal(t, "radius.azurecr.io/webapptutorial-todoapp", *versioned.Properties.Container.Image)
require.Equal(t, resourcetypeutil.MustPopulateResourceStatus(&ResourceStatus{}), versioned.Properties.Status)
require.Equal(t, "kubernetesMetadata", *versioned.Properties.Extensions[2].GetExtension().Kind)
require.Equal(t, 3, len(versioned.Properties.Extensions))
Expand Down
2 changes: 1 addition & 1 deletion pkg/corerp/api/v20231001preview/environment_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func toEnvironmentComputeDataModel(h EnvironmentComputeClassification) (*rpv1.En
var identity *rpv1.IdentitySettings
if v.Identity != nil {
identity = &rpv1.IdentitySettings{
Kind: toIdentityKind(v.Identity.Kind),
Kind: toIdentityKindDataModel(v.Identity.Kind),
Resource: to.String(v.Identity.Resource),
OIDCIssuer: to.String(v.Identity.OidcIssuer),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/corerp/api/v20231001preview/extender_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (dst *ExtenderResource) ConvertFrom(src v1.DataModelInterface) error {
dst.Tags = *to.StringMapPtr(extender.Tags)
dst.Properties = &ExtenderProperties{
Status: &ResourceStatus{
OutputResources: toOutputResources(extender.Properties.Status.OutputResources),
OutputResources: toOutputResourcesDataModel(extender.Properties.Status.OutputResources),
},
ProvisioningState: fromProvisioningStateDataModel(extender.InternalMetadata.AsyncProvisioningState),
Environment: to.Ptr(extender.Properties.Environment),
Expand Down
2 changes: 1 addition & 1 deletion pkg/corerp/api/v20231001preview/gateway_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (dst *GatewayResource) ConvertFrom(src v1.DataModelInterface) error {
dst.Tags = *to.StringMapPtr(g.Tags)
dst.Properties = &GatewayProperties{
Status: &ResourceStatus{
OutputResources: toOutputResources(g.Properties.Status.OutputResources),
OutputResources: toOutputResourcesDataModel(g.Properties.Status.OutputResources),
},
ProvisioningState: fromProvisioningStateDataModel(g.InternalMetadata.AsyncProvisioningState),
Application: to.Ptr(g.Properties.Application),
Expand Down
2 changes: 1 addition & 1 deletion pkg/corerp/api/v20231001preview/httproute_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (dst *HTTPRouteResource) ConvertFrom(src v1.DataModelInterface) error {
dst.Tags = *to.StringMapPtr(route.Tags)
dst.Properties = &HTTPRouteProperties{
Status: &ResourceStatus{
OutputResources: toOutputResources(route.Properties.Status.OutputResources),
OutputResources: toOutputResourcesDataModel(route.Properties.Status.OutputResources),
},
ProvisioningState: fromProvisioningStateDataModel(route.InternalMetadata.AsyncProvisioningState),
Application: to.Ptr(route.Properties.Application),
Expand Down
2 changes: 1 addition & 1 deletion pkg/corerp/api/v20231001preview/secretstore_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (dst *SecretStoreResource) ConvertFrom(src v1.DataModelInterface) error {
dst.Tags = *to.StringMapPtr(ss.Tags)
dst.Properties = &SecretStoreProperties{
Status: &ResourceStatus{
OutputResources: toOutputResources(ss.Properties.Status.OutputResources),
OutputResources: toOutputResourcesDataModel(ss.Properties.Status.OutputResources),
},
ProvisioningState: fromProvisioningStateDataModel(ss.InternalMetadata.AsyncProvisioningState),
Application: to.Ptr(ss.Properties.Application),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/Applications.Core/containers/container0",
"name": "container0",
"type": "Applications.Core/containers",
"properties": {
"application": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/applications/app0",
"container": {
"image": "none"
},
"resourceProvisioning": "manual",
"resources": [
{
"id": "/planes/test/local/providers/Test.Namespace/testResources/test-resource"
}
]
}
}
Loading

0 comments on commit 1a7a898

Please sign in to comment.