Skip to content

Commit

Permalink
add backup retention and geo redundant backup configurability (#1051)
Browse files Browse the repository at this point in the history
add backup retention and georedundancy for psql and mysql
  • Loading branch information
frodopwns authored May 15, 2020
1 parent b4f1f9a commit e18cbc7
Show file tree
Hide file tree
Showing 32 changed files with 400 additions and 813 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/mysqlserver_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (src *MySQLServer) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.KeyVaultToStoreSecrets = src.Spec.KeyVaultToStoreSecrets

// New Spec
//dst.Spec.StorageProfile = nil
dst.Spec.StorageProfile = nil

// Status
dst.Status = v1alpha2.ASOStatus(src.Status)
Expand Down
70 changes: 70 additions & 0 deletions api/v1alpha1/postgresqlserver_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1alpha1

import (
"github.com/Azure/azure-service-operator/api/v1alpha2"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

func (src *PostgreSQLServer) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1alpha2.PostgreSQLServer)

// ObjectMeta
dst.ObjectMeta = src.ObjectMeta

// Spec
dst.Spec.ResourceGroup = src.Spec.ResourceGroup
dst.Spec.Location = src.Spec.Location
dst.Spec.Sku = v1alpha2.AzureDBsSQLSku{
Name: src.Spec.Sku.Name,
Tier: v1alpha2.SkuTier(src.Spec.Sku.Tier),
Capacity: src.Spec.Sku.Capacity,
Size: src.Spec.Sku.Size,
Family: src.Spec.Sku.Family,
}

dst.Spec.ServerVersion = v1alpha2.ServerVersion(src.Spec.ServerVersion)
dst.Spec.SSLEnforcement = v1alpha2.SslEnforcementEnum(src.Spec.SSLEnforcement)
dst.Spec.CreateMode = src.Spec.CreateMode
dst.Spec.ReplicaProperties = v1alpha2.ReplicaProperties(src.Spec.ReplicaProperties)
dst.Spec.KeyVaultToStoreSecrets = src.Spec.KeyVaultToStoreSecrets

// New Spec
dst.Spec.StorageProfile = nil

// Status
dst.Status = v1alpha2.ASOStatus(src.Status)

return nil
}

func (dst *PostgreSQLServer) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1alpha2.PostgreSQLServer)

// ObjectMeta
dst.ObjectMeta = src.ObjectMeta

// Spec
dst.Spec.ResourceGroup = src.Spec.ResourceGroup
dst.Spec.Location = src.Spec.Location
dst.Spec.Sku = AzureDBsSQLSku{
Name: src.Spec.Sku.Name,
Tier: SkuTier(src.Spec.Sku.Tier),
Capacity: src.Spec.Sku.Capacity,
Size: src.Spec.Sku.Size,
Family: src.Spec.Sku.Family,
}
dst.Spec.ServerVersion = ServerVersion(src.Spec.ServerVersion)
dst.Spec.SSLEnforcement = SslEnforcementEnum(src.Spec.SSLEnforcement)
dst.Spec.CreateMode = src.Spec.CreateMode
dst.Spec.ReplicaProperties = ReplicaProperties(src.Spec.ReplicaProperties)
dst.Spec.KeyVaultToStoreSecrets = src.Spec.KeyVaultToStoreSecrets

// Status
dst.Status = ASOStatus(src.Status)

return nil

}
20 changes: 20 additions & 0 deletions api/v1alpha1/postgresqlserver_webhook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1alpha1

import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)

// log is for logging in this package.
var postgresqlserverlog = logf.Log.WithName("postgresqlserver-resource")

func (r *PostgreSQLServer) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
}

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
92 changes: 16 additions & 76 deletions api/v1alpha2/mysqlserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,90 +4,24 @@
package v1alpha2

import (
"github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql"
"github.com/Azure/go-autorest/autorest/to"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

type AzureDBsSQLSku struct {
// Name - The name of the sku, typically, tier + family + cores, e.g. B_Gen4_1, GP_Gen5_8.
Name string `json:"name,omitempty"`
// Tier - The tier of the particular SKU, e.g. Basic. Possible values include: 'Basic', 'GeneralPurpose', 'MemoryOptimized'
Tier SkuTier `json:"tier,omitempty"`
// Capacity - The scale up/out capacity, representing server's compute units.
Capacity int32 `json:"capacity,omitempty"`
// Size - The size code, to be interpreted by resource as appropriate.
Size string `json:"size,omitempty"`
// Family - The family of hardware.
Family string `json:"family,omitempty"`
}

// ServerVersion enumerates the values for server version.
type ServerVersion string

const (
// NineFullStopFive ...
NineFullStopFive ServerVersion = "9.5"
// NineFullStopSix ...
NineFullStopSix ServerVersion = "9.6"
// OneOne ...
OneOne ServerVersion = "11"
// OneZero ...
OneZero ServerVersion = "10"
// OneZeroFullStopTwo ...
OneZeroFullStopTwo ServerVersion = "10.2"
// OneZeroFullStopZero ...
OneZeroFullStopZero ServerVersion = "10.0"
)

type SkuTier string

const (
// Basic ...
PSQLBasic SkuTier = "Basic"
// GeneralPurpose ...
PSQLGeneralPurpose SkuTier = "GeneralPurpose"
// MemoryOptimized ...
PSQLMemoryOptimized SkuTier = "MemoryOptimized"
)

type SslEnforcementEnum string

const (
// SslEnforcementEnumDisabled ...
SslEnforcementEnumDisabled SslEnforcementEnum = "Disabled"
// SslEnforcementEnumEnabled ...
SslEnforcementEnumEnabled SslEnforcementEnum = "Enabled"
)

type StorageProfile struct {
// BackupRetentionDays - Backup retention days for the server.
BackupRetentionDays *int32 `json:"backupRetentionDays,omitempty"`
// GeoRedundantBackup - Enable Geo-redundant or not for server backup. Possible values include: 'Enabled', 'Disabled'
GeoRedundantBackup mysql.GeoRedundantBackup `json:"geoRedundantBackup,omitempty"`
// StorageMB - Max storage allowed for a server.
StorageMB *int32 `json:"storageMB,omitempty"`
// StorageAutogrow - Enable Storage Auto Grow. Possible values include: 'StorageAutogrowEnabled', 'StorageAutogrowDisabled'
StorageAutogrow mysql.StorageAutogrow `json:"storageAutogrow,omitempty"`
}

type ReplicaProperties struct {
SourceServerId string `json:"sourceServerId,omitempty"`
}

// MySQLServerSpec defines the desired state of MySQLServer
type MySQLServerSpec struct {
Location string `json:"location"`
ResourceGroup string `json:"resourceGroup,omitempty"`
Sku AzureDBsSQLSku `json:"sku,omitempty"`
ServerVersion ServerVersion `json:"serverVersion,omitempty"`
SSLEnforcement SslEnforcementEnum `json:"sslEnforcement,omitempty"`
CreateMode string `json:"createMode,omitempty"`
ReplicaProperties ReplicaProperties `json:"replicaProperties,omitempty"`
StorageProfile *StorageProfile `json:"storageProfile,omitempty"`
KeyVaultToStoreSecrets string `json:"keyVaultToStoreSecrets,omitempty"`
Location string `json:"location"`
ResourceGroup string `json:"resourceGroup,omitempty"`
Sku AzureDBsSQLSku `json:"sku,omitempty"`
ServerVersion ServerVersion `json:"serverVersion,omitempty"`
SSLEnforcement SslEnforcementEnum `json:"sslEnforcement,omitempty"`
CreateMode string `json:"createMode,omitempty"`
ReplicaProperties ReplicaProperties `json:"replicaProperties,omitempty"`
StorageProfile *MySQLStorageProfile `json:"storageProfile,omitempty"`
KeyVaultToStoreSecrets string `json:"keyVaultToStoreSecrets,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down Expand Up @@ -137,6 +71,12 @@ func NewDefaultMySQLServer(name, resourceGroup, location string) *MySQLServer {
ServerVersion: ServerVersion("8.0"),
SSLEnforcement: SslEnforcementEnumEnabled,
CreateMode: "Default",
StorageProfile: &MySQLStorageProfile{
BackupRetentionDays: to.Int32Ptr(10),
GeoRedundantBackup: "Disabled",
StorageMB: to.Int32Ptr(5120),
StorageAutogrow: "Disabled",
},
},
}
}
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha2/postgresqlserver_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1alpha2

func (*PostgreSQLServer) Hub() {}
52 changes: 52 additions & 0 deletions api/v1alpha2/postgresqlserver_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1alpha2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// PostgreSQLServerSpec defines the desired state of PostgreSQLServer
type PostgreSQLServerSpec struct {
Location string `json:"location"`
ResourceGroup string `json:"resourceGroup,omitempty"`
Sku AzureDBsSQLSku `json:"sku,omitempty"`
ServerVersion ServerVersion `json:"serverVersion,omitempty"`
SSLEnforcement SslEnforcementEnum `json:"sslEnforcement,omitempty"`
KeyVaultToStoreSecrets string `json:"keyVaultToStoreSecrets,omitempty"`
CreateMode string `json:"createMode,omitempty"`
StorageProfile *PSQLStorageProfile `json:"storageProfile,omitempty"`
ReplicaProperties ReplicaProperties `json:"replicaProperties,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:storageversion

// PostgreSQLServer is the Schema for the postgresqlservers API
// +kubebuilder:printcolumn:name="Provisioned",type="string",JSONPath=".status.provisioned"
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.message"
type PostgreSQLServer struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec PostgreSQLServerSpec `json:"spec,omitempty"`
Status ASOStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// PostgreSQLServerList contains a list of PostgreSQLServer
type PostgreSQLServerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []PostgreSQLServer `json:"items"`
}

func init() {
SchemeBuilder.Register(&PostgreSQLServer{}, &PostgreSQLServerList{})
}
86 changes: 86 additions & 0 deletions api/v1alpha2/sharedazuredbs_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

package v1alpha2

import (
"github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2017-12-01/mysql"
psql "github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql"
)

type AzureDBsSQLSku struct {
// Name - The name of the sku, typically, tier + family + cores, e.g. B_Gen4_1, GP_Gen5_8.
Name string `json:"name,omitempty"`
// Tier - The tier of the particular SKU, e.g. Basic. Possible values include: 'Basic', 'GeneralPurpose', 'MemoryOptimized'
Tier SkuTier `json:"tier,omitempty"`
// Capacity - The scale up/out capacity, representing server's compute units.
Capacity int32 `json:"capacity,omitempty"`
// Size - The size code, to be interpreted by resource as appropriate.
Size string `json:"size,omitempty"`
// Family - The family of hardware.
Family string `json:"family,omitempty"`
}

// ServerVersion enumerates the values for server version.
type ServerVersion string

const (
// NineFullStopFive ...
NineFullStopFive ServerVersion = "9.5"
// NineFullStopSix ...
NineFullStopSix ServerVersion = "9.6"
// OneOne ...
OneOne ServerVersion = "11"
// OneZero ...
OneZero ServerVersion = "10"
// OneZeroFullStopTwo ...
OneZeroFullStopTwo ServerVersion = "10.2"
// OneZeroFullStopZero ...
OneZeroFullStopZero ServerVersion = "10.0"
)

type SkuTier string

const (
// Basic ...
PSQLBasic SkuTier = "Basic"
// GeneralPurpose ...
PSQLGeneralPurpose SkuTier = "GeneralPurpose"
// MemoryOptimized ...
PSQLMemoryOptimized SkuTier = "MemoryOptimized"
)

type SslEnforcementEnum string

const (
// SslEnforcementEnumDisabled ...
SslEnforcementEnumDisabled SslEnforcementEnum = "Disabled"
// SslEnforcementEnumEnabled ...
SslEnforcementEnumEnabled SslEnforcementEnum = "Enabled"
)

type MySQLStorageProfile struct {
// BackupRetentionDays - Backup retention days for the server.
BackupRetentionDays *int32 `json:"backupRetentionDays,omitempty"`
// GeoRedundantBackup - Enable Geo-redundant or not for server backup. Possible values include: 'Enabled', 'Disabled'
GeoRedundantBackup mysql.GeoRedundantBackup `json:"geoRedundantBackup,omitempty"`
// StorageMB - Max storage allowed for a server.
StorageMB *int32 `json:"storageMB,omitempty"`
// StorageAutogrow - Enable Storage Auto Grow. Possible values include: 'StorageAutogrowEnabled', 'StorageAutogrowDisabled'
StorageAutogrow mysql.StorageAutogrow `json:"storageAutogrow,omitempty"`
}

type PSQLStorageProfile struct {
// BackupRetentionDays - Backup retention days for the server.
BackupRetentionDays *int32 `json:"backupRetentionDays,omitempty"`
// GeoRedundantBackup - Enable Geo-redundant or not for server backup. Possible values include: 'Enabled', 'Disabled'
GeoRedundantBackup psql.GeoRedundantBackup `json:"geoRedundantBackup,omitempty"`
// StorageMB - Max storage allowed for a server.
StorageMB *int32 `json:"storageMB,omitempty"`
// StorageAutogrow - Enable Storage Auto Grow. Possible values include: 'StorageAutogrowEnabled', 'StorageAutogrowDisabled'
StorageAutogrow psql.StorageAutogrow `json:"storageAutogrow,omitempty"`
}

type ReplicaProperties struct {
SourceServerId string `json:"sourceServerId,omitempty"`
}
8 changes: 4 additions & 4 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ patches:
- patches/webhook_in_azuresqlfailovergroups.yaml
- patches/webhook_in_blobcontainers.yaml
#- patches/webhook_in_appinsights.yaml
#- patches/webhook_in_postgresqlservers.yaml
- patches/webhook_in_postgresqlservers.yaml
#- patches/webhook_in_postgresqldatabases.yaml
#- patches/webhook_in_postgresqlfirewallrules.yaml
#- patches/webhook_in_postgresqlvnetrules.yaml
Expand All @@ -64,7 +64,7 @@ patches:
#- patches/webhook_in_virtualnetworks.yaml
#- patches/webhook_in_keyvaultkeys.yaml
#- patches/webhook_in_azuresqlvnetrules.yaml
#- patches/webhook_in_mysqlservers.yaml
- patches/webhook_in_mysqlservers.yaml
#- patches/webhook_in_mysqldatabases.yaml
#- patches/webhook_in_mysqlfirewallrules.yaml
#- patches/webhook_in_storageaccounts.yaml
Expand All @@ -91,7 +91,7 @@ patches:
- patches/cainjection_in_azuresqlfailovergroups.yaml
- patches/cainjection_in_blobcontainers.yaml
#- patches/cainjection_in_appinsights.yaml
#- patches/cainjection_in_postgresqlservers.yaml
- patches/cainjection_in_postgresqlservers.yaml
#- patches/cainjection_in_postgresqldatabases.yaml
#- patches/cainjection_in_postgresqlfirewallrules.yaml
#- patches/cainjection_in_postgresqlvnetrules.yaml
Expand All @@ -100,7 +100,7 @@ patches:
#- patches/cainjection_in_virtualnetworks.yaml
#- patches/cainjection_in_keyvaultkeys.yaml
#- patches/cainjection_in_azuresqlvnetrules.yaml
#- patches/cainjection_in_mysqlservers.yaml
- patches/cainjection_in_mysqlservers.yaml
#- patches/cainjection_in_mysqldatabases.yaml
#- patches/cainjection_in_mysqlfirewallrules.yaml
#- patches/cainjection_in_storageaccounts.yaml
Expand Down
Loading

0 comments on commit e18cbc7

Please sign in to comment.