Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Vighneswar Rao Bojja committed Aug 25, 2019
1 parent 2d18818 commit 6e18d66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
14 changes: 6 additions & 8 deletions internal/configs/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const nginx502Server = "unix:/var/run/nginx-502-server.sock"
var incompatibleLBMethodsForSlowStart = map[string]bool{
"random": true,
"ip_hash": true,
"hash": true,
"random two": true,
"random two least_conn": true,
"random two least_time=header": true,
Expand Down Expand Up @@ -363,18 +362,17 @@ func generateUpstream(upstreamName string, upstream conf_v1alpha1.Upstream, isEx
}

return version2.Upstream{
Name: upstreamName,
Servers: upsServers,
LBMethod: lbMethod,
Keepalive: generateIntFromPointer(upstream.Keepalive, cfgParams.Keepalive),
Name: upstreamName,
Servers: upsServers,
LBMethod: lbMethod,
Keepalive: generateIntFromPointer(upstream.Keepalive, cfgParams.Keepalive),
UpstreamZoneSize: cfgParams.UpstreamZoneSize,
}
}

func generateSlowStartForPlus(upstream conf_v1alpha1.Upstream, lbMethod string) string {
slowStart := upstream.SlowStart

if slowStart == "" {
if upstream.SlowStart == "" {
return ""
}

Expand All @@ -388,7 +386,7 @@ func generateSlowStartForPlus(upstream conf_v1alpha1.Upstream, lbMethod string)
return ""
}

return slowStart
return upstream.SlowStart
}

func generateLBMethod(method string, defaultMethod string) string {
Expand Down
28 changes: 14 additions & 14 deletions internal/configs/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1966,24 +1966,24 @@ func TestGenerateEndpointsForUpstream(t *testing.T) {

func TestGenerateSlowStartForPlusWithInCompatibleLBMethods(t *testing.T) {
serviceName := "test-slowstart-with-incompatible-LBMethods"
upstream := conf_v1alpha1.Upstream{Service: serviceName, Port: 80, SlowStart: "10s"}
expected := ""

tests := []struct {
upstream conf_v1alpha1.Upstream
expected string
}{
{
upstream: conf_v1alpha1.Upstream{Service: serviceName, Port: 80, SlowStart: "10s"},
expected: "",
},
var tests = []string{
"random",
"ip_hash",
"hash",
"random two",
"random two least_conn",
"random two least_time=header",
"random two least_time=last_byte",
}

for _, test := range tests {
for lbMethod, _ := range incompatibleLBMethodsForSlowStart {
result := generateSlowStartForPlus(test.upstream, lbMethod)
for _, lbMethod := range tests {
result := generateSlowStartForPlus(upstream, lbMethod)

if !reflect.DeepEqual(result, test.expected) {
t.Errorf("generateSlowStartForPlus returned %v, but expected %v", result, test.expected)
}
if !reflect.DeepEqual(result, expected) {
t.Errorf("generateSlowStartForPlus returned %v, but expected %v", result, expected)
}
}

Expand Down

0 comments on commit 6e18d66

Please sign in to comment.