Skip to content

Commit

Permalink
Merge pull request #34 from Azure/master
Browse files Browse the repository at this point in the history
pr
  • Loading branch information
WilliamMortlMicrosoft authored Apr 24, 2020
2 parents 81d67f9 + 4f7d28c commit 4619ee6
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
14 changes: 11 additions & 3 deletions api/v1alpha1/cosmosdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions config/samples/azure_v1alpha1_cosmosdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 21 additions & 12 deletions pkg/resourcemanager/apim/apimservice/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions pkg/resourcemanager/cosmosdbs/cosmosdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/resourcemanager/cosmosdbs/cosmosdb_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pkg/resourcemanager/vnet/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4619ee6

Please sign in to comment.