Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check data consistent by external tool #1205

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ rules:
allow-non-breakable-words: true
allow-non-breakable-inline-mappings: true
comments-indentation: disable

ignore:
- resources.yaml
File renamed without changes.
File renamed without changes.
25 changes: 19 additions & 6 deletions cmd/data-assert/main.go → tests/data-assert/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,22 @@ func genRedisDataCmd(cmd *cobra.Command, args []string) {
ctx := context.Background()
var rdb redis.UniversalClient

// Split host string by comma
hosts := strings.Split(host, ",")
for i := range hosts {
hosts[i] = strings.TrimSpace(hosts[i])
}

switch mode {
case "cluster":
rdb = redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{host},
Addrs: hosts,
Password: pass,
})
case "sentinel":
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "mymaster",
SentinelAddrs: []string{host},
SentinelAddrs: hosts,
Password: pass,
})
default:
Expand All @@ -95,7 +101,7 @@ func genRedisDataCmd(cmd *cobra.Command, args []string) {
return
}
}
fmt.Printf("successfully generated %d keys\n", totalKey)
fmt.Printf("[OK] successfully generated %d keys\n", totalKey)
}

// DataError represents data consistency check errors
Expand All @@ -118,23 +124,29 @@ func chkRedisDataCmd(cmd *cobra.Command, args []string) {
fmt.Printf("Error occurred during check: %v\n", err)
os.Exit(1)
}
fmt.Printf("Data consistency check passed! All %d keys exist\n", totalKey)
fmt.Printf("[OK] Data consistency check passed! All %d keys exist\n", totalKey)
}

func checkRedisData() error {
ctx := context.Background()
var rdb redis.UniversalClient

// Split host string by comma
hosts := strings.Split(host, ",")
for i := range hosts {
hosts[i] = strings.TrimSpace(hosts[i])
}

switch mode {
case "cluster":
rdb = redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{host},
Addrs: hosts,
Password: pass,
})
case "sentinel":
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "mymaster",
SentinelAddrs: []string{host},
SentinelAddrs: hosts,
Password: pass,
})
default:
Expand Down Expand Up @@ -198,4 +210,5 @@ func genResourceYamlCmd(cmd *cobra.Command, args []string) {
if err != nil {
panic(err)
}
fmt.Println("✅resources.yaml generated")
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,22 @@ data:
ctx := context.Background()
var rdb redis.UniversalClient

// Split host string by comma
hosts := strings.Split(host, ",")
for i := range hosts {
hosts[i] = strings.TrimSpace(hosts[i])
}

switch mode {
case "cluster":
rdb = redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{host},
Addrs: hosts,
Password: pass,
})
case "sentinel":
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "mymaster",
SentinelAddrs: []string{host},
SentinelAddrs: hosts,
Password: pass,
})
default:
Expand All @@ -102,7 +108,7 @@ data:
return
}
}
fmt.Printf("successfully generated %d keys\n", totalKey)
fmt.Printf("[OK] successfully generated %d keys\n", totalKey)
}

// DataError represents data consistency check errors
Expand All @@ -125,23 +131,29 @@ data:
fmt.Printf("Error occurred during check: %v\n", err)
os.Exit(1)
}
fmt.Printf("Data consistency check passed! All %d keys exist\n", totalKey)
fmt.Printf("[OK] Data consistency check passed! All %d keys exist\n", totalKey)
}

func checkRedisData() error {
ctx := context.Background()
var rdb redis.UniversalClient

// Split host string by comma
hosts := strings.Split(host, ",")
for i := range hosts {
hosts[i] = strings.TrimSpace(hosts[i])
}

switch mode {
case "cluster":
rdb = redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{host},
Addrs: hosts,
Password: pass,
})
case "sentinel":
rdb = redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: "mymaster",
SentinelAddrs: []string{host},
SentinelAddrs: hosts,
Password: pass,
})
default:
Expand Down Expand Up @@ -205,6 +217,7 @@ data:
if err != nil {
panic(err)
}
fmt.Println("✅resources.yaml generated")
}

go.mod: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ spec:
- try:
- apply:
file: cluster.yaml
- apply:
file: ../../../data-assert/resources.yaml
- assert:
file: ready-cluster.yaml

- name: Try saving a key With Password
- name: Put data
try:
- script:
timeout: 30s
content: >
kubectl exec --namespace ${NAMESPACE} --container redis-cluster-v1beta2-leader redis-cluster-v1beta2-leader-0 --
redis-cli -c set foo-0 bar-0
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
bash -c "cd /go/src/data-assert && go run main.go gen-redis-data --host redis-cluster-v1beta2-leader.${NAMESPACE}.svc.cluster.local:6379 --mode cluster"
check:
(contains($stdout, 'OK')): true

Expand All @@ -39,12 +41,12 @@ spec:
- assert:
file: ready-cluster.yaml

- name: Get key
- name: Assert data
try:
- script:
timeout: 30s
content: >
kubectl exec --namespace ${NAMESPACE} --container redis-cluster-v1beta2-leader redis-cluster-v1beta2-leader-0 --
redis-cli -c get foo-0
kubectl exec --namespace ${NAMESPACE} --container data-assert data-assert --
bash -c "cd /go/src/data-assert && go run main.go chk-redis-data --host redis-cluster-v1beta2-leader.${NAMESPACE}.svc.cluster.local:6379 --mode cluster"
check:
(contains($stdout, 'bar-0')): true
(contains($stdout, 'OK')): true
Loading