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 (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -28,6 +29,30 @@ import (
|
||||||
corev1 "k8s.io/api/core/v1"
|
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
|
// ExecIngressPod executes a command inside the first container in ingress controller running pod
|
||||||
func (f *Framework) ExecIngressPod(command string) (string, error) {
|
func (f *Framework) ExecIngressPod(command string) (string, error) {
|
||||||
pod, err := getIngressNGINXPod(f.Namespace, f.KubeClientSet)
|
pod, err := getIngressNGINXPod(f.Namespace, f.KubeClientSet)
|
||||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||||
package loadbalance
|
package loadbalance
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -53,20 +52,8 @@ var _ = framework.IngressNginxDescribe("Load Balance - Configmap value", func()
|
||||||
})
|
})
|
||||||
time.Sleep(waitForLuaSync)
|
time.Sleep(waitForLuaSync)
|
||||||
|
|
||||||
getCmd := "/dbg backends all"
|
algorithm, err := f.GetLbAlgorithm("http-svc", 80)
|
||||||
output, err := f.ExecIngressPod(getCmd)
|
|
||||||
Expect(err).Should(BeNil())
|
Expect(err).Should(BeNil())
|
||||||
|
Expect(algorithm).Should(Equal("ewma"))
|
||||||
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"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue