Skip to content

Commit

Permalink
provisioner - domain specific exports (#35)
Browse files Browse the repository at this point in the history
* provisioner exports

* fix readme

Co-authored-by: Radu Popovici <[email protected]>
  • Loading branch information
oncicaradupopovici and Radu Popovici authored Sep 19, 2022
1 parent 787d97f commit 4b4a9ee
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 84 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ apiVersion: provisioning.totalsoft.ro/v1alpha1
kind: AzureDatabase
spec:
dbName: origination_db
domains:
- origination
exports:
dbName:
toConfigMap:
keyTemplate: MultiTenancy__Tenants__{{ .Tenant.Code }}__ConnectionStrings__Database
- domain: origination
dbName:
toConfigMap:
keyTemplate: MultiTenancy__Tenants__{{ .Tenant.Code }}__ConnectionStrings__Database
platformRef: charismaonline.qa
sourceDatabaseId: /subscriptions/XXXXXX-b8a5-4967-a05a-2fa3c4295710/resourceGroups/SQLMI_RG/providers/Microsoft.Sql/servers/r7ddbsrv/databases/insurance_db
sqlServer:
Expand All @@ -79,12 +78,11 @@ apiVersion: provisioning.totalsoft.ro/v1alpha1
kind: AzureManagedDatabase
spec:
dbName: origination_db
domains:
- origination
exports:
dbName:
toConfigMap:
keyTemplate: MultiTenancy__Tenants__{{ .Tenant.Code }}__ConnectionStrings__Leasing_Database__Database
- domain: origination
dbName:
toConfigMap:
keyTemplate: MultiTenancy__Tenants__{{ .Tenant.Code }}__ConnectionStrings__Database
managedInstance:
name: incubsqlmi
resourceGroup: SQLMI_RG
Expand Down
51 changes: 26 additions & 25 deletions helm/crds/provisioning.totalsoft.ro_azuredatabases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,34 @@ spec:
dbName:
description: Database name prefix. Will have platform and tenant suffix.
type: string
domains:
description: The domain or bounded-context in which this database
will be used.
exports:
items:
type: string
properties:
dbName:
properties:
toConfigMap:
properties:
keyTemplate:
type: string
required:
- keyTemplate
type: object
toVault:
properties:
keyTemplate:
type: string
required:
- keyTemplate
type: object
type: object
domain:
description: The domain or bounded-context in which this database
will be used.
type: string
required:
- domain
type: object
type: array
exports:
properties:
dbName:
properties:
toConfigMap:
properties:
keyTemplate:
type: string
required:
- keyTemplate
type: object
toVault:
properties:
keyTemplate:
type: string
required:
- keyTemplate
type: object
type: object
type: object
platformRef:
description: Target platform (custom resource name).
type: string
Expand Down Expand Up @@ -96,7 +98,6 @@ spec:
type: object
required:
- dbName
- domains
- platformRef
- sqlServer
type: object
Expand Down
53 changes: 27 additions & 26 deletions helm/crds/provisioning.totalsoft.ro_azuremanageddatabases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,35 @@ spec:
description: Managed database name prefix. Will have platform and
tenant suffix.
type: string
domains:
description: The domain or bounded-context in which this database
will be used.
items:
type: string
type: array
exports:
description: Export provisioning values spec.
properties:
dbName:
properties:
toConfigMap:
properties:
keyTemplate:
type: string
required:
- keyTemplate
type: object
toVault:
properties:
keyTemplate:
type: string
required:
- keyTemplate
type: object
type: object
type: object
items:
properties:
dbName:
properties:
toConfigMap:
properties:
keyTemplate:
type: string
required:
- keyTemplate
type: object
toVault:
properties:
keyTemplate:
type: string
required:
- keyTemplate
type: object
type: object
domain:
description: The domain or bounded-context in which this database
will be used.
type: string
required:
- domain
type: object
type: array
managedInstance:
description: Target managed instance spec.
properties:
Expand Down Expand Up @@ -114,7 +116,6 @@ spec:
type: object
required:
- dbName
- domains
- managedInstance
- platformRef
type: object
Expand Down
6 changes: 3 additions & 3 deletions internal/provisioners/pulumi/azure_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func azureDbDeployFunc(platform string, tenant *platformv1.Tenant,
}
ctx.Export("azureDbName", db.Name)

for _, domain := range dbSpec.Spec.Domains {
err = valueExporter(newExportContext(ctx, domain, dbSpec.Name, dbSpec.ObjectMeta, gvk),
map[string]exportTemplateWithValue{"dbName": {dbSpec.Spec.Exports.DbName, db.Name}})
for _, exp := range dbSpec.Spec.Exports {
err = valueExporter(newExportContext(ctx, exp.Domain, dbSpec.Name, dbSpec.ObjectMeta, gvk),
map[string]exportTemplateWithValue{"dbName": {exp.DbName, db.Name}})
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/provisioners/pulumi/azure_managed_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func azureManagedDbDeployFunc(platform string, tenant *platformv1.Tenant,
return err
}

for _, domain := range dbSpec.Spec.Domains {
err = valueExporter(newExportContext(ctx, domain, dbSpec.Name, dbSpec.ObjectMeta, gvk),
map[string]exportTemplateWithValue{"dbname": {dbSpec.Spec.Exports.DbName, db.Name}})
for _, exp := range dbSpec.Spec.Exports {
err = valueExporter(newExportContext(ctx, exp.Domain, dbSpec.Name, dbSpec.ObjectMeta, gvk),
map[string]exportTemplateWithValue{"dbname": {exp.DbName, db.Name}})
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/provisioning/v1alpha1/azureDatabaseTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ type AzureDatabase struct {
type AzureDatabaseSpec struct {
// Target platform (custom resource name).
PlatformRef string `json:"platformRef"`
// The domain or bounded-context in which this database will be used.
Domains []string `json:"domains"`
// Database name prefix. Will have platform and tenant suffix.
DbName string `json:"dbName"`
// Azure Sql Server spec. New database will be created on this server
Expand All @@ -33,7 +31,7 @@ type AzureDatabaseSpec struct {
// +optional
SourceDatabaseId string `json:"sourceDatabaseId,omitempty"`
// +optional
Exports AzureDatabaseExportsSpec `json:"exports,omitempty"`
Exports []AzureDatabaseExportsSpec `json:"exports,omitempty"`
}

type SqlServerSpec struct {
Expand All @@ -46,6 +44,8 @@ type SqlServerSpec struct {
}

type AzureDatabaseExportsSpec struct {
// The domain or bounded-context in which this database will be used.
Domain string `json:"domain"`
// +optional
DbName ValueExport `json:"dbName,omitempty"`
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/provisioning/v1alpha1/azureManagedDatabaseTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ type AzureManagedDatabase struct {
type AzureManagedDatabaseSpec struct {
// Target platform (custom resource name).
PlatformRef string `json:"platformRef"`
// The domain or bounded-context in which this database will be used.
Domains []string `json:"domains"`
// Managed database name prefix. Will have platform and tenant suffix.
DbName string `json:"dbName"`
// Target managed instance spec.
Expand All @@ -31,7 +29,7 @@ type AzureManagedDatabaseSpec struct {
RestoreFrom AzureManagedDatabaseRestoreSpec `json:"restoreFrom,omitempty"`
// Export provisioning values spec.
// +optional
Exports AzureManagedDatabaseExportsSpec `json:"exports,omitempty"`
Exports []AzureManagedDatabaseExportsSpec `json:"exports,omitempty"`
}
type AzureManagedInstanceSpec struct {
// Managed instance name.
Expand All @@ -55,6 +53,8 @@ type AzureStorageContainerSpec struct {
}

type AzureManagedDatabaseExportsSpec struct {
// The domain or bounded-context in which this database will be used.
Domain string `json:"domain"`
// +optional
DbName ValueExport `json:"dbName,omitempty"`
}
Expand Down
20 changes: 9 additions & 11 deletions pkg/apis/provisioning/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4b4a9ee

Please sign in to comment.