-
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.
Merge pull request #7 from beclab/feat/kvrocks
Feat/kvrocks
- Loading branch information
Showing
83 changed files
with
5,169 additions
and
782 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ | |
|
||
# Go workspace file | ||
go.work | ||
bin |
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,105 @@ | ||
package backup | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"bytetrade.io/web3os/tapr/pkg/apis/apr/v1alpha1" | ||
"bytetrade.io/web3os/tapr/pkg/workload/kvrocks" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
func (w *Watcher) backupRedix() error { | ||
clusters, err := w.aprClientSet.AprV1alpha1().RedixClusters("").List(w.ctx, metav1.ListOptions{}) | ||
if err != nil { | ||
klog.Error("list redix clusters error, ", err) | ||
return err | ||
} | ||
|
||
klog.Info("start to backup all users' redix clusters, of ", len(clusters.Items)) | ||
for _, cluster := range clusters.Items { | ||
klog.Info("create crd to backup redix cluster, ", cluster.Name, ", ", cluster.Namespace, ", ", cluster.Spec.Type) | ||
switch cluster.Spec.Type { | ||
case v1alpha1.KVRocks: | ||
backup := kvrocks.KVRocksBackup.DeepCopy() | ||
backup.Namespace = cluster.Namespace | ||
backup.Spec.ClusterName = cluster.Name | ||
|
||
err = kvrocks.ForceCreateNewKVRocksBackup(w.ctx, w.aprClientSet, backup) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
klog.Info("wait for kvrocks backup complete") | ||
err = kvrocks.WaitForAllBackupComplete(w.ctx, w.aprClientSet) | ||
if err != nil { | ||
klog.Error("wait for kvrocks backup complete error, ", err) | ||
} | ||
case v1alpha1.RedisCluster: | ||
err = w.backupRedis() | ||
} | ||
} | ||
|
||
return err | ||
|
||
} | ||
|
||
func (w *Watcher) restoreRedix() error { | ||
clusters, err := w.aprClientSet.AprV1alpha1().RedixClusters("").List(w.ctx, metav1.ListOptions{}) | ||
if err != nil { | ||
klog.Error("list redix clusters error, ", err) | ||
return err | ||
} | ||
|
||
klog.Info("start to restore all users' redix clusters, of ", len(clusters.Items)) | ||
for _, cluster := range clusters.Items { | ||
klog.Info("create crd to restore redix cluster, ", cluster.Name, ", ", cluster.Namespace, ", ", cluster.Spec.Type) | ||
switch cluster.Spec.Type { | ||
case v1alpha1.KVRocks: | ||
// wait for kvrocks sts deploy | ||
err = wait.PollWithContext(w.ctx, time.Second, 30*time.Minute, func(ctx context.Context) (done bool, err error) { | ||
_, err = w.k8sClientSet.AppsV1(). | ||
StatefulSets(cluster.Namespace).Get(w.ctx, cluster.Name, metav1.GetOptions{}) | ||
|
||
if err != nil { | ||
if apierrors.IsNotFound(err) { | ||
return false, nil | ||
} | ||
|
||
klog.Error("find kvrocks sts error, ", err) | ||
return false, err | ||
} | ||
|
||
return true, nil | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
klog.Info("create kvrocks restore") | ||
restore := kvrocks.KVRocksRestore.DeepCopy() | ||
restore.Namespace = cluster.Namespace | ||
restore.Spec.ClusterName = cluster.Name | ||
|
||
err = kvrocks.ForceCreateNewKVRocksRestore(w.ctx, w.aprClientSet, restore) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
klog.Info("wait for all kvrocks restore complete") | ||
err = kvrocks.WaitForAllRestoreComplete(w.ctx, w.aprClientSet) | ||
if err != nil { | ||
klog.Error("wait for kvrocks restore complete error, ", err) | ||
} | ||
|
||
case v1alpha1.RedisCluster: | ||
err = w.restoreRedis() | ||
} | ||
} | ||
|
||
return err | ||
} |
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
Oops, something went wrong.