Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1643 from fanminshi/remove_backup_restore_spec
Browse files Browse the repository at this point in the history
*: remove backup and restore spec
  • Loading branch information
fanminshi committed Nov 9, 2017
2 parents 285583e + b09609f commit 9d485b4
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 494 deletions.
110 changes: 1 addition & 109 deletions pkg/apis/etcd/v1beta2/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,81 +14,15 @@

package v1beta2

import "errors"

type BackupStorageType string

const (
BackupStorageTypeDefault = ""
BackupStorageTypePersistentVolume = "PersistentVolume"
BackupStorageTypeS3 = "S3"
BackupStorageTypeABS = "ABS"
BackupStorageTypeS3 = "S3"

AWSSecretCredentialsFileName = "credentials"
AWSSecretConfigFileName = "config"

// ABSStorageAccount defines the key for the Azure Storage Account value in the ABS Kubernetes secret
ABSStorageAccount = "storage-account"
// ABSStorageKey defines the key for the Azure Storage Key value in the ABS Kubernetes secret
ABSStorageKey = "storage-key"
)

var (
errPVZeroSize = errors.New("PV backup should not have 0 size volume")
errPVNoStorageClass = errors.New("PV backup must have a storage class set")
)

type BackupPolicy struct {
// Pod defines the policy to create the backup pod.
Pod *PodPolicy `json:"pod,omitempty"`

// StorageType specifies the type of storage device to store backup files.
// If it's not set by user, the default is "PersistentVolume".
StorageType BackupStorageType `json:"storageType"`

StorageSource `json:",inline"`

// BackupIntervalInSecond specifies the interval between two backups.
// The default interval is 1800 seconds.
BackupIntervalInSecond int `json:"backupIntervalInSecond"`

// If greater than 0, MaxBackups is the maximum number of backup files to retain.
// If equal to 0, it means unlimited backups.
// Otherwise, it is invalid.
MaxBackups int `json:"maxBackups"`

// AutoDelete tells whether to cleanup backup data if cluster is deleted.
// By default (false), operator will keep the backup data.
AutoDelete bool `json:"autoDelete"`
}

func (bp *BackupPolicy) Validate() error {
if bp.MaxBackups < 0 {
return errors.New("MaxBackups value should be >= 0")
}
if bp.StorageType == BackupStorageTypePersistentVolume {
pv := bp.StorageSource.PV
if pv == nil || pv.VolumeSizeInMB <= 0 {
return errPVZeroSize
}
if len(pv.StorageClass) == 0 {
return errPVNoStorageClass
}
}
return nil
}

type StorageSource struct {
// PV represents a Persistent Volume resource, operator will claim the
// required size before creating the etcd cluster for backup purpose.
// If the snapshot size is larger than the size specified operator would
// kill the cluster and report failure condition in status.
PV *PVSource `json:"pv,omitempty"`
S3 *S3Source `json:"s3,omitempty"`
// ABS represents an Azure Blob Storage resource for storing etcd backups
ABS *ABSSource `json:"abs,omitempty"`
}

// TODO: support per cluster S3 Source configuration.
type S3Source struct {
// The name of the AWS S3 bucket to store backups in.
Expand All @@ -109,45 +43,3 @@ type S3Source struct {
// AWSSecret overwrites the default etcd operator wide AWS credential and config.
AWSSecret string `json:"awsSecret,omitempty"`
}

// ABSSource represents an Azure Blob Storage (ABS) backup storage source
type ABSSource struct {
// ABSContainer is the name of the ABS container to store backups in.
ABSContainer string `json:"absContainer,omitempty"`

// ABSSecret is the name of the secret object that stores the ABS credentials.
//
// Within the secret object, the following fields MUST be provided:
// 'storage-account' holding the Azure Storage account name
// 'storage-key' holding the Azure Storage account key
ABSSecret string `json:"absSecret,omitempty"`
}

type BackupServiceStatus struct {
// RecentBackup is status of the most recent backup created by
// the backup service
RecentBackup *BackupStatus `json:"recentBackup,omitempty"`

// Backups is the totoal number of existing backups
Backups int `json:"backups"`

// BackupSize is the total size of existing backups in MB.
BackupSize float64 `json:"backupSize"`
}

type BackupStatus struct {
// Creation time of the backup.
CreationTime string `json:"creationTime"`

// Size is the size of the backup in MB.
Size float64 `json:"size"`

// Revision is the revision of the backup.
Revision int64 `json:"revision"`

// Version is the version of the backup cluster.
Version string `json:"version"`

// TimeTookInSecond is the total time took to create the backup.
TimeTookInSecond int `json:"timeTookInSecond"`
}
50 changes: 0 additions & 50 deletions pkg/apis/etcd/v1beta2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ func (c *EtcdCluster) AsOwner() metav1.OwnerReference {
}
}

type PVSource struct {
// VolumeSizeInMB specifies the required volume size.
VolumeSizeInMB int `json:"volumeSizeInMB"`

// StorageClass indicates what Kubernetes storage class will be used.
// This enables the user to have fine-grained control over how persistent
// volumes are created since it uses the existing StorageClass mechanism in
// Kubernetes.
StorageClass string `json:"storageClass"`
}

type ClusterSpec struct {
// Size is the expected size of the etcd cluster.
// The etcd-operator will eventually make the size of the running
Expand Down Expand Up @@ -106,17 +95,6 @@ type ClusterSpec struct {
// Updating Pod does not take effect on any existing etcd pods.
Pod *PodPolicy `json:"pod,omitempty"`

// Backup defines the policy to backup data of etcd cluster if not nil.
// If backup policy is set but restore policy not, and if a previous backup exists,
// this cluster would face conflict and fail to start.
Backup *BackupPolicy `json:"backup,omitempty"`

// Restore defines the policy to restore cluster form existing backup if not nil.
// It's not allowed if restore policy is set and backup policy not.
//
// Restore is a cluster initialization configuration. It cannot be updated.
Restore *RestorePolicy `json:"restore,omitempty"`

// SelfHosted determines if the etcd cluster is used for a self-hosted
// Kubernetes cluster.
//
Expand All @@ -127,16 +105,6 @@ type ClusterSpec struct {
TLS *TLSPolicy `json:"TLS,omitempty"`
}

// RestorePolicy defines the policy to restore cluster form existing backup if not nil.
type RestorePolicy struct {
// BackupClusterName is the cluster name of the backup to recover from.
BackupClusterName string `json:"backupClusterName"`

// StorageType specifies the type of storage device to store backup files.
// If not set, the default is "PersistentVolume".
StorageType BackupStorageType `json:"storageType"`
}

// PodPolicy defines the policy to create pod for the etcd container.
type PodPolicy struct {
// Labels specifies the labels to attach to pods the operator creates for the
Expand Down Expand Up @@ -168,30 +136,12 @@ type PodPolicy struct {
// This field cannot be updated.
EtcdEnv []v1.EnvVar `json:"etcdEnv,omitempty"`

// PV represents a Persistent Volume resource.
// If defined new pods will use a persistent volume to store etcd data.
// TODO(sgotti) unimplemented
PV *PVSource `json:"pv,omitempty"`

// By default, kubernetes will mount a service account token into the etcd pods.
// AutomountServiceAccountToken indicates whether pods running with the service account should have an API token automatically mounted.
AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty"`
}

func (c *ClusterSpec) Validate() error {
if c.Backup == nil && c.Restore != nil {
return ErrBackupUnsetRestoreSet
}
if c.Backup != nil && c.Restore != nil {
if c.Backup.StorageType != c.Restore.StorageType {
return errors.New("spec: backup and restore storage types are different")
}
}
if c.Backup != nil {
if err := c.Backup.Validate(); err != nil {
return err
}
}
if c.TLS != nil {
if err := c.TLS.Validate(); err != nil {
return err
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/etcd/v1beta2/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ type ClusterStatus struct {
// TargetVersion is the version the cluster upgrading to.
// If the cluster is not upgrading, TargetVersion is empty.
TargetVersion string `json:"targetVersion"`

// BackupServiceStatus is the status of the backup service.
// BackupServiceStatus only exists when backup is enabled in the
// cluster spec.
BackupServiceStatus *BackupServiceStatus `json:"backupServiceStatus,omitempty"`
}

// ClusterCondition represents one current condition of an etcd cluster.
Expand Down
Loading

0 comments on commit 9d485b4

Please sign in to comment.