GetLbAlgorithm helper func for e2e

This commit is contained in:
Elvin Efendi 2019-07-02 23:50:30 -04:00
parent d3eb42b98b
commit 964a484b2f
2 changed files with 27 additions and 15 deletions

View file

@ -18,6 +18,7 @@ package framework
import (
"bytes"
"encoding/json"
"fmt"
"io"
"os/exec"
@ -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)