Skip to content

Commit 6507405

Browse files
authored
Merge pull request #36 from ucloud/v0.2.2
V0.2.2
2 parents ef9da40 + 9bc4ace commit 6507405

File tree

29 files changed

+520
-268
lines changed

29 files changed

+520
-268
lines changed

deploy/e2e.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ spec:
3030
value: ""
3131
- name: S3_BUCKET
3232
value: ""
33+
- name: CLUSTER_DOMAIN
34+
value: ""
3335

3436
---
3537
apiVersion: rbac.authorization.k8s.io/v1

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@ require (
44
github.com/appscode/go v0.0.0-20191006073906-e3d193d493fc
55
github.com/appscode/osm v0.12.0
66
github.com/aws/aws-sdk-go v1.20.20
7-
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
87
github.com/go-logr/logr v0.1.0
98
github.com/go-openapi/spec v0.19.2
9+
github.com/go-redis/redis v6.15.7+incompatible
1010
github.com/mediocregopher/radix.v2 v0.0.0-20181115013041-b67df6e626f9
1111
github.com/onsi/ginkgo v1.8.0
1212
github.com/onsi/gomega v1.5.0
1313
github.com/operator-framework/operator-sdk v0.13.0
1414
github.com/pkg/errors v0.8.1
15+
github.com/satori/go.uuid v1.2.0
1516
github.com/spf13/pflag v1.0.5
17+
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
1618
gomodules.xyz/stow v0.2.3
1719
k8s.io/api v0.0.0
1820
k8s.io/apimachinery v0.0.0
1921
k8s.io/client-go v12.0.0+incompatible
2022
k8s.io/kube-openapi v0.0.0-20190918143330-0270cf2f1c1d
2123
k8s.io/kubernetes v1.16.2
24+
kmodules.xyz/constants v0.0.0-20191024095500-cd4313df4aa6
2225
kmodules.xyz/objectstore-api v0.0.0-20191014210450-ac380fa650a3
2326
sigs.k8s.io/controller-runtime v0.4.0
2427
)

go.sum

Lines changed: 30 additions & 0 deletions
Large diffs are not rendered by default.

hack/docker/redis-tools/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RUN set -x \
88
zip \
99
&& rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man /tmp/*
1010

11-
COPY osm /usr/local/bin/osm
11+
COPY rclone /usr/local/bin/rclone
1212
COPY redis-tools.sh /usr/local/bin/redis-tools.sh
1313
RUN chmod +x /usr/local/bin/redis-tools.sh
1414

hack/docker/redis-tools/make.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ IMG=redis-tools
1717
DB_VERSION=5.0.4
1818
TAG="$DB_VERSION"
1919

20-
OSM_VER=${OSM_VER:-v1.50.2}
20+
RCLONE_VER=${RCLONE_VER:-v1.50.2}
2121

2222
DIST=$REPO_ROOT/dist
2323
mkdir -p $DIST
2424

2525
build() {
2626
pushd "$REPO_ROOT/hack/docker/redis-tools"
2727

28-
if [ ! -f "osm" ]; then
28+
if [ ! -f "rclone" ]; then
2929
# Download rclone
30-
wget https://downloads.rclone.org/"${OSM_VER}"/rclone-"${OSM_VER}"-linux-amd64.zip
31-
unzip rclone-"${OSM_VER}"-linux-amd64.zip
32-
chmod +x rclone-"${OSM_VER}"-linux-amd64/rclone
33-
mv rclone-"${OSM_VER}"-linux-amd64/rclone osm
30+
wget https://downloads.rclone.org/"${RCLONE_VER}"/rclone-"${RCLONE_VER}"-linux-amd64.zip
31+
unzip rclone-"${RCLONE_VER}"-linux-amd64.zip
32+
chmod +x rclone-"${RCLONE_VER}"-linux-amd64/rclone
33+
mv rclone-"${RCLONE_VER}"-linux-amd64/rclone rclone
3434
fi
3535

3636
local cmd="docker build --pull -t $DOCKER_REGISTRY/$IMG:$TAG ."
3737
echo $cmd; $cmd
3838

39-
rm -rf rclone-"${OSM_VER}"-linux-amd64*
40-
rm osm
39+
rm -rf rclone-"${RCLONE_VER}"-linux-amd64*
40+
rm rclone
4141
popd
4242
}
4343

hack/docker/redis-tools/redis-tools.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ show_help() {
1414
echo " --host=HOST database host"
1515
echo " --user=USERNAME database username"
1616
echo " --bucket=BUCKET name of bucket"
17+
echo " --location=LOCATION location of backend (<provider>:<bucket name>)"
1718
echo " --folder=FOLDER name of folder in bucket"
1819
echo " --snapshot=SNAPSHOT name of snapshot"
1920
}
@@ -25,11 +26,12 @@ REDIS_PORT=${REDIS_PORT:-6379}
2526
REDIS_USER=${REDIS_USER:-}
2627
REDIS_PASSWORD=${REDIS_PASSWORD:-}
2728
REDIS_BUCKET=${REDIS_BUCKET:-}
29+
REDIS_LOCATION=${REDIS_LOCATION:-}
2830
REDIS_FOLDER=${REDIS_FOLDER:-}
2931
REDIS_SNAPSHOT=${REDIS_SNAPSHOT:-}
3032
REDIS_DATA_DIR=${REDIS_DATA_DIR:-/data}
3133
REDIS_RESTORE_SUCCEEDED=${REDIS_RESTORE_SUCCEEDED:-0}
32-
OSM_CONFIG_FILE=/etc/osm/config
34+
RCLONE_CONFIG_FILE=/etc/rclone/config
3335

3436
op=$1
3537
shift
@@ -56,6 +58,10 @@ while test $# -gt 0; do
5658
export REDIS_BUCKET=$(echo $1 | sed -e 's/^[^=]*=//g')
5759
shift
5860
;;
61+
--location*)
62+
export REDIS_LOCATION=$(echo $1 | sed -e 's/^[^=]*=//g')
63+
shift
64+
;;
5965
--folder*)
6066
export REDIS_FOLDER=$(echo $1 | sed -e 's/^[^=]*=//g')
6167
shift
@@ -108,7 +114,7 @@ case "$op" in
108114
ls -lh "$SOURCE_DIR"
109115
echo "Uploading dump file to the backend......."
110116
echo "From $SOURCE_DIR"
111-
osm --config "$OSM_CONFIG_FILE" copy "$SOURCE_DIR" ceph:"$REDIS_BUCKET"/"$REDIS_FOLDER/$REDIS_SNAPSHOT" -v
117+
rclone --config "$RCLONE_CONFIG_FILE" copy "$SOURCE_DIR" "$REDIS_LOCATION"/"$REDIS_FOLDER/$REDIS_SNAPSHOT" -v
112118

113119
echo "Backup successful"
114120
;;
@@ -120,9 +126,9 @@ case "$op" in
120126
fi
121127
index=$(echo "${POD_NAME}" | awk -F- '{print $(NF-1)}')
122128
REDIS_SNAPSHOT=${REDIS_SNAPSHOT}-${index}
123-
SOURCE_SNAPSHOT="$REDIS_BUCKET"/"$REDIS_FOLDER/$REDIS_SNAPSHOT"
129+
SOURCE_SNAPSHOT="$REDIS_LOCATION"/"$REDIS_FOLDER/$REDIS_SNAPSHOT"
124130
echo "From $SOURCE_SNAPSHOT"
125-
osm --config "$OSM_CONFIG_FILE" sync ceph:"$SOURCE_SNAPSHOT" "$REDIS_DATA_DIR" -v
131+
rclone --config "$RCLONE_CONFIG_FILE" sync "$SOURCE_SNAPSHOT" "$REDIS_DATA_DIR" -v
126132

127133
echo "Recovery successful"
128134
;;

hack/e2e.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ if [[ -z ${STORAGECLASSNAME} ]]; then
99
exit 1
1010
fi
1111

12+
if [[ -z ${CLUSTER_DOMAIN} ]]; then
13+
echo "env CLUSTER_DOMAIN not set"
14+
exit 1
15+
fi
16+
1217
if [[ -z ${GINKGO_SKIP} ]]; then
1318
export GINKGO_SKIP=""
1419
fi

pkg/apis/redis/v1alpha1/constants.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ const (
5959
NodesPlacementInfoOptimal NodesPlacementInfo = "Optimal"
6060
)
6161

62+
type RestorePhase string
63+
64+
const (
65+
// RestorePhaseRunning used for Restore that are currently running.
66+
RestorePhaseRunning RestorePhase = "Running"
67+
// RestorePhaseRestart used for Restore that are restart master nodes.
68+
RestorePhaseRestart RestorePhase = "Restart"
69+
// RestorePhaseSucceeded used for Restore that are Succeeded.
70+
RestorePhaseSucceeded RestorePhase = "Succeeded"
71+
)
72+
6273
const (
6374
DatabaseNamePrefix = "redis"
6475

pkg/apis/redis/v1alpha1/default.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,19 @@ func (in *DistributedRedisCluster) IsRestoreFromBackup() bool {
7070
}
7171

7272
func (in *DistributedRedisCluster) IsRestored() bool {
73-
return in.Status.Restore.RestoreSucceeded > 0
73+
return in.Status.Restore.Phase == RestorePhaseSucceeded
74+
}
75+
76+
func (in *DistributedRedisCluster) ShouldInitRestorePhase() bool {
77+
return in.Status.Restore.Phase == ""
78+
}
79+
80+
func (in *DistributedRedisCluster) IsRestoreRunning() bool {
81+
return in.Status.Restore.Phase == RestorePhaseRunning
82+
}
83+
84+
func (in *DistributedRedisCluster) IsRestoreRestarting() bool {
85+
return in.Status.Restore.Phase == RestorePhaseRestart
7486
}
7587

7688
func defaultResource() *v1.ResourceRequirements {
@@ -114,7 +126,7 @@ func (in *RedisClusterBackup) Validate() error {
114126
return nil
115127
}
116128

117-
func (in *RedisClusterBackup) Location() (string, error) {
129+
func (in *RedisClusterBackup) RemotePath() (string, error) {
118130
spec := in.Spec.Backend
119131
timePrefix := in.Status.StartTime.Format("20060102150405")
120132
if spec.S3 != nil {
@@ -131,10 +143,14 @@ func (in *RedisClusterBackup) Location() (string, error) {
131143
return "", fmt.Errorf("no storage provider is configured")
132144
}
133145

134-
func (in *RedisClusterBackup) OSMSecretName() string {
135-
return fmt.Sprintf("osmconfig-%v", in.Name)
146+
func (in *RedisClusterBackup) RCloneSecretName() string {
147+
return fmt.Sprintf("rcloneconfig-%v", in.Name)
136148
}
137149

138150
func (in *RedisClusterBackup) JobName() string {
139151
return fmt.Sprintf("redisbackup-%v", in.Name)
140152
}
153+
154+
func (in *RedisClusterBackup) IsRefLocalPVC() bool {
155+
return in.Spec.Local != nil && in.Spec.Local.PersistentVolumeClaim != nil
156+
}

pkg/apis/redis/v1alpha1/distributedrediscluster_types.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ type DistributedRedisClusterStatus struct {
116116
}
117117

118118
type Restore struct {
119-
// The number of restore which reached phase Succeeded.
120-
RestoreSucceeded int32 `json:"restoreSucceeded,omitempty"`
121-
Backup *RedisClusterBackup `json:"backup, omitempty"`
122-
//BackupSourceSpec `json:",inline"`
119+
Phase RestorePhase `json:"phase,omitempty"`
120+
Backup *RedisClusterBackup `json:"backup, omitempty"`
123121
}
124122

125123
// RedisClusterNode represent a RedisCluster Node

0 commit comments

Comments
 (0)