Skip to content

Commit

Permalink
Rename app-scoped namespace extension kind and populate status.compute (
Browse files Browse the repository at this point in the history
#4832)

# Description

- Rename kuberentesNamespaceOverride to kuberentesNamespace
- Fix datamodel converter
- separate out populateKubernetesNamespace and improve test coverage
- populate status.compute

```json
{
    "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/radius-test-rg/providers/applications.core/applications/defaultapp",
    "location": "global",
    "name": "defaultapp",
    "properties": {
        "environment": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-RG/providers/Applications.Core/environments/default",
        "extensions": [
            {
                "kind": "kubernetesNamespace",
                "namespace": "myenvapp"
            }
        ],
        "provisioningState": "Succeeded",
        "status": {
            "compute": {
                "kind": "kubernetes",
                "namespace": "myenvapp"
            }
        }
    },
    "type": "applications.core/applications"
}
```

## Issue reference

<!--
We strive to have all PR being opened based on an issue, where the
problem or feature have been discussed prior to implementation.
-->

#3740 

## Checklist

Please make sure you've completed the relevant tasks for this PR, out of
the following list:

* [x] Code compiles correctly
* [x] Adds necessary unit tests for change
* [ ] Adds necessary E2E tests for change
* [x] Unit tests passing
* [ ] Extended the documentation / Created issue for it
  • Loading branch information
youngbupark authored Dec 8, 2022
1 parent 83e81c6 commit bf211ce
Show file tree
Hide file tree
Showing 42 changed files with 765 additions and 440 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
* **environment**: string (Required): The resource id of the environment linked to application.
* **extensions**: [ApplicationExtension](#applicationextension)[]: Extensions spec of the resource
* **provisioningState**: 'Accepted' | 'Canceled' | 'Deleting' | 'Failed' | 'Provisioning' | 'Succeeded' | 'Updating' (ReadOnly): Provisioning state of the resource at the time the operation was called.
* **status**: [ResourceStatus](#resourcestatus) (ReadOnly): Status of a resource.

## ApplicationExtension
* **Discriminator**: kind
Expand All @@ -90,7 +91,7 @@

### ApplicationKubernetesNamespaceExtension
#### Properties
* **kind**: 'kubernetesNamespaceOverride' (Required): Specifies the extensions of a resource.
* **kind**: 'kubernetesNamespace' (Required): Specifies the extensions of a resource.
* **namespace**: string (Required): The Kubernetes namespace to use for this application.


Expand All @@ -104,6 +105,29 @@
### Additional Properties
* **Additional Properties Type**: string

## ResourceStatus
### Properties
* **compute**: [EnvironmentCompute](#environmentcompute): Compute resource used by application environment resource.
* **outputResources**: any[]: Array of AnyObject

## EnvironmentCompute
* **Discriminator**: kind

### Base Properties
* **identity**: [IdentitySettings](#identitysettings)
* **resourceId**: string: The resource id of the compute resource for application environment.
### KubernetesCompute
#### Properties
* **kind**: 'kubernetes' (Required): Type of compute resource.
* **namespace**: string (Required): The namespace to use for the environment.


## IdentitySettings
### Properties
* **kind**: 'azure.com.workload' | 'undefined' (Required): Configuration for supported external identity providers
* **oidcIssuer**: string: The URI for your compute platform's OIDC issuer
* **resource**: string: The resource ID of the provisioned identity

## SystemData
### Properties
* **createdAt**: string: The timestamp of resource creation (UTC).
Expand Down Expand Up @@ -261,16 +285,6 @@
### Additional Properties
* **Additional Properties Type**: string

## IdentitySettings
### Properties
* **kind**: 'azure.com.workload' | 'undefined' (Required): Configuration for supported external identity providers
* **oidcIssuer**: string: The URI for your compute platform's OIDC issuer
* **resource**: string: The resource ID of the provisioned identity

## ResourceStatus
### Properties
* **outputResources**: any[]: Array of AnyObject

## TrackedResourceTags
### Properties
### Additional Properties
Expand All @@ -285,18 +299,6 @@
* **recipes**: [EnvironmentPropertiesRecipes](#environmentpropertiesrecipes): Dictionary of <EnvironmentRecipeProperties>
* **useDevRecipes**: bool: Flag to use radius owned recipes.

## EnvironmentCompute
* **Discriminator**: kind

### Base Properties
* **identity**: [IdentitySettings](#identitysettings)
* **resourceId**: string: The resource id of the compute resource for application environment.
### KubernetesCompute
#### Properties
* **kind**: 'kubernetes' (Required): Type of compute resource.
* **namespace**: string (Required): The namespace to use for the environment.


## EnvironmentExtension
* **Discriminator**: kind

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/environments@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":49},"Applications.Core/applications@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":71},"Applications.Core/httpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":87},"Applications.Core/gateways@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":105},"Applications.Core/containers@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":170},"Applications.Core/volumes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":207},"Applications.Link/mongoDatabases@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":42},"Applications.Link/daprPubSubBrokers@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":62},"Applications.Link/sqlDatabases@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":82},"Applications.Link/redisCaches@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":103},"Applications.Link/rabbitMQMessageQueues@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":122},"Applications.Link/daprSecretStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":140},"Applications.Link/daprInvokeHttpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":154},"Applications.Link/daprStateStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":174},"Applications.Link/extenders@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":189}},"Functions":{"applications.link/mongodatabases":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":190}]},"applications.link/rediscaches":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":191}]},"applications.link/rabbitmqmessagequeues":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":192}]},"applications.link/extenders":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":194}]}}}
{"Resources":{"Applications.Core/environments@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":49},"Applications.Core/applications@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":73},"Applications.Core/httpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":87},"Applications.Core/gateways@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":105},"Applications.Core/containers@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":170},"Applications.Core/volumes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":207},"Applications.Link/mongoDatabases@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":42},"Applications.Link/daprPubSubBrokers@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":62},"Applications.Link/sqlDatabases@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":82},"Applications.Link/redisCaches@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":103},"Applications.Link/rabbitMQMessageQueues@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":122},"Applications.Link/daprSecretStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":140},"Applications.Link/daprInvokeHttpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":154},"Applications.Link/daprStateStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":174},"Applications.Link/extenders@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":189}},"Functions":{"applications.link/mongodatabases":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":190}]},"applications.link/rediscaches":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":191}]},"applications.link/rabbitmqmessagequeues":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":192}]},"applications.link/extenders":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":194}]}}}
37 changes: 10 additions & 27 deletions pkg/corerp/api/v20220315privatepreview/application_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (dst *ApplicationResource) ConvertFrom(src conv.DataModelInterface) error {
dst.Properties = &ApplicationProperties{
ProvisioningState: fromProvisioningStateDataModel(app.InternalMetadata.AsyncProvisioningState),
Environment: to.StringPtr(app.Properties.Environment),
Status: &ResourceStatus{
Compute: fromEnvironmentComputeDataModel(app.Properties.Status.Compute),
},
}

var extensions []ApplicationExtensionClassification
Expand All @@ -89,23 +92,16 @@ func fromAppExtensionClassificationDataModel(e datamodel.Extension) ApplicationE
switch e.Kind {
case datamodel.KubernetesMetadata:
var ann, lbl = getFromExtensionClassificationFields(e)
converted := ApplicationKubernetesMetadataExtension{
return &ApplicationKubernetesMetadataExtension{
Kind: to.StringPtr(string(e.Kind)),
Annotations: *to.StringMapPtr(ann),
Labels: *to.StringMapPtr(lbl),
}

return converted.GetApplicationExtension()

case datamodel.KubernetesNamespaceOverride:
var namespace = getFromExtensionNamespace(e)
converted := ApplicationKubernetesNamespaceExtension{
case datamodel.KubernetesNamespaceExtension:
return &ApplicationKubernetesNamespaceExtension{
Kind: to.StringPtr(string(e.Kind)),
Namespace: &namespace,
Namespace: to.StringPtr(e.KubernetesNamespace.Namespace),
}

return converted.GetApplicationExtension()

}

return nil
Expand All @@ -122,30 +118,17 @@ func toAppExtensionDataModel(e ApplicationExtensionClassification) *datamodel.Ex
Labels: to.StringMap(c.Labels),
},
}

case *ApplicationKubernetesNamespaceExtension:
if c.Namespace == nil || *c.Namespace == "" {
return nil
}
return &datamodel.Extension{
Kind: datamodel.KubernetesNamespaceOverride,
KubernetesNamespaceOverride: &datamodel.KubeNamespaceOverrideExtension{
Namespace: *c.Namespace,
Kind: datamodel.KubernetesNamespaceExtension,
KubernetesNamespace: &datamodel.KubeNamespaceExtension{
Namespace: to.String(c.Namespace),
},
}
}

return nil
}

func getFromExtensionNamespace(e datamodel.Extension) string {
var namespace string

if e.KubernetesNamespaceOverride != nil {
if e.KubernetesNamespaceOverride.Namespace != "" {
namespace = e.KubernetesNamespaceOverride.Namespace
}
}

return namespace
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
)

func TestApplicationConvertVersionedToDataModel(t *testing.T) {

conversionTests := []struct {
filename string
err error
Expand Down Expand Up @@ -63,7 +62,9 @@ func TestApplicationConvertVersionedToDataModel(t *testing.T) {
if tt.emptyExt {
require.Equal(t, getTestKubernetesEmptyMetadataExtensions(t), ct.Properties.Extensions)
} else {
require.Equal(t, getTestKubernetesMetadataAppExtensions(t), ct.Properties.Extensions)
exts := getTestKubernetesMetadataExtensions(t)
exts = append(exts, datamodel.Extension{Kind: datamodel.KubernetesNamespaceExtension, KubernetesNamespace: &datamodel.KubeNamespaceExtension{Namespace: "app0-ns"}})
require.Equal(t, exts, ct.Properties.Extensions)
}
}
})
Expand All @@ -82,11 +83,6 @@ func TestApplicationConvertDataModelToVersioned(t *testing.T) {
err: nil,
emptyExt: false,
},
{
filename: "applicationresourcedatamodelemptyext.json",
err: nil,
emptyExt: true,
},
}

for _, tt := range conversionTests {
Expand All @@ -110,11 +106,8 @@ func TestApplicationConvertDataModelToVersioned(t *testing.T) {
require.Equal(t, "Applications.Core/applications", r.Type)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/environments/env0", r.Properties.Environment)
require.Equal(t, "kubernetesMetadata", *versioned.Properties.Extensions[0].GetExtension().Kind)
require.Equal(t, "kubernetesNamespaceOverride", *versioned.Properties.Extensions[1].GetExtension().Kind)
if !tt.emptyExt {
require.Equal(t, "kubernetesNamespaceOverride", *versioned.Properties.Extensions[1].GetExtension().Kind)
require.Equal(t, 2, len(versioned.Properties.Extensions))
}
require.Equal(t, "kubernetesNamespace", *versioned.Properties.Extensions[1].GetExtension().Kind)
require.Equal(t, "app0-ns", *(versioned.Properties.Status.Compute.(*KubernetesCompute).Namespace))
}
})
}
Expand All @@ -135,14 +128,3 @@ func TestApplicationConvertFromValidation(t *testing.T) {
require.ErrorAs(t, tc.err, &err)
}
}

func getTestKubernetesMetadataAppExtensions(t *testing.T) []datamodel.Extension {
extensions := append(getTestKubernetesMetadataExtensions(t), datamodel.Extension{
Kind: datamodel.KubernetesNamespaceOverride,
KubernetesNamespaceOverride: &datamodel.KubeNamespaceOverrideExtension{
Namespace: "app0-ns",
},
})

return extensions
}
Loading

0 comments on commit bf211ce

Please sign in to comment.