Skip to content

Commit

Permalink
e2e: replace nginx with agnhost
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzujian committed Jul 20, 2023
1 parent b260d4c commit 5268dec
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 52 deletions.
1 change: 0 additions & 1 deletion test/e2e/framework/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ const (
PauseImage = "kubeovn/pause:3.2"
BusyBoxImage = "busybox:stable"
AgnhostImage = "kubeovn/agnhost:2.43"
NginxImage = "nginx:latest"
)
100 changes: 49 additions & 51 deletions test/e2e/kube-ovn/pod/vpc_pod_probe.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package pod

import (
"context"
"fmt"
"math/rand"
"net"
"strconv"
"time"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubectl/pkg/util/podutils"
k8sframework "k8s.io/kubernetes/test/e2e/framework"

apiv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
"github.com/kubeovn/kube-ovn/pkg/util"
Expand Down Expand Up @@ -94,99 +102,89 @@ var _ = framework.SerialDescribe("[group:pod]", func() {
_ = subnetClient.CreateSync(subnet)

ginkgo.By("Creating pod with HTTP liveness and readiness probe that port is accessible " + podName)
pod := framework.MakePod(namespaceName, podName, nil, map[string]string{util.LogicalSwitchAnnotation: custVPCSubnetName}, framework.NginxImage, nil, nil)

port := 8000 + rand.Intn(1000)
portStr := strconv.Itoa(port)
args := []string{"netexec", "--http-port", portStr}
pod := framework.MakePod(namespaceName, podName, nil, map[string]string{util.LogicalSwitchAnnotation: custVPCSubnetName}, framework.AgnhostImage, nil, args)
pod.Spec.Containers[0].ReadinessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Port: intstr.FromInt(80),
Port: intstr.FromInt(port),
},
},
}
pod.Spec.Containers[0].LivenessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Port: intstr.FromInt(80),
},
},
}

pod = podClient.CreateSync(pod)
framework.ExpectEqual(pod.Status.ContainerStatuses[0].Ready, true)
checkTProxyRules(f, pod, 80, true)
checkTProxyRules(f, pod, port, true)

ginkgo.By("Deleting pod " + podName)
podClient.DeleteSync(podName)

ginkgo.By("Creating pod with HTTP liveness and readiness probe that port is not accessible " + podName)
pod = framework.MakePod(namespaceName, podName, nil, map[string]string{util.LogicalSwitchAnnotation: custVPCSubnetName}, framework.NginxImage, nil, nil)
pod = framework.MakePod(namespaceName, podName, nil, map[string]string{util.LogicalSwitchAnnotation: custVPCSubnetName}, framework.AgnhostImage, nil, args)
pod.Spec.Containers[0].ReadinessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Port: intstr.FromInt(81),
Port: intstr.FromInt(port + 1),
},
},
}
pod.Spec.Containers[0].LivenessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Port: intstr.FromInt(81),
},
},
_ = podClient.Create(pod)

err := k8sframework.Gomega().Eventually(context.Background(), k8sframework.HandleRetry(func(ctx context.Context) (bool, error) {
pod, err := podClient.Get(ctx, podName, metav1.GetOptions{})
if err != nil {
return false, err
}
return podutils.IsPodReady(pod), nil
})).WithTimeout(15 * time.Second).Should(gomega.BeFalse())
if err != nil {
framework.Failf("Pod %s is expected not to be ready: %v", podName, err)
}

_ = podClient.Create(pod)
time.Sleep(5 * time.Second)
pod = podClient.GetPod(podName)
checkTProxyRules(f, pod, port+1, true)

framework.ExpectEqual(pod.Status.ContainerStatuses[0].Ready, false)
checkTProxyRules(f, pod, 81, true)
ginkgo.By("Deleting pod " + podName)
podClient.DeleteSync(podName)

ginkgo.By("Creating pod with TCP probe liveness and readiness probe that port is accessible " + podName)
pod = framework.MakePod(namespaceName, podName, nil, map[string]string{util.LogicalSwitchAnnotation: custVPCSubnetName}, framework.NginxImage, nil, nil)
pod = framework.MakePod(namespaceName, podName, nil, map[string]string{util.LogicalSwitchAnnotation: custVPCSubnetName}, framework.AgnhostImage, nil, args)
pod.Spec.Containers[0].ReadinessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
TCPSocket: &corev1.TCPSocketAction{
Port: intstr.FromInt(80),
},
},
}
pod.Spec.Containers[0].LivenessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
TCPSocket: &corev1.TCPSocketAction{
Port: intstr.FromInt(80),
Port: intstr.FromInt(port),
},
},
}

pod = podClient.CreateSync(pod)
framework.ExpectEqual(pod.Status.ContainerStatuses[0].Ready, true)
checkTProxyRules(f, pod, port, true)

checkTProxyRules(f, pod, 80, true)
ginkgo.By("Deleting pod " + podName)
podClient.DeleteSync(podName)

ginkgo.By("Creating pod with TCP probe liveness and readiness probe that port is not accessible " + podName)
pod = framework.MakePod(namespaceName, podName, nil, map[string]string{util.LogicalSwitchAnnotation: custVPCSubnetName}, framework.NginxImage, nil, nil)
pod = framework.MakePod(namespaceName, podName, nil, map[string]string{util.LogicalSwitchAnnotation: custVPCSubnetName}, framework.AgnhostImage, nil, args)
pod.Spec.Containers[0].ReadinessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
TCPSocket: &corev1.TCPSocketAction{
Port: intstr.FromInt(81),
Port: intstr.FromInt(port - 1),
},
},
}
pod.Spec.Containers[0].LivenessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
TCPSocket: &corev1.TCPSocketAction{
Port: intstr.FromInt(81),
},
},
}

_ = podClient.Create(pod)
time.Sleep(5 * time.Second)
err = k8sframework.Gomega().Eventually(context.Background(), k8sframework.HandleRetry(func(ctx context.Context) (bool, error) {
pod, err := podClient.Get(ctx, podName, metav1.GetOptions{})
if err != nil {
return false, err
}
return podutils.IsPodReady(pod), nil
})).WithTimeout(15 * time.Second).Should(gomega.BeFalse())
if err != nil {
framework.Failf("Pod %s is expected not to be ready: %v", podName, err)
}

pod = podClient.GetPod(podName)
framework.ExpectEqual(pod.Status.ContainerStatuses[0].Ready, false)
checkTProxyRules(f, pod, 81, false)
checkTProxyRules(f, pod, port-1, false)
})
})

Expand All @@ -209,7 +207,7 @@ func checkTProxyRules(f *framework.Framework, pod *corev1.Pod, probePort int, ex
iptables.CheckIptablesRulesOnNode(f, nodeName, util.Mangle, util.OvnOutput, apiv1.ProtocolIPv4, expectedRules, exist)
hostIP := pod.Status.HostIP
if isZeroIP {
hostIP = "0.0.0.0"
hostIP = net.IPv4zero.String()
}
expectedRules = []string{
fmt.Sprintf(`-A OVN-PREROUTING -d %s/32 -p tcp -m tcp --dport %d -j TPROXY --on-port %d --on-ip %s --tproxy-mark %s`, podIP.IP, probePort, util.TProxyListenPort, hostIP, tProxyPreRoutingMarkMask),
Expand Down

0 comments on commit 5268dec

Please sign in to comment.