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/apim/apimservice/reconcile.go b/pkg/resourcemanager/apim/apimservice/reconcile.go index 8f226c7bd70..80f04019817 100644 --- a/pkg/resourcemanager/apim/apimservice/reconcile.go +++ b/pkg/resourcemanager/apim/apimservice/reconcile.go @@ -192,24 +192,33 @@ func (g *AzureAPIMgmtServiceManager) Delete(ctx context.Context, obj runtime.Obj resourceGroupName := instance.Spec.ResourceGroup resourceName := instance.ObjectMeta.Name - catch := []string{ - errhelp.ResourceGroupNotFoundErrorCode, - errhelp.ParentNotFoundErrorCode, - errhelp.NotFoundErrorCode, - } - requeue := []string{ - errhelp.AsyncOpIncompleteError, - } - _, err = g.DeleteAPIMgmtSvc(ctx, resourceGroupName, resourceName) if err != nil { azerr := errhelp.NewAzureErrorAzureError(err) - if helpers.ContainsString(catch, azerr.Type) { + + alreadyDeletedErrors := []string{ + errhelp.ResourceGroupNotFoundErrorCode, + errhelp.ParentNotFoundErrorCode, + errhelp.NotFoundErrorCode, + } + requeue := []string{ + errhelp.AsyncOpIncompleteError, + } + + // already deleted so exit successfully + if helpers.ContainsString(alreadyDeletedErrors, azerr.Type) { return false, nil - } else if helpers.ContainsString(requeue, azerr.Type) { + } + + // requeue the delete to try again + instance.Status.Message = "Deletion is not complete" + errorStr := err.Error() + if helpers.ContainsString(requeue, azerr.Type) || + strings.Contains(errorStr, "FailedDelete") || + strings.Contains(errorStr, "Failure sending request: StatusCode=0") { return true, nil } - return true, fmt.Errorf("API Mgmt Svc delete error %v", err) + return true, fmt.Errorf("API Mgmt Svc delete error: %v", err) } return false, nil 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 diff --git a/pkg/resourcemanager/vnet/reconcile.go b/pkg/resourcemanager/vnet/reconcile.go index b2eac84b4ca..7b61c09e500 100644 --- a/pkg/resourcemanager/vnet/reconcile.go +++ b/pkg/resourcemanager/vnet/reconcile.go @@ -73,7 +73,9 @@ func (g *AzureVNetManager) Ensure(ctx context.Context, obj runtime.Object, opts errhelp.NetcfgInvalidVirtualNetworkSite, errhelp.InvalidCIDRNotation, errhelp.InvalidRequestFormat, + errhelp.LocationNotAvailableForResourceType, errhelp.InvalidAddressPrefixFormat, + } // everything ok - just requeue @@ -85,6 +87,7 @@ func (g *AzureVNetManager) Ensure(ctx context.Context, obj runtime.Object, opts if helpers.ContainsString(catch, azerr.Type) { instance.Status.Provisioning = false return false, nil + } instance.Status.Provisioning = false