Merge pull request #4270 from ElvinEfendi/e2e-test-refactor
GetLbAlgorithm helper func for e2e
This commit is contained in:
commit
a653e329aa
2 changed files with 27 additions and 15 deletions
|
@ -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)
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package loadbalance
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -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"))
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue