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

Add redis host and port parameter to the scaler with tests #719

Merged
merged 1 commit into from
Apr 2, 2020
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
30 changes: 29 additions & 1 deletion pkg/scalers/redis_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
defaultRedisPassword = ""
defaultDbIdx = 0
defaultEnableTLS = false
defaultHost = ""
defaultPort = ""
)

type redisScaler struct {
Expand All @@ -33,6 +35,8 @@ type redisMetadata struct {
listName string
address string
password string
host string
port string
databaseIndex int
enableTLS bool
}
Expand Down Expand Up @@ -70,14 +74,38 @@ func parseRedisMetadata(metadata, resolvedEnv, authParams map[string]string) (*r
}

address := defaultRedisAddress
host := defaultHost
port := defaultPort
if val, ok := metadata["address"]; ok && val != "" {
address = val
} else {
if val, ok := metadata["host"]; ok && val != "" {
host = val
} else {
return nil, fmt.Errorf("no address or host given. address should be in the format of host:port or you should set the host/port values")
}
if val, ok := metadata["port"]; ok && val != "" {
port = val
} else {
return nil, fmt.Errorf("no address or port given. address should be in the format of host:port or you should set the host/port values")
}
}

if val, ok := resolvedEnv[address]; ok {
meta.address = val
} else {
return nil, fmt.Errorf("no address given. Address should be in the format of host:port")
if val, ok := resolvedEnv[host]; ok {
meta.host = val
} else {
return nil, fmt.Errorf("no address given or host given. Address should be in the format of host:port or you should provide both host and port")
}

if val, ok := resolvedEnv[port]; ok {
meta.port = val
} else {
return nil, fmt.Errorf("no address or port given. Address should be in the format of host:port or you should provide both host and port")
}
meta.address = fmt.Sprintf("%s:%s", meta.host, meta.port)
}

meta.password = defaultRedisPassword
Expand Down
7 changes: 7 additions & 0 deletions pkg/scalers/redis_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

var testRedisResolvedEnv = map[string]string{
"REDIS_HOST": "none",
"REDIS_PORT": "6379",
"REDIS_PASSWORD": "none",
}

Expand All @@ -20,6 +21,12 @@ var testRedisMetadata = []parseRedisMetadataTestData{
{map[string]string{}, true, map[string]string{}},
// properly formed listName
{map[string]string{"listName": "mylist", "listLength": "10", "address": "REDIS_HOST", "password": "REDIS_PASSWORD"}, false, map[string]string{}},
// properly formed hostPort
{map[string]string{"listName": "mylist", "listLength": "10", "host": "REDIS_HOST", "port": "REDIS_PORT", "password": "REDIS_PASSWORD"}, false, map[string]string{}},
// properly formed hostPort
{map[string]string{"listName": "mylist", "listLength": "10", "address": "REDIS_HOST", "host": "REDIS_HOST", "port": "REDIS_PORT", "password": "REDIS_PASSWORD"}, false, map[string]string{}},
// improperly formed hostPort
{map[string]string{"listName": "mylist", "listLength": "10", "host": "REDIS_HOST", "password": "REDIS_PASSWORD"}, true, map[string]string{}},
// properly formed listName, empty address
{map[string]string{"listName": "mylist", "listLength": "10", "address": "", "password": ""}, true, map[string]string{}},
// improperly formed listLength
Expand Down