Skip to content

Commit

Permalink
Merge pull request #967 from jpflueger/cosmosdb-mongodb-version
Browse files Browse the repository at this point in the history
adding mongodb version to cosmosdb
  • Loading branch information
Justin Pflueger authored Apr 20, 2020
2 parents 4b0b17e + b38abb8 commit b98e0b9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/cosmosdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type CosmosDBProperties struct {
// CosmosDBDatabaseAccountOfferType - The offer type for the Cosmos DB database account.
DatabaseAccountOfferType CosmosDBDatabaseAccountOfferType `json:"databaseAccountOfferType,omitempty"`
//Locations []CosmosDBLocation `json:"locations,omitempty"`
MongoDBVersion string `json:"mongoDBVersion,omitempty"`
}

// +kubebuilder:validation:Enum=Standard
Expand Down
5 changes: 4 additions & 1 deletion config/samples/azure_v1alpha1_cosmosdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ spec:
resourceGroup: resourcegroup-azure-operators
properties:
databaseAccountOfferType: Standard
# 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"

# Use the field below to optionally specify a different keyvault
# Use the field below to optionally specify a different keyvault
# to store the connectiong string secrets in
#keyVaultToStoreSecrets: asoSecretKeyVault
11 changes: 11 additions & 0 deletions pkg/resourcemanager/cosmosdbs/cosmosdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (*AzureCosmosDBManager) CreateOrUpdateCosmosDB(
location string,
kind v1alpha1.CosmosDBKind,
dbType v1alpha1.CosmosDBDatabaseAccountOfferType,
dbVersion string,
tags map[string]*string) (*documentdb.DatabaseAccount, error) {
cosmosDBClient, err := getCosmosDBClient()
if err != nil {
Expand All @@ -53,6 +54,15 @@ func (*AzureCosmosDBManager) CreateOrUpdateCosmosDB(
dbKind := documentdb.DatabaseAccountKind(kind)
sDBType := string(dbType)

var capabilities []documentdb.Capability
if dbKind == documentdb.MongoDB && dbVersion == "3.6" {
capabilities = []documentdb.Capability{
{Name: to.StringPtr("EnableMongo")},
}
} else {
capabilities = make([]documentdb.Capability, 0)
}

/*
* Current state of Locations and CosmosDB properties:
* Creating a Database account with CosmosDB requires
Expand Down Expand Up @@ -86,6 +96,7 @@ func (*AzureCosmosDBManager) CreateOrUpdateCosmosDB(
EnableMultipleWriteLocations: to.BoolPtr(false),
IsVirtualNetworkFilterEnabled: to.BoolPtr(false),
Locations: &locationsArray,
Capabilities: &capabilities,
},
}
createUpdateFuture, err := cosmosDBClient.CreateOrUpdate(
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcemanager/cosmosdbs/cosmosdb_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewAzureCosmosDBManager(secretClient secrets.SecretClient) *AzureCosmosDBMa
// CosmosDBManager client functions
type CosmosDBManager interface {
// CreateOrUpdateCosmosDB creates a new cosmos database account
CreateOrUpdateCosmosDB(ctx context.Context, groupName string, cosmosDBName string, location string, kind v1alpha1.CosmosDBKind, dbType v1alpha1.CosmosDBDatabaseAccountOfferType, tags map[string]*string) (*documentdb.DatabaseAccount, error)
CreateOrUpdateCosmosDB(ctx context.Context, groupName string, cosmosDBName string, location string, kind v1alpha1.CosmosDBKind, dbType v1alpha1.CosmosDBDatabaseAccountOfferType, dbVersion string, tags map[string]*string) (*documentdb.DatabaseAccount, error)

// GetCosmosDB gets a cosmos database account
GetCosmosDB(ctx context.Context, groupName string, cosmosDBName string) (*documentdb.DatabaseAccount, error)
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 @@ -95,8 +95,9 @@ func (m *AzureCosmosDBManager) Ensure(ctx context.Context, obj runtime.Object, o
location := instance.Spec.Location
kind := instance.Spec.Kind
dbType := instance.Spec.Properties.DatabaseAccountOfferType
dbVersion := instance.Spec.Properties.MongoDBVersion

db, err = m.CreateOrUpdateCosmosDB(ctx, groupName, accountName, location, kind, dbType, tags)
db, err = m.CreateOrUpdateCosmosDB(ctx, groupName, accountName, location, kind, dbType, dbVersion, tags)
if err != nil {
azerr := errhelp.NewAzureErrorAzureError(err)
instance.Status.Message = err.Error()
Expand Down

0 comments on commit b98e0b9

Please sign in to comment.