Merge pull request #120347 from shijinye/e2eclean

e2e_network:stop using deprecated framework.ExpectError
This commit is contained in:
Kubernetes Prow Robot 2023-09-26 12:04:59 -07:00 committed by GitHub
commit bb024e1f91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View File

@ -29,6 +29,7 @@ import (
"github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega" "github.com/onsi/gomega"
networkingv1 "k8s.io/api/networking/v1" networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
@ -233,14 +234,14 @@ var _ = common.SIGDescribe("Netpol API", func() {
SetSpecPodSelectorMatchLabels(map[string]string{"pod-name": "test-pod"}), SetSpecPodSelectorMatchLabels(map[string]string{"pod-name": "test-pod"}),
SetSpecEgressRules(egressRule)) SetSpecEgressRules(egressRule))
_, err := npClient.Create(ctx, npTemplate, metav1.CreateOptions{}) _, err := npClient.Create(ctx, npTemplate, metav1.CreateOptions{})
framework.ExpectError(err, "request template:%v", npTemplate) gomega.Expect(err).To(gomega.HaveOccurred(), "request template:%v", npTemplate)
ginkgo.By("EndPort field cannot be defined if the Port field is defined as a named (string) port.") ginkgo.By("EndPort field cannot be defined if the Port field is defined as a named (string) port.")
egressRule = networkingv1.NetworkPolicyEgressRule{} egressRule = networkingv1.NetworkPolicyEgressRule{}
egressRule.Ports = append(egressRule.Ports, networkingv1.NetworkPolicyPort{Port: &intstr.IntOrString{Type: intstr.String, StrVal: "serve-80"}, EndPort: &endport}) egressRule.Ports = append(egressRule.Ports, networkingv1.NetworkPolicyPort{Port: &intstr.IntOrString{Type: intstr.String, StrVal: "serve-80"}, EndPort: &endport})
npTemplate.Spec.Egress = []networkingv1.NetworkPolicyEgressRule{egressRule} npTemplate.Spec.Egress = []networkingv1.NetworkPolicyEgressRule{egressRule}
_, err = npClient.Create(ctx, npTemplate, metav1.CreateOptions{}) _, err = npClient.Create(ctx, npTemplate, metav1.CreateOptions{})
framework.ExpectError(err, "request template:%v", npTemplate) gomega.Expect(err).To(gomega.HaveOccurred(), "request template:%v", npTemplate)
ginkgo.By("EndPort field must be equal or greater than port.") ginkgo.By("EndPort field must be equal or greater than port.")
ginkgo.By("When EndPort field is smaller than port, it will failed") ginkgo.By("When EndPort field is smaller than port, it will failed")
@ -248,7 +249,7 @@ var _ = common.SIGDescribe("Netpol API", func() {
egressRule.Ports = append(egressRule.Ports, networkingv1.NetworkPolicyPort{Port: &intstr.IntOrString{Type: intstr.Int, IntVal: 30000}, EndPort: &endport}) egressRule.Ports = append(egressRule.Ports, networkingv1.NetworkPolicyPort{Port: &intstr.IntOrString{Type: intstr.Int, IntVal: 30000}, EndPort: &endport})
npTemplate.Spec.Egress = []networkingv1.NetworkPolicyEgressRule{egressRule} npTemplate.Spec.Egress = []networkingv1.NetworkPolicyEgressRule{egressRule}
_, err = npClient.Create(ctx, npTemplate, metav1.CreateOptions{}) _, err = npClient.Create(ctx, npTemplate, metav1.CreateOptions{})
framework.ExpectError(err, "request template:%v", npTemplate) gomega.Expect(err).To(gomega.HaveOccurred(), "request template:%v", npTemplate)
ginkgo.By("EndPort field is equal with port.") ginkgo.By("EndPort field is equal with port.")
egressRule.Ports[0].Port = &intstr.IntOrString{Type: intstr.Int, IntVal: 20000} egressRule.Ports[0].Port = &intstr.IntOrString{Type: intstr.Int, IntVal: 20000}

View File

@ -2139,15 +2139,15 @@ var _ = common.SIGDescribe("Services", func() {
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
cmd = fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, clusterIPAddress) cmd = fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, clusterIPAddress)
_, err := e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd) _, err := e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd)
framework.ExpectError(err, "expected error when trying to connect to cluster IP") gomega.Expect(err).To(gomega.HaveOccurred(), "expected error when trying to connect to cluster IP")
cmd = fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, nodePortAddress0) cmd = fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, nodePortAddress0)
_, err = e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd) _, err = e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd)
framework.ExpectError(err, "expected error when trying to connect to NodePort address") gomega.Expect(err).To(gomega.HaveOccurred(), "expected error when trying to connect to NodePort address")
cmd = fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, nodePortAddress1) cmd = fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, nodePortAddress1)
_, err = e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd) _, err = e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd)
framework.ExpectError(err, "expected error when trying to connect to NodePort address") gomega.Expect(err).To(gomega.HaveOccurred(), "expected error when trying to connect to NodePort address")
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
} }
@ -2529,7 +2529,7 @@ var _ = common.SIGDescribe("Services", func() {
// the second pause pod is on a different node, so it should see a connection error every time // the second pause pod is on a different node, so it should see a connection error every time
cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress) cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress)
_, err := e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd) _, err := e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd)
framework.ExpectError(err, "expected error when trying to connect to cluster IP") gomega.Expect(err).To(gomega.HaveOccurred(), "expected error when trying to connect to cluster IP")
} }
}) })
@ -2599,7 +2599,7 @@ var _ = common.SIGDescribe("Services", func() {
// the second pause pod is on a different node, so it should see a connection error every time // the second pause pod is on a different node, so it should see a connection error every time
cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress) cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress)
_, err := e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd) _, err := e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd)
framework.ExpectError(err, "expected error when trying to connect to cluster IP") gomega.Expect(err).To(gomega.HaveOccurred(), "expected error when trying to connect to cluster IP")
} }
}) })
@ -2672,7 +2672,7 @@ var _ = common.SIGDescribe("Services", func() {
// the second pause pod is on a different node, so it should see a connection error every time // the second pause pod is on a different node, so it should see a connection error every time
cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress) cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress)
_, err := e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd) _, err := e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd)
framework.ExpectError(err, "expected error when trying to connect to cluster IP") gomega.Expect(err).To(gomega.HaveOccurred(), "expected error when trying to connect to cluster IP")
} }
ginkgo.By("Creating 2 pause hostNetwork pods that will try to connect to the webserver") ginkgo.By("Creating 2 pause hostNetwork pods that will try to connect to the webserver")
@ -2701,7 +2701,7 @@ var _ = common.SIGDescribe("Services", func() {
// the second pause pod is on a different node, so it should see a connection error every time // the second pause pod is on a different node, so it should see a connection error every time
cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress) cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress)
_, err := e2eoutput.RunHostCmd(pausePod3.Namespace, pausePod3.Name, cmd) _, err := e2eoutput.RunHostCmd(pausePod3.Namespace, pausePod3.Name, cmd)
framework.ExpectError(err, "expected error when trying to connect to cluster IP") gomega.Expect(err).To(gomega.HaveOccurred(), "expected error when trying to connect to cluster IP")
} }
}) })
@ -2943,7 +2943,7 @@ var _ = common.SIGDescribe("Services", func() {
cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress) cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, serviceAddress)
_, err := e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd) _, err := e2eoutput.RunHostCmd(pausePod1.Namespace, pausePod1.Name, cmd)
framework.ExpectError(err, "expected error when trying to connect to cluster IP") gomega.Expect(err).To(gomega.HaveOccurred(), "expected error when trying to connect to cluster IP")
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
} }
@ -3099,7 +3099,7 @@ var _ = common.SIGDescribe("Services", func() {
// connections are neither internal nor external and always get Cluster traffic policy. // connections are neither internal nor external and always get Cluster traffic policy.
cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, nodePortAddress1) cmd := fmt.Sprintf(`curl -q -s --connect-timeout 5 %s/hostname`, nodePortAddress1)
_, err := e2eoutput.RunHostCmd(pausePod0.Namespace, pausePod0.Name, cmd) _, err := e2eoutput.RunHostCmd(pausePod0.Namespace, pausePod0.Name, cmd)
framework.ExpectError(err, "expected error when trying to connect to node port for pausePod0") gomega.Expect(err).To(gomega.HaveOccurred(), "expected error when trying to connect to node port for pausePod0")
execHostnameTest(*pausePod0, nodePortAddress0, webserverPod0.Name) execHostnameTest(*pausePod0, nodePortAddress0, webserverPod0.Name)
execHostnameTest(*pausePod1, nodePortAddress0, webserverPod0.Name) execHostnameTest(*pausePod1, nodePortAddress0, webserverPod0.Name)
@ -3311,7 +3311,7 @@ var _ = common.SIGDescribe("Services", func() {
ginkgo.By("fetching the Endpoint") ginkgo.By("fetching the Endpoint")
_, err = f.ClientSet.CoreV1().Endpoints(testNamespaceName).Get(ctx, testEndpointName, metav1.GetOptions{}) _, err = f.ClientSet.CoreV1().Endpoints(testNamespaceName).Get(ctx, testEndpointName, metav1.GetOptions{})
framework.ExpectError(err, "should not be able to fetch Endpoint") gomega.Expect(err).To(gomega.HaveOccurred(), "should not be able to fetch Endpoint")
}) })
/* /*