Skip to content

Commit

Permalink
CosmosDB additional API types (#989)
Browse files Browse the repository at this point in the history
* adding capabilities to cosmosdb

* adding enums and empty capabilties array check

Co-authored-by: Justin Pflueger <jupflueg@microsoft.com>
  • Loading branch information
melonrush13 and Justin Pflueger authored Apr 24, 2020
1 parent 844d792 commit 7420fd1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 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
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

0 comments on commit 7420fd1

Please sign in to comment.