Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBCP - updates to container,env,app datamodel #4448

Merged
merged 15 commits into from
Nov 15, 2022

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,30 @@
## ApplicationProperties
### Properties
* **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.

## ApplicationExtension
* **Discriminator**: kind

### Base Properties
### ApplicationKubernetesMetadataExtension
#### Properties
* **annotations**: [ApplicationKubernetesMetadataExtensionAnnotations](#applicationkubernetesmetadataextensionannotations): Annotations to be applied to the Kubernetes resources output by the resource
* **kind**: 'kubernetesMetadata' (Required): Specifies the extensions of a resource.
* **labels**: [ApplicationKubernetesMetadataExtensionLabels](#applicationkubernetesmetadataextensionlabels): Labels to be applied to the Kubernetes resources output by the resource


## ApplicationKubernetesMetadataExtensionAnnotations
### Properties
### Additional Properties
* **Additional Properties Type**: string

## ApplicationKubernetesMetadataExtensionLabels
### Properties
### Additional Properties
* **Additional Properties Type**: string

## SystemData
### Properties
* **createdAt**: string: The timestamp of resource creation (UTC).
Expand All @@ -97,7 +119,7 @@
* **connections**: [ContainerPropertiesConnections](#containerpropertiesconnections): Dictionary of <ConnectionProperties>
* **container**: [Container](#container) (Required): Definition of a container.
* **environment**: string: The resource id of the environment linked to the resource
* **extensions**: [Extension](#extension)[]: Extensions spec of the resource
* **extensions**: [ContainerExtension](#containerextension)[]: Extensions spec of the resource
* **identity**: [IdentitySettings](#identitysettings)
* **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.
Expand Down Expand Up @@ -199,7 +221,7 @@
* **source**: string (Required): The source of the volume


## Extension
## ContainerExtension
* **Discriminator**: kind

### Base Properties
Expand All @@ -212,12 +234,28 @@
* **protocol**: 'TCP' | 'UDP' | 'grpc' | 'http': Protocol in use by the port
* **provides**: string: Specifies the resource id of a dapr.io.InvokeHttpRoute that can route traffic to this resource.

### ContainerKubernetesMetadataExtension
#### Properties
* **annotations**: [ContainerKubernetesMetadataExtensionAnnotations](#containerkubernetesmetadataextensionannotations): Annotations to be applied to the Kubernetes resources output by the resource
* **kind**: 'kubernetesMetadata' (Required): Specifies the extensions of a resource.
* **labels**: [ContainerKubernetesMetadataExtensionLabels](#containerkubernetesmetadataextensionlabels): Labels to be applied to the Kubernetes resources output by the resource

### ManualScalingExtension
#### Properties
* **kind**: 'manualScaling' (Required): Specifies the extensions of a resource.
* **replicas**: int: Replica count.


## ContainerKubernetesMetadataExtensionAnnotations
### Properties
### Additional Properties
* **Additional Properties Type**: string

## ContainerKubernetesMetadataExtensionLabels
### Properties
### Additional Properties
* **Additional Properties Type**: string

## IdentitySettings
### Properties
* **kind**: 'azure.com.workload' | 'undefined' (Required): Configuration for supported external identity providers
Expand All @@ -236,6 +274,7 @@
## EnvironmentProperties
### Properties
* **compute**: [EnvironmentCompute](#environmentcompute) (Required): Compute resource used by application environment resource.
* **extensions**: [EnvironmentExtension](#environmentextension)[]: Extensions spec of the resource
* **providers**: [Providers](#providers): Cloud providers configuration
* **provisioningState**: 'Accepted' | 'Canceled' | 'Deleting' | 'Failed' | 'Provisioning' | 'Succeeded' | 'Updating' (ReadOnly): Provisioning state of the resource at the time the operation was called.
* **recipes**: [EnvironmentPropertiesRecipes](#environmentpropertiesrecipes): Dictionary of <EnvironmentRecipeProperties>
Expand All @@ -253,6 +292,27 @@
* **namespace**: string (Required): The namespace to use for the environment.


## EnvironmentExtension
* **Discriminator**: kind

### Base Properties
### EnvironmentKubernetesMetadataExtension
#### Properties
* **annotations**: [EnvironmentKubernetesMetadataExtensionAnnotations](#environmentkubernetesmetadataextensionannotations): Annotations to be applied to the Kubernetes resources output by the resource
* **kind**: 'kubernetesMetadata' (Required): Specifies the extensions of a resource.
* **labels**: [EnvironmentKubernetesMetadataExtensionLabels](#environmentkubernetesmetadataextensionlabels): Labels to be applied to the Kubernetes resources output by the resource


## EnvironmentKubernetesMetadataExtensionAnnotations
### Properties
### Additional Properties
* **Additional Properties Type**: string

## EnvironmentKubernetesMetadataExtensionLabels
### Properties
### Additional Properties
* **Additional Properties Type**: string

## Providers
### Properties
* **azure**: [ProvidersAzure](#providersazure): Azure cloud provider configuration
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":43},"Applications.Core/applications@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":57},"Applications.Core/httpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":73},"Applications.Core/gateways@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":91},"Applications.Core/containers@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":152},"Applications.Core/volumes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":189},"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":64},"Applications.Link/sqlDatabases@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":84},"Applications.Link/redisCaches@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":105},"Applications.Link/rabbitMQMessageQueues@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":124},"Applications.Link/daprSecretStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":143},"Applications.Link/daprInvokeHttpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":157},"Applications.Link/daprStateStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":181},"Applications.Link/extenders@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":196}},"Functions":{"applications.link/mongodatabases":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":197}]},"applications.link/rediscaches":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":198}]},"applications.link/rabbitmqmessagequeues":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":199}]},"applications.link/extenders":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":201}]}}}
{"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":69},"Applications.Core/httpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":85},"Applications.Core/gateways@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":103},"Applications.Core/containers@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":168},"Applications.Core/volumes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":205},"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":64},"Applications.Link/sqlDatabases@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":84},"Applications.Link/redisCaches@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":105},"Applications.Link/rabbitMQMessageQueues@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":124},"Applications.Link/daprSecretStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":143},"Applications.Link/daprInvokeHttpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":157},"Applications.Link/daprStateStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":181},"Applications.Link/extenders@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":196}},"Functions":{"applications.link/mongodatabases":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":197}]},"applications.link/rediscaches":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":198}]},"applications.link/rabbitmqmessagequeues":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":199}]},"applications.link/extenders":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":201}]}}}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ func (src *ApplicationResource) ConvertTo() (conv.DataModelInterface, error) {
},
},
}

var extensions []datamodel.Extension
if src.Properties.Extensions != nil {
for _, e := range src.Properties.Extensions {
extensions = append(extensions, toAppExtensionDataModel(e))
}
converted.Properties.Extensions = extensions
}

return converted, nil
}

Expand All @@ -60,5 +69,48 @@ func (dst *ApplicationResource) ConvertFrom(src conv.DataModelInterface) error {
Environment: to.StringPtr(app.Properties.Environment),
}

var extensions []ApplicationExtensionClassification
if app.Properties.Extensions != nil {
for _, e := range app.Properties.Extensions {
extensions = append(extensions, fromAppExtensionClassificationDataModel(e))
}
dst.Properties.Extensions = extensions
}

return nil
}

// fromAppExtensionClassificationDataModel: Converts from base datamodel to versioned datamodel
func fromAppExtensionClassificationDataModel(e datamodel.Extension) ApplicationExtensionClassification {
switch e.Kind {
case datamodel.KubernetesMetadata:
var ann, lbl = getFromExtensionClassificationFields(e)
converted := ApplicationKubernetesMetadataExtension{
Kind: to.StringPtr(string(e.Kind)),
Annotations: *to.StringMapPtr(ann),
Labels: *to.StringMapPtr(lbl),
}

return converted.GetApplicationExtension()
}

return nil
}

// toAppExtensionDataModel: Converts from versioned datamodel to base datamodel
func toAppExtensionDataModel(e ApplicationExtensionClassification) datamodel.Extension {
switch c := e.(type) {
case *ApplicationKubernetesMetadataExtension:

converted := datamodel.Extension{
Kind: datamodel.KubernetesMetadata,
lakshmimsft marked this conversation as resolved.
Show resolved Hide resolved
KubernetesMetadata: &datamodel.BaseKubernetesMetadataExtension{
Annotations: to.StringMap(c.Annotations),
Labels: to.StringMap(c.Labels),
},
}
return converted
}

return datamodel.Extension{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,106 @@ import (
)

func TestApplicationConvertVersionedToDataModel(t *testing.T) {
// arrange
rawPayload := radiustesting.ReadFixture("applicationresource.json")
r := &ApplicationResource{}
err := json.Unmarshal(rawPayload, r)
require.NoError(t, err)

// act
dm, err := r.ConvertTo()
conversionTests := []struct {
filename string
err error
emptyExt bool
}{
{
filename: "applicationresource.json",
err: nil,
emptyExt: false,
},
{
filename: "applicationresourceemptyext.json",
err: nil,
emptyExt: true,
},
{
filename: "applicationresourceemptyext2.json",
err: nil,
emptyExt: true,
},
}

for _, tt := range conversionTests {
t.Run(tt.filename, func(t *testing.T) {
rawPayload := radiustesting.ReadFixture(tt.filename)
r := &ApplicationResource{}
err := json.Unmarshal(rawPayload, r)
require.NoError(t, err)

// assert
require.NoError(t, err)
ct := dm.(*datamodel.Application)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/Applications.Core/applications/app0", ct.ID)
require.Equal(t, "app0", ct.Name)
require.Equal(t, "Applications.Core/applications", ct.Type)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/environments/env0", ct.Properties.Environment)
require.Equal(t, "2022-03-15-privatepreview", ct.InternalMetadata.UpdatedAPIVersion)
// act
dm, err := r.ConvertTo()

if tt.err != nil {
require.ErrorIs(t, err, tt.err)
} else {
// assert
require.NoError(t, err)
ct := dm.(*datamodel.Application)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/Applications.Core/applications/app0", ct.ID)
require.Equal(t, "app0", ct.Name)
require.Equal(t, "Applications.Core/applications", ct.Type)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/testGroup/providers/Applications.Core/environments/env0", ct.Properties.Environment)
require.Equal(t, "2022-03-15-privatepreview", ct.InternalMetadata.UpdatedAPIVersion)
if tt.emptyExt {
require.Equal(t, getTestKubernetesEmptyMetadataExtensions(t), ct.Properties.Extensions)
} else {
require.Equal(t, getTestKubernetesMetadataExtensions(t), ct.Properties.Extensions)
}
}
})
}

}

func TestApplicationConvertDataModelToVersioned(t *testing.T) {
// arrange
rawPayload := radiustesting.ReadFixture("applicationresourcedatamodel.json")
r := &datamodel.Application{}
err := json.Unmarshal(rawPayload, r)
require.NoError(t, err)
conversionTests := []struct {
filename string
err error
emptyExt bool
}{
{
filename: "applicationresourcedatamodel.json",
err: nil,
emptyExt: false,
},
{
filename: "applicationresourcedatamodelemptyext.json",
err: nil,
emptyExt: true,
},
}

// act
versioned := &ApplicationResource{}
err = versioned.ConvertFrom(r)
for _, tt := range conversionTests {
t.Run(tt.filename, func(t *testing.T) {
rawPayload := radiustesting.ReadFixture(tt.filename)
r := &datamodel.Application{}
err := json.Unmarshal(rawPayload, r)
require.NoError(t, err)

// assert
require.NoError(t, err)
require.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/radius-test-rg/providers/Applications.Core/applications/app0", r.ID)
require.Equal(t, "app0", r.Name)
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)
// act
versioned := &ApplicationResource{}
err = versioned.ConvertFrom(r)

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/applications/app0", r.ID)
require.Equal(t, "app0", r.Name)
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)
if !tt.emptyExt {
require.Equal(t, 1, len(versioned.Properties.Extensions))
}
}
})
}
}

func TestApplicationConvertFromValidation(t *testing.T) {
Expand Down
Loading