diff --git a/api/v1alpha1/cosmosdb_types.go b/api/v1alpha1/cosmosdb_types.go index e483810ba31..db276801196 100644 --- a/api/v1alpha1/cosmosdb_types.go +++ b/api/v1alpha1/cosmosdb_types.go @@ -45,9 +45,17 @@ type CosmosDBProperties struct { // DatabaseAccountOfferType - The offer type for the Cosmos DB database account. DatabaseAccountOfferType CosmosDBDatabaseAccountOfferType `json:"databaseAccountOfferType,omitempty"` // IsVirtualNetworkFilterEnabled - Flag to indicate whether to enable/disable Virtual Network ACL rules. - IsVirtualNetworkFilterEnabled bool `json:"isVirtualNetworkFilterEnabled,omitempty"` - EnableMultipleWriteLocations bool `json:"enableMultipleWriteLocations,omitempty"` - MongoDBVersion string `json:"mongoDBVersion,omitempty"` + IsVirtualNetworkFilterEnabled bool `json:"isVirtualNetworkFilterEnabled,omitempty"` + EnableMultipleWriteLocations bool `json:"enableMultipleWriteLocations,omitempty"` + MongoDBVersion string `json:"mongoDBVersion,omitempty"` + Capabilities *[]Capability `json:"capabilities,omitempty"` +} + +// Capability cosmos DB capability object +type Capability struct { + //Name *CosmosCapability `json:"name,omitempty"` + // +kubebuilder:validation:Enum=EnableCassandra;EnableTable;EnableGremlin;EnableMongo; + Name *string `json:"name,omitempty"` } // +kubebuilder:validation:Enum=Standard diff --git a/config/samples/azure_v1alpha1_cosmosdb.yaml b/config/samples/azure_v1alpha1_cosmosdb.yaml index e4b857a7a66..32287131ad0 100644 --- a/config/samples/azure_v1alpha1_cosmosdb.yaml +++ b/config/samples/azure_v1alpha1_cosmosdb.yaml @@ -10,6 +10,13 @@ spec: databaseAccountOfferType: Standard enableMultipleWriteLocations: false + # Optionally set the capabilities name to the following options: (the default is SQL) + # "EnableCassandra", "EnableTable", "EnableGremlin", "EnableMongo" + # NOTE: If using "EnableMongo" kind must be set to MongoDB for this to take effect + #capabilities: + # - name: "EnableCassandra" + + # optionally set the mongoDBVersion to "3.2" or "3.6", if omitted the default is "3.2" # NOTE: kind must be set to MongoDB for this to take effect # mongoDBVersion: "3.6" diff --git a/pkg/resourcemanager/cosmosdbs/cosmosdb.go b/pkg/resourcemanager/cosmosdbs/cosmosdb.go index 8665da4084b..ccbcd0978e1 100644 --- a/pkg/resourcemanager/cosmosdbs/cosmosdb.go +++ b/pkg/resourcemanager/cosmosdbs/cosmosdb.go @@ -59,9 +59,12 @@ func (*AzureCosmosDBManager) CreateOrUpdateCosmosDB( vnetEnabled := bool(properties.IsVirtualNetworkFilterEnabled) var capabilities []documentdb.Capability - if dbKind == documentdb.MongoDB && properties.MongoDBVersion == "3.6" { - capabilities = []documentdb.Capability{ - {Name: to.StringPtr("EnableMongo")}, + if properties.Capabilities != nil { + for _, i := range *properties.Capabilities { + name := i.Name + capabilities = append(capabilities, documentdb.Capability{ + Name: name, + }) } } else { capabilities = make([]documentdb.Capability, 0) diff --git a/pkg/resourcemanager/cosmosdbs/cosmosdb_reconcile.go b/pkg/resourcemanager/cosmosdbs/cosmosdb_reconcile.go index b06554f1fd1..5c40284dd8a 100644 --- a/pkg/resourcemanager/cosmosdbs/cosmosdb_reconcile.go +++ b/pkg/resourcemanager/cosmosdbs/cosmosdb_reconcile.go @@ -102,6 +102,7 @@ func (m *AzureCosmosDBManager) Ensure(ctx context.Context, obj runtime.Object, o EnableMultipleWriteLocations: instance.Spec.Properties.EnableMultipleWriteLocations, MongoDBVersion: instance.Spec.Properties.MongoDBVersion, IsVirtualNetworkFilterEnabled: instance.Spec.Properties.IsVirtualNetworkFilterEnabled, + Capabilities: instance.Spec.Properties.Capabilities, } db, err = m.CreateOrUpdateCosmosDB(ctx, groupName, accountName, location, kind, networkRule, ipRules, cosmosDBProperties, tags) @@ -115,7 +116,7 @@ func (m *AzureCosmosDBManager) Ensure(ctx context.Context, obj runtime.Object, o instance.Status.Message = "Resource request successfully submitted to Azure" instance.Status.SpecHash = hash return false, nil - case errhelp.InvalidResourceLocation, errhelp.LocationNotAvailableForResourceType: + case errhelp.InvalidResourceLocation, errhelp.LocationNotAvailableForResourceType, errhelp.BadRequest: instance.Status.Provisioning = false instance.Status.Message = azerr.Error() return true, nil