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

Add networking test for invalid external gateway #26883

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions test/extended/networking/external_gateway.go
@@ -0,0 +1,48 @@
package networking

import (
"context"
"time"

g "github.com/onsi/ginkgo"
exutil "github.com/openshift/origin/test/extended/util"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
frameworkpod "k8s.io/kubernetes/test/e2e/framework/pod"
)

var _ = g.Describe("[sig-network] external gateway address", func() {
oc := exutil.NewCLI("ns-global")

InOVNKubernetesContext(func() {
f := oc.KubeFramework()

g.It("Should validate failure if an external gateway address does not match the address family of the pod", func() {
err := createPod(f.ClientSet, f.Namespace.Name, "test-valid-gateway-pod")
expectNoError(err)
// Set external gateway address into an IPv6 address that does not match the
// address family of the pod.
makeNamespaceWithExternalGatewaySet(f, "fd00:10:244:2::6")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a comment explaining why this IPv6 address is being used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, done.

err = createPod(f.ClientSet, f.Namespace.Name, "test-invalid-gateway-pod")
expectError(err, "pod creation failed due to invalid gateway address")
})
})

})

func createPod(client clientset.Interface, ns, generateName string) error {
pod := frameworkpod.NewAgnhostPod(ns, "", nil, nil, nil)
pod.ObjectMeta.GenerateName = generateName
execPod, err := client.CoreV1().Pods(ns).Create(context.TODO(), pod, metav1.CreateOptions{})
expectNoError(err, "failed to create new pod in namespace: %s", ns)
err = wait.PollImmediate(poll, 2*time.Minute, func() (bool, error) {
retrievedPod, err := client.CoreV1().Pods(execPod.Namespace).Get(context.TODO(), execPod.Name, metav1.GetOptions{})
if err != nil {
return false, err
}
return retrievedPod.Status.Phase == v1.PodRunning, nil
})
return err
}
19 changes: 19 additions & 0 deletions test/extended/networking/util.go
Expand Up @@ -248,6 +248,25 @@ func makeNamespaceScheduleToAllNodes(f *e2e.Framework) {
}
}

func makeNamespaceWithExternalGatewaySet(f *e2e.Framework, gatewayIP string) {
for {
ns, err := f.ClientSet.CoreV1().Namespaces().Get(context.Background(), f.Namespace.Name, metav1.GetOptions{})
expectNoError(err)
if ns.Annotations == nil {
ns.Annotations = make(map[string]string)
}
ns.Annotations["k8s.ovn.org/routing-external-gws"] = gatewayIP
_, err = f.ClientSet.CoreV1().Namespaces().Update(context.Background(), ns, metav1.UpdateOptions{})
if err == nil {
return
}
if kapierrs.IsConflict(err) {
continue
}
expectNoError(err)
}
}

// findAppropriateNodes tries to find a source and destination for a type of node connectivity
// test (same node, or different node).
func findAppropriateNodes(f *e2e.Framework, nodeType NodeType) (*corev1.Node, *corev1.Node, error) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.