-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed: generate configmap for redis to start from /conf/redis.conf; f…
…orce set appendonly=no when do restore
- Loading branch information
Showing
6 changed files
with
315 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package manager | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-logr/logr" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
var log = logf.Log.WithName("test") | ||
|
||
func Test_isRedisConfChanged(t *testing.T) { | ||
type args struct { | ||
confInCm string | ||
currentConf map[string]string | ||
log logr.Logger | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
}{ | ||
{ | ||
name: "should false", | ||
args: args{ | ||
confInCm: `appendfsync everysec | ||
appendonly yes | ||
auto-aof-rewrite-min-size 67108864 | ||
save 900 1 300 10`, | ||
currentConf: map[string]string{ | ||
"appendfsync": "everysec", | ||
"appendonly": "yes", | ||
"auto-aof-rewrite-min-size": "67108864", | ||
"save": "900 1 300 10", | ||
}, | ||
log: log, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "should false with newline", | ||
args: args{ | ||
confInCm: `appendfsync everysec | ||
appendonly yes | ||
auto-aof-rewrite-min-size 67108864 | ||
save 900 1 300 10 | ||
`, | ||
currentConf: map[string]string{ | ||
"appendfsync": "everysec", | ||
"appendonly": "yes", | ||
"auto-aof-rewrite-min-size": "67108864", | ||
"save": "900 1 300 10", | ||
}, | ||
log: log, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "should true, compare value", | ||
args: args{ | ||
confInCm: `appendfsync everysec | ||
appendonly yes | ||
auto-aof-rewrite-min-size 6710886 | ||
save 900 1 300 10 | ||
`, | ||
currentConf: map[string]string{ | ||
"appendfsync": "everysec", | ||
"appendonly": "yes", | ||
"auto-aof-rewrite-min-size": "67108864", | ||
"save": "900 1 300 10", | ||
}, | ||
log: log, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "should true, add current", | ||
args: args{ | ||
confInCm: `appendfsync everysec | ||
appendonly yes | ||
save 900 1 300 10 | ||
`, | ||
currentConf: map[string]string{ | ||
"appendfsync": "everysec", | ||
"appendonly": "yes", | ||
"auto-aof-rewrite-min-size": "67108864", | ||
"save": "900 1 300 10", | ||
}, | ||
log: log, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "should true, del current", | ||
args: args{ | ||
confInCm: `appendfsync everysec | ||
appendonly yes | ||
auto-aof-rewrite-min-size 67108864 | ||
save 900 1 300 10 | ||
`, | ||
currentConf: map[string]string{ | ||
"appendfsync": "everysec", | ||
"appendonly": "yes", | ||
"save": "900 1 300 10", | ||
}, | ||
log: log, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "should true, compare key", | ||
args: args{ | ||
confInCm: `appendfsync everysec | ||
appendonly yes | ||
save 900 1 300 10 | ||
`, | ||
currentConf: map[string]string{ | ||
"appendonly": "yes", | ||
"auto-aof-rewrite-min-size": "67108864", | ||
"save": "900 1 300 10", | ||
}, | ||
log: log, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "should true, compare save", | ||
args: args{ | ||
confInCm: `appendfsync everysec | ||
appendonly yes | ||
auto-aof-rewrite-min-size 67108864 | ||
save 900 1 300 10 | ||
`, | ||
currentConf: map[string]string{ | ||
"appendfsync": "everysec", | ||
"appendonly": "yes", | ||
"auto-aof-rewrite-min-size": "67108864", | ||
"save": "900 1", | ||
}, | ||
log: log, | ||
}, | ||
want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := isRedisConfChanged(tt.args.confInCm, tt.args.currentConf, tt.args.log); got != tt.want { | ||
t.Errorf("isRedisConfChanged() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,84 @@ | ||
package configmaps | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_generateRedisConfContent(t *testing.T) { | ||
confMap := map[string]string{ | ||
"activerehashing": "yes", | ||
"appendfsync": "everysec", | ||
"appendonly": "yes", | ||
"auto-aof-rewrite-min-size": "67108864", | ||
"auto-aof-rewrite-percentage": "100", | ||
"cluster-node-timeout": "15000", | ||
"cluster-require-full-coverage": "yes", | ||
"hash-max-ziplist-entries": "512", | ||
"hash-max-ziplist-value": "64", | ||
"hll-sparse-max-bytes": "3000", | ||
"list-compress-depth": "0", | ||
"maxmemory": "1000000000", | ||
"maxmemory-policy": "noeviction", | ||
"maxmemory-samples": "5", | ||
"no-appendfsync-on-rewrite": "no", | ||
"notify-keyspace-events": "", | ||
"repl-backlog-size": "1048576", | ||
"repl-backlog-ttl": "3600", | ||
"set-max-intset-entries": "512", | ||
"slowlog-log-slower-than": "10000", | ||
"slowlog-max-len": "128", | ||
"stop-writes-on-bgsave-error": "yes", | ||
"tcp-keepalive": "0", | ||
"timeout": "0", | ||
"zset-max-ziplist-entries": "128", | ||
"zset-max-ziplist-value": "64", | ||
} | ||
want := `activerehashing yes | ||
appendfsync everysec | ||
appendonly yes | ||
auto-aof-rewrite-min-size 67108864 | ||
auto-aof-rewrite-percentage 100 | ||
cluster-node-timeout 15000 | ||
cluster-require-full-coverage yes | ||
hash-max-ziplist-entries 512 | ||
hash-max-ziplist-value 64 | ||
hll-sparse-max-bytes 3000 | ||
list-compress-depth 0 | ||
maxmemory 1000000000 | ||
maxmemory-policy noeviction | ||
maxmemory-samples 5 | ||
no-appendfsync-on-rewrite no | ||
notify-keyspace-events | ||
repl-backlog-size 1048576 | ||
repl-backlog-ttl 3600 | ||
set-max-intset-entries 512 | ||
slowlog-log-slower-than 10000 | ||
slowlog-max-len 128 | ||
stop-writes-on-bgsave-error yes | ||
tcp-keepalive 0 | ||
timeout 0 | ||
zset-max-ziplist-entries 128 | ||
zset-max-ziplist-value 64 | ||
` | ||
type args struct { | ||
configMap map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "test", | ||
args: struct{ configMap map[string]string }{configMap: confMap}, | ||
want: want, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := generateRedisConfContent(tt.args.configMap); got != tt.want { | ||
t.Errorf("generateRedisConfContent()\n[%v], want\n[%v]", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.