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

GetLbAlgorithm helper func for e2e #4270

Merged
merged 1 commit into from
Jul 3, 2019
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
25 changes: 25 additions & 0 deletions test/e2e/framework/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package framework

import (
"bytes"
"encoding/json"
"fmt"
"io"
"os/exec"
Expand All @@ -28,6 +29,30 @@ import (
corev1 "k8s.io/api/core/v1"
)

// GetLbAlgorithm returns algorithm identifier for the given backend
func (f *Framework) GetLbAlgorithm(serviceName string, servicePort int) (string, error) {
backendName := fmt.Sprintf("%s-%s-%v", f.Namespace, serviceName, servicePort)
cmd := fmt.Sprintf("/dbg backends get %s", backendName)

output, err := f.ExecIngressPod(cmd)
if err != nil {
return "", err
}

var backend map[string]interface{}
err = json.Unmarshal([]byte(output), &backend)
if err != nil {
return "", err
}

algorithm, ok := backend["load-balance"].(string)
if !ok {
return "", fmt.Errorf("error while accessing load-balance field of backend")
}

return algorithm, nil
}

// ExecIngressPod executes a command inside the first container in ingress controller running pod
func (f *Framework) ExecIngressPod(command string) (string, error) {
pod, err := getIngressNGINXPod(f.Namespace, f.KubeClientSet)
Expand Down
17 changes: 2 additions & 15 deletions test/e2e/loadbalance/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package loadbalance

import (
"encoding/json"
"strings"
"time"

Expand Down Expand Up @@ -53,20 +52,8 @@ var _ = framework.IngressNginxDescribe("Load Balance - Configmap value", func()
})
time.Sleep(waitForLuaSync)

getCmd := "/dbg backends all"
output, err := f.ExecIngressPod(getCmd)
algorithm, err := f.GetLbAlgorithm("http-svc", 80)
Expect(err).Should(BeNil())

var backends []map[string]interface{}
unmarshalErr := json.Unmarshal([]byte(output), &backends)
Expect(unmarshalErr).Should(BeNil())

for _, backend := range backends {
if backend["name"].(string) != "upstream-default-backend" {
lb, ok := backend["load-balance"].(string)
Expect(ok).Should(Equal(true))
Expect(lb).Should(Equal("ewma"))
}
}
Expect(algorithm).Should(Equal("ewma"))
})
})