Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/restore bkp for managed db #4

Merged
merged 2 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@ spec:
managedInstance:
name: incubsqlmi
resourceGroup: SQLMI_RG
restoreFrom:
backupFileName: origination_test_backup_2022_04_13_154723.bak
storageContainer:
uri: https://my-blobstorage.blob.core.windows.net/backup-repository
sasToken: my-saas-token
platformRef: charismaonline.qa
```
31 changes: 28 additions & 3 deletions helm/crds/provisioning.totalsoft.ro_azuremanageddatabases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ spec:
tenant suffix.
type: string
managedInstance:
description: Target managed instance spec
description: Target managed instance spec.
properties:
name:
description: Managed instance name
description: Managed instance name.
type: string
resourceGroup:
description: Managed instance ressource group
description: Managed instance resource group.
type: string
required:
- name
Expand All @@ -53,6 +53,31 @@ spec:
platformRef:
description: Target platform (custom resource name).
type: string
restoreFrom:
description: Restore from external backup. Leave empty for a new empty
database.
properties:
backupFileName:
description: The backup file to restore from.
type: string
storageContainer:
description: Azure storage container spec.
properties:
sasToken:
description: The storage container shared access signature
token.
type: string
uri:
description: The storage container uri.
type: string
required:
- sasToken
- uri
type: object
required:
- backupFileName
- storageContainer
type: object
required:
- dbName
- managedInstance
Expand Down
15 changes: 12 additions & 3 deletions internal/provisioners/pulumi/pulumi.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,24 @@ func azureManagedDbDeployFunc(platform string, tenant *provisioningv1.Tenant, az
return func(ctx *pulumi.Context) error {
for _, dbSpec := range azureDbs {
dbName := fmt.Sprintf("%s_%s_%s", dbSpec.Spec.DbName, platform, tenant.Spec.Code)
db, err := azureSql.NewManagedDatabase(ctx, dbName, &azureSql.ManagedDatabaseArgs{
args := azureSql.ManagedDatabaseArgs{
ManagedInstanceName: pulumi.String(dbSpec.Spec.ManagedInstance.Name),
ResourceGroupName: pulumi.String(dbSpec.Spec.ManagedInstance.ResourceGroup),
})
}
restoreFrom := dbSpec.Spec.RestoreFrom
if (restoreFrom != provisioningv1.AzureManagedDatabaseRestoreSpec{}) {
args.CreateMode = pulumi.String("RestoreExternalBackup")
args.AutoCompleteRestore = pulumi.Bool(true)
args.LastBackupName = pulumi.String(restoreFrom.BackupFileName)
args.StorageContainerSasToken = pulumi.String(restoreFrom.StorageContainer.SasToken)
args.StorageContainerUri = pulumi.String(restoreFrom.StorageContainer.Uri)
}
db, err := azureSql.NewManagedDatabase(ctx, dbName, &args)
if err != nil {
return err
}

ctx.Export(fmt.Sprintf("azureManagedDb:%s:%s", dbSpec.Spec.DbName, tenant.Spec.Code), db.Name)
ctx.Export(fmt.Sprintf("azureManagedDb:%s", dbSpec.Spec.DbName), db.Name)
}
return nil
}
Expand Down
27 changes: 22 additions & 5 deletions pkg/apis/provisioning/v1alpha1/azureManagedDatabaseTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,33 @@ type AzureManagedDatabaseSpec struct {
PlatformRef string `json:"platformRef"`
// Managed database name prefix. Will have platform and tenant suffix.
DbName string `json:"dbName"`
// Target managed instance spec
ManagedInstance AzureManagedInstance `json:"managedInstance"`
// Target managed instance spec.
ManagedInstance AzureManagedInstanceSpec `json:"managedInstance"`
// Restore from external backup. Leave empty for a new empty database.
// +optional
RestoreFrom AzureManagedDatabaseRestoreSpec `json:"restoreFrom,omitempty"`
}
type AzureManagedInstance struct {
// Managed instance name
type AzureManagedInstanceSpec struct {
// Managed instance name.
Name string `json:"name"`
// Managed instance ressource group
// Managed instance resource group.
ResourceGroup string `json:"resourceGroup"`
}

type AzureManagedDatabaseRestoreSpec struct {
//The backup file to restore from.
BackupFileName string `json:"backupFileName"`
//Azure storage container spec.
StorageContainer AzureStorageContainerSpec `json:"storageContainer"`
}

type AzureStorageContainerSpec struct {
// The storage container shared access signature token.
SasToken string `json:"sasToken"`
// The storage container uri.
Uri string `json:"uri"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type AzureManagedDatabaseList struct {
Expand Down
42 changes: 38 additions & 4 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.