forked from radondb/radondb-mysql-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: backup to S3 and restore from S3 radondb#116
- Loading branch information
Showing
35 changed files
with
1,603 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
Copyright 2021 RadonDB. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
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. | ||
|
||
// BackupSpec defines the desired state of Backup | ||
type BackupSpec struct { | ||
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
// To specify the image that will be used for sidecar container. | ||
// +optional | ||
// +kubebuilder:default:="acekingke/sidecar:0.1" | ||
Image string `json:"image"` | ||
// HostName represents the host for which to take backup | ||
HostName string `json:"hostname"` | ||
ClusterName string `json:"clustname"` | ||
} | ||
|
||
// BackupStatus defines the observed state of Backup | ||
type BackupStatus struct { | ||
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster | ||
// Important: Run "make" to regenerate code after modifying this file | ||
Completed bool `json:"completed,omitempty"` | ||
|
||
// Conditions represents the backup resource conditions list. | ||
Conditions []BackupCondition `json:"conditions,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
|
||
// Backup is the Schema for the backups API | ||
type Backup struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec BackupSpec `json:"spec,omitempty"` | ||
Status BackupStatus `json:"status,omitempty"` | ||
} | ||
|
||
// BackupCondition defines condition struct for backup resource | ||
type BackupCondition struct { | ||
// type of cluster condition, values in (\"Ready\") | ||
Type BackupConditionType `json:"type"` | ||
// Status of the condition, one of (\"True\", \"False\", \"Unknown\") | ||
Status corev1.ConditionStatus `json:"status"` | ||
|
||
// LastTransitionTime | ||
LastTransitionTime metav1.Time `json:"lastTransitionTime"` | ||
// Reason | ||
Reason string `json:"reason"` | ||
// Message | ||
Message string `json:"message"` | ||
} | ||
|
||
// BackupConditionType defines condition types of a backup resources | ||
type BackupConditionType string | ||
|
||
const ( | ||
// BackupComplete means the backup has finished his execution | ||
BackupComplete BackupConditionType = "Complete" | ||
// BackupFailed means backup has failed | ||
BackupFailed BackupConditionType = "Failed" | ||
) | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// BackupList contains a list of Backup | ||
type BackupList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []Backup `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&Backup{}, &BackupList{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
Copyright 2021 RadonDB. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package backup | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/radondb/radondb-mysql-kubernetes/utils" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
v1alhpa1 "github.com/radondb/radondb-mysql-kubernetes/api/v1alpha1" | ||
) | ||
|
||
var log = logf.Log.WithName("backup") | ||
|
||
// Backup is a type wrapper over Backup that contains the Business logic | ||
type Backup struct { | ||
*v1alhpa1.Backup | ||
} | ||
|
||
// New returns a wraper object over Backup | ||
func New(backup *v1alhpa1.Backup) *Backup { | ||
return &Backup{ | ||
Backup: backup, | ||
} | ||
} | ||
|
||
// Unwrap returns the api backup object | ||
func (b *Backup) Unwrap() *v1alhpa1.Backup { | ||
return b.Backup | ||
} | ||
|
||
// GetNameForJob returns the name of the job | ||
func (b *Backup) GetNameForJob() string { | ||
return fmt.Sprintf("%s-backup", b.Name) | ||
} | ||
|
||
func (b *Backup) GetBackupURL(cluster_name string, hostname string) string { | ||
return fmt.Sprintf("%s.%s-mysql.%s:%v", hostname, cluster_name, b.Namespace, utils.XBackupPort) | ||
|
||
} |
Oops, something went wrong.