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

e2e: add qos policy test cases #2924

Merged
merged 2 commits into from
Jun 16, 2023
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
6 changes: 4 additions & 2 deletions pkg/controller/qos_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ func (c *Controller) handleUpdateQoSPolicy(key string) error {
if cachedQos.Spec.BindingType == kubeovnv1.QoSBindingTypeEIP {
eips, err := c.iptablesEipsLister.List(
labels.SelectorFromSet(labels.Set{util.QoSLabel: key}))
if err != nil {
// when eip is not found, we should delete finalizer
if err != nil && !k8serrors.IsNotFound(err) {
klog.Errorf("failed to get eip list, %v", err)
return err
}
Expand All @@ -414,7 +415,8 @@ func (c *Controller) handleUpdateQoSPolicy(key string) error {
if cachedQos.Spec.BindingType == kubeovnv1.QoSBindingTypeNatGw {
gws, err := c.vpcNatGatewayLister.List(
labels.SelectorFromSet(labels.Set{util.QoSLabel: key}))
if err != nil {
// when nat gw is not found, we should delete finalizer
if err != nil && !k8serrors.IsNotFound(err) {
klog.Errorf("failed to get gw list, %v", err)
return err
}
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/framework/docker/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,12 @@ func NetworkDisconnect(networkID, containerID string) error {

return cli.NetworkDisconnect(context.Background(), networkID, containerID, false)
}

func NetworkRemove(networkID string) error {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return err
}
defer cli.Close()
return cli.NetworkRemove(context.Background(), networkID)
}
34 changes: 34 additions & 0 deletions test/e2e/framework/exec_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package framework

import (
"context"

"github.com/kubeovn/kube-ovn/pkg/util"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/test/e2e/framework"

"github.com/onsi/gomega"
)

// ExecCommandInContainer executes a command in the specified container.
func ExecCommandInContainer(f *Framework, podName, containerName string, cmd ...string) (string, string, error) {
return util.ExecuteCommandInContainer(f.ClientSet, f.ClientConfig(), f.Namespace.Name, podName, containerName, cmd...)
}

// ExecShellInContainer executes the specified command on the pod's container.
func ExecShellInContainer(f *Framework, podName, containerName string, cmd string) (string, string, error) {
return ExecCommandInContainer(f, podName, containerName, "/bin/sh", "-c", cmd)
}

func execCommandInPod(ctx context.Context, f *Framework, podName string, cmd ...string) (string, string, error) {
pod, err := f.PodClient().Get(ctx, podName, metav1.GetOptions{})
framework.ExpectNoError(err, "failed to get pod %v", podName)
gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty())
return ExecCommandInContainer(f, podName, pod.Spec.Containers[0].Name, cmd...)
}

// ExecShellInPod executes the specified command on the pod.
func ExecShellInPod(ctx context.Context, f *Framework, podName string, cmd string) (string, string, error) {
return execCommandInPod(ctx, f, podName, "/bin/sh", "-c", cmd)
}
27 changes: 26 additions & 1 deletion test/e2e/framework/iptables-eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ func (c *IptablesEIPClient) PatchSync(original, modified *apiv1.IptablesEIP, req
return c.Get(eip.Name).DeepCopy()
}

// PatchQoS patches the vpc nat gw and waits for the qos to be ready for `timeout`.
// If the qos doesn't become ready before the timeout, it will fail the test.
func (c *IptablesEIPClient) PatchQoSPolicySync(eipName string, qosPolicyName string) *apiv1.IptablesEIP {
eip := c.Get(eipName)
modifiedEIP := eip.DeepCopy()
modifiedEIP.Spec.QoSPolicy = qosPolicyName
_ = c.Patch(eip, modifiedEIP)
ExpectTrue(c.WaitToQoSReady(eipName))
return c.Get(eipName).DeepCopy()
}

// Delete deletes a iptables eip if the iptables eip exists
func (c *IptablesEIPClient) Delete(name string) {
err := c.IptablesEIPInterface.Delete(context.TODO(), name, metav1.DeleteOptions{})
Expand Down Expand Up @@ -118,6 +129,19 @@ func (c *IptablesEIPClient) WaitToBeReady(name string, timeout time.Duration) bo
return false
}

// WaitToQoSReady returns whether the qos is ready within timeout.
func (c *IptablesEIPClient) WaitToQoSReady(name string) bool {
for start := time.Now(); time.Since(start) < timeout; time.Sleep(poll) {
eip := c.Get(name)
if eip.Status.QoSPolicy == eip.Spec.QoSPolicy {
Logf("qos %s is ready ", name)
return true
}
Logf("qos %s is not ready ", name)
}
return false
}

// WaitToBeUpdated returns whether the iptables eip is updated within timeout.
func (c *IptablesEIPClient) WaitToBeUpdated(eip *apiv1.IptablesEIP, timeout time.Duration) bool {
Logf("Waiting up to %v for iptables eip %s to be updated", timeout, eip.Name)
Expand Down Expand Up @@ -147,7 +171,7 @@ func (c *IptablesEIPClient) WaitToDisappear(name string, interval, timeout time.
return nil
}

func MakeIptablesEIP(name, v4ip, v6ip, mac, natGwDp, externalSubnet string) *apiv1.IptablesEIP {
func MakeIptablesEIP(name, v4ip, v6ip, mac, natGwDp, externalSubnet, qosPolicyName string) *apiv1.IptablesEIP {
eip := &apiv1.IptablesEIP{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -162,5 +186,6 @@ func MakeIptablesEIP(name, v4ip, v6ip, mac, natGwDp, externalSubnet string) *api
if externalSubnet != "" {
eip.Spec.ExternalSubnet = externalSubnet
}
eip.Spec.QoSPolicy = qosPolicyName
return eip
}
Loading